필터 지우기
필터 지우기

Using subplot with ode45?

조회 수: 3 (최근 30일)
Erin W
Erin W 2016년 10월 27일
댓글: Erin W 2016년 10월 27일
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? :)

채택된 답변

KSSV
KSSV 2016년 10월 27일
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
Erin W
Erin W 2016년 10월 27일
Fantastic! That completely fixes my problem. Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by