フィルターのクリア

ODE: equation solution problem

3 ビュー (過去 30 日間)
Pinco
Pinco 2012 年 8 月 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;
  1 件のコメント
Pinco
Pinco 2012 年 8 月 30 日
Thanks so much!! It works perfectly!! :D :D

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by