Hello,
Here is a working simple script for solving an ODE.
clear all;clcclose alltime_period = [0 10]; % tmin,tmax
initial = [0,10]; % initial cond [t,y]
[t,y]= ode45(@myode45function, time_period, initial);figure(1)plot(t,y(:,1))axis([0 10 0 12])title('ODE solution: y(t)=2-2*exp(-0.2*t) ','Fontweight','bold','fontsize',14);function dy_dt = myode45function(t,y)dy_dt=[0.4-y*0.2] % Output : dy_dt
end
Question :
If i want to solve an ODE which contain values as variables, how can i make the script work?
Like if i wanted to solve this : dy_dt=[0.4-y*0.2*b+d] , where for example b=2, d=3
If i define b=2, d=3 at the beginnihg of the script, and write
[t,y]= ode45(@myode45function, time_period, initial,b,d);...function dy_dt = myode45function(t,y,b,d)
It gives the error message like :
Not enough input arguments.Error in Untitled3>myode45function (line 19)dy_dt=[0.4-y*0.2*b] % Output : dy_dtError in odearguments (line 90)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 Untitled3 (line 9)[t,y]= ode45(@myode45function, time_period, initial,b);
Can anyone help what is the proper way to do this? I want to give value to parameters (like b,d) at in the script, not in the myode45function
Thanks!
Best Answer