How can I use odeset and some variable parameters within ode45?
5 views (last 30 days)
Show older comments
OMID Ahmadi
on 13 Oct 2013
Commented: OMID Ahmadi
on 14 Oct 2013
I would like to solve the following ODE function:
*******************
function dc=reaction(t,c,s,q,w) % c is concentartion variable for all three substances.
dc = zeros(3,1); % a column vector
dc(1)=s*(c(2)-(c(2)*c(1))+c(1)-q*(c(1)^2));
dc(2)=(-c(2)-c(1)*c(2)+c(3))/s;
dc(3)=(c(1)-c(3))*w;
****************
where s, q and w are variables that could be changed / defined in the main code.
*******************
clc,clf,
c0=[25.00 1.000 20.00]; % initial values
tspan=[0 15]; % time range
s=1; q=1; w=0.2; % parameters
options = odeset('RelTol',1e-8);
[t,c] = ode45(@reaction,tspan,c0,options,[],s,q,w);
%[t,c] = ode45(@reaction,tspan,c0,[],s,q,w,options);
Non of the above ode45 syntaxes work and I get an error message saying:
??? Error using ==> reaction
Too many input arguments.
Error in ==> odearguments at 110
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in ==> concentration_mh2 at 21
[t,c] = ode45(@reaction,tspan,c0,[],s,q,w,options);
I wonder what is the correct syntax in this case, I even tried evoking the reaction function by an anonymous function in the main code but it did not work fro me!
I appreciate if one can suggest me the right approach.
0 Comments
Accepted Answer
Azzi Abdelmalek
on 13 Oct 2013
[t,c] = ode45(@(t,c) reaction(t,c,s,q,w),tspan,c0,options);
3 Comments
Azzi Abdelmalek
on 13 Oct 2013
If you want more samples, use
options = odeset('MaxStep',1e-2);
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!