Filter löschen
Filter löschen

ODE: equation solution problem

3 Ansichten (letzte 30 Tage)
Pinco
Pinco am 30 Aug. 2012
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

Akzeptierte Antwort

Matt Tearle
Matt Tearle am 30 Aug. 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;
  1 Kommentar
Pinco
Pinco am 30 Aug. 2012
Thanks so much!! It works perfectly!! :D :D

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by