Tengo el siguiente código y quiero combinar gráficas de espacio de fase en una sola figura.Múltiples gráficas en una figura
He codificado las funciones, pero no sé cómo hacer que MATLAB las incluya en una sola figura. Como puede ver, son las variables r
, a
, b
y d
las que cambian. ¿Cómo los combino?
También me gustaría trazar el campo vectorial de estos gráficos de fase de espacio utilizando el comando quiver, pero simplemente no funciona.
%function lotkavolterra
% Plots time series and phase space diagrams.
clear all; close all;
t0 = 0;
tf = 20;
N0 = 20;
P0 = 5;
% Original plot
r = 2;
a = 1;
b = 0.2;
d = 1.5;
% Time series plots
lv = @(t,x)(lv_eq(t,x,r,a,b,d));
[t,NP] = ode45(lv,[t0,tf],[N0 P0]);
N = NP(:,1); P = NP(:,2);
figure
plot(t,N,t,P,' --');
axis([0 20 0 50])
xlabel('Time')
ylabel('predator-prey')
title(['r=',num2str(r),', a=',num2str(a),', b=',num2str(b),', d=',num2str(d)]);
saveas(gcf,'predator-prey.png')
legend('prey','predator')
% Phase space plot
figure
quiver(N,P);
axis([0 50 0 10])
%axis tight
% Change variables
r = 2;
a = 1.5;
b = 0.1;
d = 1.5;
%time series plots
lv = @(t,x)(lv_eq(t,x,r,a,b,d));
[t,NP] = ode45(lv,[t0,tf],[N0 P0]);
N = NP(:,1); P = NP(:,2);
figure
plot(t,N,t,P,' --');
axis([0 20 0 50])
xlabel('Time')
ylabel('predator-prey')
title(['r=',num2str(r),', a=',num2str(a),', b=',num2str(b),', d=',num2str(d)]);
saveas(gcf,'predator-prey.png')
legend('prey','predator')
% Phase space plot
figure
plot(N,P);
axis([0 50 0 10])
% Change variables
r = 2;
a = 1;
b = 0.2;
d = 0.5;
% Time series plots
lv = @(t,x)(lv_eq(t,x,r,a,b,d));
[t,NP] = ode45(lv,[t0,tf],[N0 P0]);
N = NP(:,1); P = NP(:,2);
figure
plot(t,N,t,P,' --');
axis([0 20 0 50])
xlabel('Time')
ylabel('predator-prey')
title(['r=',num2str(r),', a=',num2str(a),', b=',num2str(b),', d=',num2str(d)]);
saveas(gcf,'predator-prey.png')
legend('prey','predator')
% Phase space plot
figure
plot(N,P);
axis([0 50 0 10])
% Change variables
r = 0.5;
a = 1;
b = 0.2;
d = 1.5;
% Time series plots
lv = @(t,x)(lv_eq(t,x,r,a,b,d));
[t,NP] = ode45(lv,[t0,tf],[N0 P0]);
N = NP(:,1); P = NP(:,2);
figure
plot(t,N,t,P,' --');
axis([0 20 0 50])
xlabel('Time')
ylabel('predator-prey')
title(['r=',num2str(r),', a=',num2str(a),', b=',num2str(b),', d=',num2str(d)]);
saveas(gcf,'predator-prey.png')
legend('prey','predator')
% Phase space plot
figure
plot(N,P);
axis([0 50 0 10])
% FUNCTION being called from external .m file
%function dx = lv_eq(t,x,r,a,b,d)
%N = x(1);
%P = x(2);
%dN = r*N-a*P*N;
%dP = b*a*P*N-d*P;
%dx = [dN;dP];
Hola de nuevo ... Muchas gracias por su ayuda. Ahora he logrado trazar todas las figuras en una figura (eche un vistazo a mi figura, se ve bien :)) ¿Podrían ayudarme también a trazar el vector archivado utilizando el comando temblor? ...
user1135423