ODE: equation solution problem

1 次查看(过去 30 天)
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

采纳的回答

Matt Tearle
Matt Tearle 2012-8-30
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;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by