Problem with ODE solver

조회 수: 2 (최근 30일)
Mohammad Quddus
Mohammad Quddus 2012년 2월 22일
I would like to solve a simple parabolic equation, y=2*x^2 from -4 to 4. So I use ode45 to solve this problem according to the code below:
[T,Y] = ode113(@para,[-4 4],32,[],4);
plot (T,Y);
function dy = para(t,y,a)
dy=a*y; % as dy/dx= 4*x
Its giving me wiered results. Can you guys tell me what' going on here. I also tried other ODE functions. All of them are giving me the wrong results.

채택된 답변

Grzegorz Knor
Grzegorz Knor 2012년 2월 22일
[T,Y] = ode113(@(x,y)4*x,[-4 4],32);
fplot('2*x.^2',[-4 4])
hold on
plot (T,Y,'ro')
  댓글 수: 1
Mohammad Quddus
Mohammad Quddus 2012년 2월 23일
Thanks a lot for helping me out. This no give me the celar picture of how to use ODE if the right hand side of the equation is only a f(x), instead of f(x,y).

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt Tearle
Matt Tearle 2012년 2월 22일
Your equation is defining dy/dx = ay, not dy/dx = ax. Big difference! The solution to the former is y(x) = C*exp(ax); the solution to the latter is y(x) = ax^2/2, as you were hoping for.
So
function dy = para(x,y,a)
dy=a*x; % as dy/dx= 4*x
(I'm vaguely curious why you'd want to bother with an ODE solver for an integral of this kind, but that's a side-issue.)
  댓글 수: 1
Mohammad Quddus
Mohammad Quddus 2012년 2월 23일
Yes you are right. I was looking for the second one. I know it is really simple and noone should be bothered about solving this kind of silly equation with ODE functions.
However I post this as I was not sure about how to right the ODE if it is only a f(x) instead of f(x,y). So based on these two answers I now have the clear picture about how to write the ODE function for both f(x) and f(x,y). Sometimes you know very silly things you can't figure out when you are running behind time.
Anyway thank you for your answer. really appreciate.

댓글을 달려면 로그인하십시오.

카테고리

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