"Not Enough Arguments" Error in ode23 - code is perfect as far as I know...
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Lauren
am 27 Feb. 2014
Bearbeitet: Star Strider
am 27 Feb. 2014
function kinetics=examquestion1(t,Y)
kinetics=zeros(3,1);
kinetics(1)=-Y(1)*Y(2)+0.1*Y(3);
kinetics(2)=-Y(1)*Y(2)+0.1*Y(3);
kinetics(3)=Y(1)*Y(2)-0.1*Y(3);
[tv,Yv]=ode45(@examquestion1,[0 10],[1;1;0],t);
plot(tv,Yv(:,1),'+',tv,Yv(:,2),'x',tv,Yv(:,3),'o')
hold on
grid
title('Solutions w/k1=1 and k-1=0.1')
text(0.3,14,'-+- A(t)')
text(0.3,10,'-x- B(t)')
text(0.3,-12,'-o- P(t)')
xlabel('time')
hold off
end
Above is my code, error is in line 4 "kinetics(1)=......." I have no clue what to do!! Please help, time is of the essence. Thank you :)
Code is for solving a system of 3 differential equations, representing the kinetics of an A + B = C reaction.
0 Kommentare
Akzeptierte Antwort
Paul
am 27 Feb. 2014
Put this in an m-file:
function kinetics=examquestion1(t,Y)
kinetics=zeros(3,1);
kinetics(1)=-Y(1)*Y(2)+0.1*Y(3);
kinetics(2)=-Y(1)*Y(2)+0.1*Y(3);
kinetics(3)=Y(1)*Y(2)-0.1*Y(3);
save it as examquestion1. Then run:
[tv,Yv]=ode45(@examquestion1,[0 10],[1;1;0]);
plot(tv,Yv(:,1),'+',tv,Yv(:,2),'x',tv,Yv(:,3),'o')
hold on
grid
title('Solutions w/k1=1 and k-1=0.1')
text(0.3,14,'-+- A(t)')
text(0.3,10,'-x- B(t)')
text(0.3,-12,'-o- P(t)')
xlabel('time')
hold off
0 Kommentare
Weitere Antworten (1)
Star Strider
am 27 Feb. 2014
Bearbeitet: Star Strider
am 27 Feb. 2014
You can only put a function file inside another function file. If you want your ODE to run in your file, you have to code it as an anonymous function.
You also made a simple typographical error:
[tv,Yv]=ode45(@examquestion1,[0 10],[1;1;0],t);
It will throw an error because of the t.
I reformatted your ODE as an anonymous function (for my convenience only) and this ran without problems:
examquestion1 = @(t,Y) [-Y(1)*Y(2)+0.1*Y(3); -Y(1)*Y(2)+0.1*Y(3); Y(1)*Y(2)-0.1*Y(3)];
[tv,Yv]=ode45(examquestion1,[0 10],[1;1;0]);
Also, with respect to your text statements, see the legend command. It may make what you’re doing easier.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!