I'm trying to simulate a non linear prey-predator system using ode45, but I'm pretty new to Matlab functions and keep getting errors.
close; clear;
timerange = [0 20];
IC=[1; 1; 1; 1];
r = [1 0.72 1.53 1.27];
a = [1 1.09 1.52 0;
0 1 0.44 1.36;
2.33 0 1 0.47;
1.21 0.51 0.35 1];
IC=[1 1 1 1];
fun = @(t, x)predapredatore(x, r, a);
[t, x]=ode45(predapredatore,timerange,IC);
Not enough input arguments.

Error in solution>predapredatore (line 18)
dx= [r(1)*x(1)*(1 - a(1,1)*x(1) - a(1,2)*x(2) - a(1,3)*x(3) - a(1,4)*x(4));...
plot(t, x)
function dx=predapredatore(x, r, a)
dx= [r(1)*x(1)*(1 - a(1,1)*x(1) - a(1,2)*x(2) - a(1,3)*x(3) - a(1,4)*x(4));...
r(2)*x(2)*(1 - a(2,1)*x(1) - a(2,2)*x(2) - a(2,3)*x(3) - a(2,4)*x(4));...
r(3)*x(3)*(1 - a(3,1)*x(1) - a(3,2)*x(2) - a(3,3)*x(3) - a(3,4)*x(4));...
r(4)*x(4)*(1 - a(4,1)*x(1) - a(4,2)*x(2) - a(4,3)*x(3) - a(4,4)*x(4));];
end
The errors I get are:
Not enough input arguments.
Error in preypredator>predapredatore (line 28)
dx= [r(1)*x(1)*(1 - a(1,1)*x(1) - a(1,2)*x(2) - a(1,3)*x(3) - a(1,4)*x(4));...
Error in preypredator (line 13)
[t, x]=ode45(predapredatore,timerange,IC);
Where am I missing input arguments? And what type of errors are in line 28 and 13?

 Akzeptierte Antwort

Star Strider
Star Strider am 12 Nov. 2022
You already did everything necessary. Just change the ode45 call to:
[t, x]=ode45(fun,timerange,IC);
and it works —
close; clear;
timerange = [0 20];
IC=[1; 1; 1; 1];
r = [1 0.72 1.53 1.27];
a = [1 1.09 1.52 0;
0 1 0.44 1.36;
2.33 0 1 0.47;
1.21 0.51 0.35 1];
IC=[1 1 1 1];
fun = @(t, x)predapredatore(x, r, a);
[t, x]=ode45(fun,timerange,IC);
plot(t, x)
function dx=predapredatore(x, r, a)
dx= [r(1)*x(1)*(1 - a(1,1)*x(1) - a(1,2)*x(2) - a(1,3)*x(3) - a(1,4)*x(4));...
r(2)*x(2)*(1 - a(2,1)*x(1) - a(2,2)*x(2) - a(2,3)*x(3) - a(2,4)*x(4));...
r(3)*x(3)*(1 - a(3,1)*x(1) - a(3,2)*x(2) - a(3,3)*x(3) - a(3,4)*x(4));...
r(4)*x(4)*(1 - a(4,1)*x(1) - a(4,2)*x(2) - a(4,3)*x(3) - a(4,4)*x(4));];
end
.

Weitere Antworten (0)

Produkte

Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by