Using odesolver with functions that have many inputs
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.)
0 commentaires
Réponse acceptée
Andrew Newell
le 10 Juin 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!