3 lines and 3 different y axes on one plot?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Image Analyst
am 1 Mai 2014
Please attach your data, or give us an m-file that can generate it so people can try something.
Antworten (1)
Sara
am 1 Mai 2014
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;];
0 Kommentare
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!