Plot 4 diagrams in one plot
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, I want to plot 4 diagrams in one plot. Actual i have two plots with 4 different values:
clear ;clc
mu=[0 0.1 1 10];
tspan=[0 20*pi];
x0=0.5;dx0=0;
IC=[x0 dx0]; % initial conditions
for i=1:4
dxdt=@(t,x)[x(2);
mu(i)*(1-x(1)^2)*x(2)-x(1)];
[T,X]=ode45(dxdt,tspan,IC);
figure(1)
plot(T,X(:,1))
hold on
xlabel('t')
ylabel('x(t)')
figure(2)
plot(X(:,1),X(:,2))
hold on
xlabel('x(t)')
ylabel('v(t)')
end
figure(1)
legend('mu=0','mu=0.1','mu=1','mu=10')
figure(2)
legend('mu=0','mu=0.1','mu=1','mu=10')
I want 4 diagrams for each value in one window (like on the right side of my picture). I have tried to input this code: But this doesn't work very good:
ax1 = subplot(2,2,i);
hold on
grid on
box on
It should look something like this:
0 Commenti
Risposte (1)
Alan Stevens
il 24 Nov 2020
Like this?
mu=[0 0.1 1 10];
tspan=[0 20*pi];
x0=0.5;dx0=0;
IC=[x0 dx0]; % initial conditions
for i=1:4
dxdt=@(t,x)[x(2);
mu(i)*(1-x(1)^2)*x(2)-x(1)];
[T,X]=ode45(dxdt,tspan,IC);
if i==1 || i==3
subplot(2,2,i)
plot(T,X(:,1))
xlabel('t')
ylabel('x(t)')
else
subplot(2,2,i)
plot(X(:,1),X(:,2))
xlabel('x(t)')
ylabel('v(t)')
end
end
5 Commenti
Alan Stevens
il 24 Nov 2020
Or, (finally!):
mu=[0 0.1 1 10];
tspan=[0 20*pi];
x0=0.5;dx0=0;
IC=[x0 dx0]; % initial conditions
for i=1:4
dxdt=@(t,x)[x(2);
mu(i)*(1-x(1)^2)*x(2)-x(1)];
[T,X]=ode45(dxdt,tspan,IC);
if i==1 || i==2
figure(1)
subplot(2,2,i)
plot(T,X(:,1))
xlabel('t')
ylabel('x(t)')
figure(2)
subplot(2,2,i)
plot(T,X(:,2))
xlabel('t')
ylabel('v(t)')
elseif i ==3
figure(1)
subplot(2,2,i)
plot(T,X(:,1))
xlabel('t')
ylabel('x(t)')
figure(2)
subplot(2,2,i)
plot(T,X(:,2))
xlabel('t')
ylabel('v(t)')
else
figure(1)
subplot(2,2,4)
plot(T,X(:,1))
xlabel('t'),ylabel('x(t)')
figure(2)
subplot(2,2,4)
plot(T,X(:,2))
xlabel('t'),ylabel('v(t)')
end
end
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!