Plot several solution curves to y'(t) = y(t) - t

18 ビュー (過去 30 日間)
Carla Roos
Carla Roos 2022 年 11 月 30 日
コメント済み: Carla Roos 2022 年 11 月 30 日
Hi!
I want to plot several solution curves to an ODE using ode45. My main problem is that I do not understand how to write y(t) - t.
The whole equation is as following:
y'(t) = y(t) - y, 0 <= t <= 2, with the initial conditions y(0) E [-2, 2].
I have tried solving it by using syms y(t) without any success...
Best regards

採用された回答

Sam Chak
Sam Chak 2022 年 11 月 30 日
You can create an anonymous function of t and y.
fun = @(t, y) y - t; % <--- Type like this
% solve for y(0) = 2
[t, y] = ode45(fun, [0 2], 2);
plot(t, y), hold on
% solve for y(0) = -2
[t, y] = ode45(fun, [0 2], -2);
plot(t, y), hold off,
grid on, xlabel('t'), ylabel('y(t)'),
legend('y(0) = 2', 'y(0) = –2')
  1 件のコメント
Carla Roos
Carla Roos 2022 年 11 月 30 日
Thank you very much!
Hope you have a great day! :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by