Labels dont show up
2 ビュー (過去 30 日間)
古いコメントを表示
Hello,
Why does only the label for the last curve shows up? How do I get the labels to all show up on the same plot? I am graphing 3 different Euler's approximations and then an exact solution for an ODE on the same plot. Also how do I label the axis ?
f = @(t,y) t*y-y;
y0 = 0.5;
t = 0:0.2:1;
[t,y1] = euler(f,t,y0);
plot(t,y1)
legend('Euler 0.2')
hold on
t = 0:0.1:1;
[t,y3] = euler(f,t,y0);
plot(t,y3)
legend('Euler 0.1')
t = 0:0.05:1;
[t,y4] = euler(f,t,y0);
plot(t,y4)
legend('Euler 0.05')
[t,y2] = ode45(f,[0 10],y0);
plot(t,y2,'LineWidth',3)
legend('Exact solution')
0 件のコメント
回答 (1 件)
Shubham Gupta
2019 年 9 月 24 日
編集済み: Shubham Gupta
2019 年 9 月 24 日
One way to do this :
f = @(t,y) t*y-y;
y0 = 0.5;
t = 0:0.2:1;
[t,y1] = euler(f,t,y0);
plot(t,y1,'DisplayName','Euler 0.2');
hold on
t = 0:0.1:1;
[t,y3] = euler(f,t,y0);
plot(t,y3,'DisplayName','Euler 0.1');
t = 0:0.05:1;
[t,y4] = euler(f,t,y0);
plot(t,y4,'DisplayName','Euler 0.05');
[t,y2] = ode45(f,[0 10],y0);
plot(t,y2,'LineWidth',3,'DisplayName','Exact solution');
legend show
I hope it helps !
0 件のコメント
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!