필터 지우기
필터 지우기

3 lines and 3 different y axes on one plot?

조회 수: 3 (최근 30일)
Joey
Joey 2014년 5월 1일
답변: Sara 2014년 5월 1일
I need to plot 3 different sets of Y values for the same values of T on one plot. It needs to look something like the pic I attached. I've read docs on plotting with different axes but they make no sense to me.
  댓글 수: 2
Image Analyst
Image Analyst 2014년 5월 1일
Please attach your data, or give us an m-file that can generate it so people can try something.
Joey
Joey 2014년 5월 1일
편집: Joey 2014년 5월 1일
I attached it. I "assignin" the T and Y matrix to the base workspace. Y(:,1) is commoners, Y(:,2) is nature, and Y(:,3) is wealth.

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

답변 (1개)

Sara
Sara 2014년 5월 1일
First, you need to pass the parameter to the ode function. I cut and pasted them there but you can add them after l in the ode call. The last 4 lines in figures3 produce the plot. Is that what you were looking for? Use xlabel and ylabel to add axes titles.
function figures3()
% with xE=0 (no elites): egalitarian society
% xC(0) = 100 , xE(0) = 0 , y(0) = l , w(0) = 0
% 3a: d = 6.67e-6
% 3b: d = 1.67e-5
% 3c: d = 2.67e-5
% 3d: d = 3.67e-5
l = 100; %nature carrying capacity
options = odeset('RelTol',1e-4);
[T,Y] = ode45(@fun,[0 1000],[100; l; 0],options,l);
assignin('base','T',T)
assignin('base','Y',Y)
for i = 1:3
plot(T,Y(:,i),'color',rand(3,1)),hold on
end
legend('var1','var2','var3',2)
function [dz] = fun(t,z,l)
d = 6.67e-6; %depletion rate
am = .01; %normal (min) death rate
aM = .07; %famine (max) death rate
bC = .03; %commoner birth rate
bE = .03; %elite brith rate
s = .0005; %subsistence salary per capita
p = .005; %threshold wealth per capita
g = .01; %regeneration rate of nature
k = 1; %inequality factor
n = (aM-bC)/(aM-am);
XM = (g*(l/2)^2)/(n*s); % max carry capacity
xE = 0;
wth = p.*z(1)+k*p.*xE; % wealth threshold
CC = min(1,z(3)./wth)*s.*z(1); % consumption rate commoners , s is subsistence salary per captia
CE = min(1,z(3)./wth)*k.*s.*xE; % consumption rate elite , k is the factor of salary larger than commoners
aC = am+max(0,1-CC/(s.*z(1))).*(aM-am); % death rate commoners
aE = am+max(0,1-CC/(s.*xE)).*(aM-am); % death rate elite
dz=[bC.*z(1)-aC.*z(1); g.*z(2).*(l-z(2))-d.*z(1).*z(2); d.*z(1).*z(2)-CC-CE;];

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by