I am trying to get an ode45 code to plot the differential equation.
My code is:
tspan = [0 100];y0 = [0,0];[tout,yout] = ode45(@prob1,ts,y0);plot(t,y(:,3))grid onxlabel('Time')ylabel('x(t)')
and
function ydot = prob1(t,y)ydot(1) = [-6*y(1) - 2*y(2) - 5*y(3) + .5*step(t)];ydot(2) = y(1);ydot(3) = y(2);ydot = [ydot(1);ydot(2);ydot(3)];end
but it is giving me an error of when I run the function of "undefined function or variable t" and when I run the ode45 script is gives:
Index exceeds matrix dimensions.Error in prob1 (line 3)ydot(1) = [-6*y(1) - 2*y(2) - 5*y(3) + .5*step(t)];Error in odearguments (line 87)f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);Error in prob1_file (line 4)[tout,yout] = ode45(@prob1,ts,y0);
Any advice would be greatly appreciated.
Best Answer