Solving ODEs using matlab (ode45)

조회 수: 18(최근 30일)
Pazzo Giampalo
Pazzo Giampalo 2013년 7월 19일
답변: SANDEEP KUMAR R 2016년 9월 14일
I am new to matlab. I was trying to follow an instruction from
I want to use ode45 to solve ODEs.
I have the following in my function page:
function dxy = diffxy (t, xy)
x = xy(1);
xdot = xy(2);
y = xy(3);
xdot = xdot;
ydot = 3*x+5;
xdoubledot = 3-ydot+2*xdot
dxy = [xdot; xdoubledot; ydot]
To get a solution, I type [T, XY] ode45 ('diffxy', 0, 10, [0 1 0]) in my command window (t from 0 to 10 and the initial value of x is 0, xdot is 1, and ydot is 0). But the following message :
??? [T, XY] ode45 ('diffxy', 0 10, [0 1 0])
Error: Unexpected MATLAB expression.
I wonder if anyone could please help.
  댓글 수: 1
Jan 2013년 7월 20일
편집: Jan 2013년 7월 20일
What is "my function page"?
I've formatted your code. Please read the "? Help" link to find out, how to do this by your own. Thanks.
You need an additional "=" to assign the output.

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


Matt Kindig
Matt Kindig 2013년 7월 19일
Did you forget the assignment sign?
[T, XY] = ode45 ('diffxy', 0 10, [0 1 0])
  댓글 수: 2
Jan 2013년 7월 20일
Please explain "didn't work" with details. And we have to know, where you have written the shown code.

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

Pazzo 2013년 8월 3일
I found out that I should add a bracket, [ ],along with an equal sign, =, to make it work.
thank you for your help though.

SANDEEP KUMAR R 2016년 9월 14일
Instead of 'diffxy' use @diffxy in ode45


Community Treasure Hunt

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

Start Hunting!

Translated by