Hi everyone,
I have a problem with an ode45 function. Hier is my code:
function dx=num_lsg1(t,x)
dx=zeros(2,1);
dx(1)=k*x(2)-x(1)*(1-x(2));
dx(2) = (x(1)*(1-x(2))-kmm*x(2))/e;
%def parameters
k=0.625;
e=0.001;
kmm=1;
s0=1;
c0=0;
t=linspace(0,0.01,100);
x0=[s0 c0];
% Main program
[t,x]=ode45(@(t,x) num_lsg1(t,x), t, x0);
plot(x(:,1),'-o', x(:,2),'-x');
end
Hier is the arror message:
>> num_lsg1
Not enough input arguments.
Error in num_lsg1 (line 5)
dx(1)=k*x(2)-x(1)*(1-x(2));
Could someone help me to find the problem?
Thank you!

 Akzeptierte Antwort

madhan ravi
madhan ravi am 14 Dez. 2018
Bearbeitet: madhan ravi am 14 Dez. 2018

0 Stimmen

% Main program
s0=1;
c0=0;
t=linspace(0,0.01,100);
x0=[s0 c0];
% Main program
[t,x]=ode45(@(t,x) num_lsg1(t,x), t, x0); % function call
plot(t,x(:,1),'-o')
figure % plot it in separate figure because obviously the scales are different
plot(t, x(:,2),'-x');
function dx=num_lsg1(t,x) % function definition
%def parameters
k=0.625; % have t be defined before usage (that's why you had error)
e=0.001;
kmm=1;
dx=zeros(2,1);
dx(1)=k*x(2)-x(1)*(1-x(2));
dx(2) = (x(1)*(1-x(2))-kmm*x(2))/e;
end
Screen Shot 2018-12-14 at 12.38.17 PM.png
Screen Shot 2018-12-14 at 12.38.27 PM.png

2 Kommentare

Tatjana Henning
Tatjana Henning am 14 Dez. 2018
Thank you sooo much!!! It works now!
madhan ravi
madhan ravi am 14 Dez. 2018
Anytime :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by