필터 지우기
필터 지우기

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 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