Using odesolver with functions that have many inputs

4 visualizaciones (últimos 30 días)
Arun
Arun el 10 de Jun. de 2011
I'm trying to use ode45 to integrate a first order differential equation. The first line of my function m-file is
function dEds = dPdE(s, E, U0, H0, mu, T, t, initial, final,timestep)
s is my independent variable, and E(s) is what I am solving for. All the other variables are matrices or scalars, and are used in the m-file. My question is, when using ode45, how do I specify these other variables? On this page
other inputs are being put in after the (blank) options, and I verified for myself that it can work, but I haven't seen any documentation refer to that. Furthermore it doesn't seem to be working when I try and solve my equation:
[s E]=ode45(@dPdE,[0 5],E(321),[],U0,H0,mu,5,3.2,2,3,.01);
It says too many input arguments. How can I make this go?
(A more trivial question I have is whether I need to put s as an input argument if the function never uses it.)

Respuesta aceptada

Andrew Newell
Andrew Newell el 10 de Jun. de 2011
The documentation in the link you provide probably applies to an older version of MATLAB than you have. Instead, create an anonymous function:
f = @(s,E) dPdE(s, E, U0, H0, mu, T, t, initial, final,timestep);
Then you can solve the equation using
[s, E]=ode45(f,[0 5],E(321));
Yes, you do need to provide s as an input argument.

Más respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by