Azzera filtri
Azzera filtri

3 lines and 3 different y axes on one plot?

3 visualizzazioni (ultimi 30 giorni)
Joey
Joey il 1 Mag 2014
Risposto: Sara il 1 Mag 2014
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 Commenti
Image Analyst
Image Analyst il 1 Mag 2014
Please attach your data, or give us an m-file that can generate it so people can try something.
Joey
Joey il 1 Mag 2014
Modificato: Joey il 1 Mag 2014
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.

Accedi per commentare.

Risposte (1)

Sara
Sara il 1 Mag 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;];

Categorie

Scopri di più su Visual Exploration in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by