Solving ODEs using matlab (ode45)

Hello,
I am new to matlab. I was trying to follow an instruction from mit.edu.
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.
Thankyou!
Pazzo

1 件のコメント

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

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

回答 (3 件)

Matt Kindig
Matt Kindig 2013 年 7 月 19 日

0 投票

Did you forget the assignment sign?
[T, XY] = ode45 ('diffxy', 0 10, [0 1 0])

2 件のコメント

Pazzo Giampalo
Pazzo Giampalo 2013 年 7 月 20 日
thank you Matt, but no, that didn't work. I guess my question is, when I have the function page written out, how do I call that function (execute it) in my command window? I tried to look up online, but still not figure it out using ode45.
Jan
Jan 2013 年 7 月 20 日
Please explain "didn't work" with details. And we have to know, where you have written the shown code.

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

Pazzo
Pazzo 2013 年 8 月 3 日

0 投票

Jan,
I found out that I should add a bracket, [ ],along with an equal sign, =, to make it work.
thank you for your help though.
Pazzo
SANDEEP KUMAR R
SANDEEP KUMAR R 2016 年 9 月 14 日

0 投票

Instead of 'diffxy' use @diffxy in ode45

カテゴリ

タグ

質問済み:

2013 年 7 月 19 日

回答済み:

2016 年 9 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by