Here is the funciton:
function [Y] = d_o(X,t,m,k,c)x = X(1);y = X(2);Y(1,1)=y;Y(2,1)=1/m*(-k*x-c*y);end
Here is the script:
T = 0:0.1:100;y0 = [0.1,1];m = 1; k = 0.1; c = 0.05;d_o_an = @(X,t) d_o(X,t,m,k,c);[tout,yout] = ode45(d_o_an,T,y0);plot(tout, yout);
I think the problem is in the anonymous function, if I change @(X,t) to @(t,X), the code can run. But why?
Best Answer