Filter löschen
Filter löschen

Using subplot with ode45?

3 Ansichten (letzte 30 Tage)
Erin W
Erin W am 27 Okt. 2016
Kommentiert: Erin W am 27 Okt. 2016
Hi,
I need to evaluate a nonlinear ode at different values of r and then use subplot to plot them but I can't get subplot to work. Each plots on it's own just fine but the subplot piece doesn't work.
%determine the behavior of the host population in
%the absence of a parasitoid population for different
%values of r
N(1) = 20;
K = 50;
r1 = 1;
r2 = 2;
r3 = 3;
r4 = 4;
tspan = [1,1000];
N0 = 20;
[t,N] = ode45(@(t,N) N(1)*exp(r1*(1-(N(1)/K))), tspan, N0);
plot(t,N,'-o')
tspan = [1,1000];
M0 = 20;
[t,M] = ode45(@(t,M) M(1)*exp(r2*(1-(M(1)/K))), tspan, M0);
plot(t,M,'-o')
tspan = [1,1000];
G0 = 20;
[t,G] = ode45(@(t,G) G(1)*exp(r3*(1-(G(1)/K))), tspan, G0);
plot(t,G,'-o')
tspan = [1,1000];
H0 = 20;
[t,H] = ode45(@(t,H) H(1)*exp(r4*(1-(H(1)/K))), tspan, H0);
plot(t,H,'-o')
figure
subplot(2,2,1)
plot(t,N,'-o')
title('r=1)')
subplot(2,2,2)
plot(t,M,'-o')
title('r=2')
subplot(2,2,3)
plot(t,G,'-o')
title('r=3')
subplot(2,2,4)
plot(t,H,'-o')
title('r=4')
Help? :)

Akzeptierte Antwort

KSSV
KSSV am 27 Okt. 2016
Each time 't' changing while running ode45. Consider naming 't' differently.
clc; clear all ;
%determine the behavior of the host population in
%the absence of a parasitoid population for different
%values of r
N1 = 20;
K = 50;
r1 = 1;
r2 = 2;
r3 = 3;
r4 = 4;
tspan = [1,1000];
N0 = 20;
[t1,N] = ode45(@(t,N) N(1)*exp(r1*(1-(N(1)/K))), tspan, N0);
plot(t1,N,'-o')
tspan = [1,1000];
M0 = 20;
[t2,M] = ode45(@(t,M) M(1)*exp(r2*(1-(M(1)/K))), tspan, M0);
plot(t2,M,'-o')
tspan = [1,1000];
G0 = 20;
[t3,G] = ode45(@(t,G) G(1)*exp(r3*(1-(G(1)/K))), tspan, G0);
plot(t3,G,'-o')
tspan = [1,1000];
H0 = 20;
[t4,H] = ode45(@(t,H) H(1)*exp(r4*(1-(H(1)/K))), tspan, H0);
plot(t4,H,'-o')
figure
subplot(2,2,1)
plot(t1,N,'-o')
title('r=1)')
subplot(2,2,2)
plot(t2,M,'-o')
title('r=2')
subplot(2,2,3)
plot(t3,G,'-o')
title('r=3')
subplot(2,2,4)
plot(t4,H,'-o')
title('r=4')
  1 Kommentar
Erin W
Erin W am 27 Okt. 2016
Fantastic! That completely fixes my problem. Thank you!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by