how to use ode45 ?

6 次查看(过去 30 天)
Célia Lejeune
Célia Lejeune 2020-3-19
Hello,
I create a function called odefun and I need to test it with ode 45 and euler explicit and see which one is the best.
My function is normally all good but I don't know how to use ode 45.
knowing that my function has 5 variables
this is what I put:
[T,Y]=ode45 (@odefun, [25,29],[10,200,1000,15,5],vectorize,varargin)
this is the warning:
Not enough input arguments.
Error in vectorize (line 17)
v = char(s);
could you help me ?

回答(1 个)

Cris LaPierre
Cris LaPierre 2020-3-19
编辑:Cris LaPierre 2020-3-19
We don't know what odefun or vectorize are, but it doesn't make sense to be using varargin here. Have you tried looking at the doc page? There are some simple examples there that might help. Here's one I modified slightly to match your calling syntax above.
A = 1;
B = 2;
tspan = [0 5];
y0 = [0 0.01];
[t,y] = ode45(@odefcn,tspan, y0, [],A, B);
plot(t,y(:,1),'-o',t,y(:,2),'-.')
function dydt = odefcn(t,y,A,B)
dydt = zeros(2,1);
dydt(1) = y(2);
dydt(2) = (A/B)*t.*y(1);
end
Note that ode45 has to have the first 2 inputs be time and initial conditions. These correspond to the odefcn inputs t and y. The empty brackets are for options. I can then tack on any remaining inputs to odefcn after that in order (A, then B).
The other way is to use the calling syntax shown in the doc:
[t,y] = ode45(@(t,y) odefcn(t,y,A,B), tspan, y0);

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by