ODE: equation solution problem
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone!
I'm using ode solvers for the first time, and I have some problems. I want to resolve y'(x) + 3 y(x) - 6x = 0, I use this code:
f = inline(' 6*x - 3*y');
[x,y] = ode45(f,[0 2],0);
plot(x,y)
obtaining correct result. Now I want to resolve y'(x) + 3 y(x) = 0. I wrote:
f = inline('- 3*y');
[x,y] = ode45(f,[0 2],0);
plot(x,y)
but there are errors:
"Error using inline/feval (line 25)
Too many inputs to inline function.
Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...]"
The same if I try to resolve y'(x) + 3y(x) = 2. How can I resolve this?
Thanks in advance.
Pinco
0 commentaires
Réponse acceptée
Matt Tearle
le 30 Août 2012
The problem is that the ODE solvers expect a function of two variables (x & y, in your case), but there's only one variable name in your second function. So one solution is to fake it:
f = inline('0*x-3*y');
But a better approach is to use function handles instead of inline:
f = @(x,y) 6*x - 3*y;
or
f = @(x,y) -3*y;
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!