I am trying to solve differential equations by using ode45 solver. However, it does not work as expected.
function ydot=Untitledrt(z,y)
ydot = zeros(6,1);
%y(1)=A
%y(2)=B
%y(3)=C
%y(4)=D
%y(5)=P
%y(6)=T
m1 = 6;
m2 = 9;
m3 = 5;
k1 = 6;
k2 = 7;
k3 = 4;
k4 = 1;
c1 = 1;
c2 = 0.2;
c3 = 0.1;
c4 = 2;
F1 = 3;
F2 = 9;
F3 = 12;
ydot(1)=y(2)
ydot(2)=((-((k1+k2)./m1)).*y(1))-(((c1+c2)./m1).*y(2))+((k2./m1).*y(3))+ ((c2./m1).*y(4))+(F1./m1)
ydot(3)=y(4)
ydot(4)=((k2./m2).*y(1))+((c2./m2).*y(2))-(((k2+k3)./m2).*y(3))-(((c2+c3).*m2).*y(4))+((k3/m2).*y(5))+((c3./m2).*y(6))+(F2./m2)
ydot(5)=y(6)
ydot(6)=((k2./m3).*y(3))+((c3./m3).*y(4))-(((k3+k4)./m3).*y(5))-(((c3+c4)./m3).*y(6))+(F3./m3)
MATLAB keeps returning the following error message:
Not enough input arguments.
Error in Untitledrt (line 24)
ydot(1)=y(2)
I understand that the error is due to not defining the y terms. Some other examples of ODE45 solver codes also do not define y terms. Is there something I am missing? Or someone can please suggest something to make this code work without defining y terms. Thank you in advance.
y
must be a vector – Mikhail Genkinz
here would be thet
of the ODE, which you're not using (meaning your system is autonomous). In this case you should be able to replace it with ~, i.e.function ydot=Untitledrt(~,y)
, which in many cases MATLAB will recognise and help speed up the code by not instantiating that variable when making the call. Might not be an an issue here, but a good habit to develop. – Steve Heim