how to use ode45 ?
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 ?
0 comentarios
Respuestas (1)
Cris LaPierre
el 19 de Mzo. de 2020
Editada: Cris LaPierre
el 19 de Mzo. de 2020
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);
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!