Labels dont show up
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Shubham Gupta
il 24 Set 2019
Modificato: Shubham Gupta
il 24 Set 2019
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 Commenti
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!