Plotting system of differential equations

Hi,
does anybody know the code to plot a system of differential equations? For example say,
x1(dot) = -x2 + (x1)^2 -(x1*x2)
x2(dot) = x1 + (x1*x2)
Thanks in advance! :)
Sajith.

 採用された回答

Star Strider
Star Strider 2015 年 3 月 24 日

1 投票

Yes.
Use ode45 to integrate your equations, then plot the solution.
Give it a go. It should be very easy for you to cast your system of equations as an Anonymous Function. If you have problems with your code, we can help you get it running.

5 件のコメント

Sajith Dharmasena
Sajith Dharmasena 2015 年 3 月 24 日
I'm not very familiar with MATLAB. Do you think you could show me how to use ode45 and then plot the functions?
Sajith
Star Strider
Star Strider 2015 年 3 月 24 日
Since you already Accepted my Answer, here you go:
odesys = @(t,x) [(-x(2) + (x(1)).^2 -(x(1).*x(2))); (x(1) +
(x(1).*x(2)))];
x0 = [0; 1]; % Initial Conditions
tspan = [0 60]; % Time Of Integration
[t, x] = ode45(odesys, tspan, x0); % Integrate
figure(1)
plot(t, x)
grid
legend('x_1(t)', 'x_2(t)', 'Location', 'NE')
You didn’t specify time span (‘tspan’) or initial conditions (‘x0’), so you may want to revisit those, and specify different values.
Sajith Dharmasena
Sajith Dharmasena 2015 年 3 月 24 日
Thank you so much for your help!
Sajith Dharmasena
Sajith Dharmasena 2015 年 3 月 24 日
How do you plot x1 vs x2? (phase plane)
Star Strider
Star Strider 2015 年 3 月 24 日
You plot just that:
plot(x(:,1), x(:,2))

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by