%% Illustration of a PVT diagram 7.6.1999, 3.4.2006 revisited 29. 09. 2009
rr=8314;                % R
r=1/rr;                 % 1/R
ii1=3;                  % degrees of freedom (dof) one atom
ii2=6;                  % dof nonlinear molecule
p=(0:10:1000);          % [Pa]
v=(0:10:1000);          % [m^3]
ms=3;
[V,P]=meshgrid(v,p);
T=r*P.*V;               % [K]
% 3-dim plot T(P,V)
f1=figure;              
meshc(V,P,T); hold on; xlabel('V [m^3]'); ylabel('P [Pa]'); zlabel('T [K]'); title('EOS 3D');
% point A
pa=800; va=400; ta=r*pa.*va;
% A -> B isochoric path
pb=(pa:-10:200); vb=va*ones(size(pb)); tb=r*pb.*vb;
plot3(vb,pb,tb,'ko','markersize',ms);
% A -> C isobaric path
vc=(va:10:800); pc=pa*ones(size(vc)); tc=r*pc.*vc;
plot3(vc,pc,tc,'b*','markersize',ms);
% A -> D izothermic path
vd=(va:10:800); pd=rr*ta./vd; td=ta*ones(size(vd));
plot3(vd,pd,td,'r*','markersize',ms);
% A -> E adiabatic path ii1=3
ka1=(ii1+2)/ii1; qa1=pa*va^ka1;
ve=vd; pe=(qa1./(ve.^ka1)); te=r*pe.*ve;
plot3(ve,pe,te,'m*','markersize',ms);
% A -> F adiabatic path ii2=6
ka2=(ii2+2)/ii2; qa2=pa*va^ka2;
vf=vd; pf=(qa2./(vf.^ka2)); tf=r*pf.*vf;
plot3(vf,pf,tf,'c*','markersize',ms);
% A -> G polytropic ga=1.25;
ga=1.2; qa3=pa*va^ga;
vg=vd; pg=(qa3./(vg.^ga)); tg=r*pg.*vg;
plot3(vg,pg,tg,'y*','markersize',ms);
text(va-100,pa,ta,'A','fontsize',20);
% contour of the T(P,V) - P-V diagram
f2=figure;              
contour(V,P,T); hold on; xlabel('V [m^3]'); ylabel('P [Pa]');
plot(vb,pb,'ko','markersize',ms);   % isochoric
plot(vc,pc,'b*','markersize',ms);   % isobaric
plot(vd,pd,'r*','markersize',ms);   % isothermic
plot(ve,pe,'m*','markersize',ms);   % adiabatic ii1=3
plot(vf,pf,'c*','markersize',ms);   % adiabatic ii1=6
plot(vg,pg,'y*','markersize',ms);   % polytropic ga=1.25
text(va-60,pa,'A','fontsize',20);
legend('isothermes','isochoric','isobaric','isothermic','adiabatic i = 3','adiabatic i = 6','polytropic g = 1.2');
title('P-V diagram (3D from above)');
% contour of the P(T,V) - T-V diagram
f3=figure;              
contour(V,T,P); hold on; xlabel('V [m^3]'); ylabel('T [K]');
plot(vb,tb,'ko','markersize',ms);
plot(vc,tc,'b*','markersize',ms);
plot(vd,td,'r*','markersize',ms);
plot(ve,te,'m*','markersize',ms);
plot(vf,tf,'c*','markersize',ms);
plot(vg,tg,'y*','markersize',ms);
legend('isobares','isochoric','isobaric','isothermic','adiabatic i = 3','adiabatic i = 6','polytropic g = 1.2');
title('T-V diagram (3D from the right)');
% contour of the V(T,P) - T-P diagram
f4=figure;              
contour(P,T,V); hold on; xlabel('P [Pa]'); ylabel('T [K]');
plot(pb,tb,'ko','markersize',ms);
plot(pc,tc,'b*','markersize',ms);
plot(pd,td,'r*','markersize',ms);
plot(pe,te,'m*','markersize',ms);
plot(pf,tf,'c*','markersize',ms);
plot(pg,tg,'y*','markersize',ms);
legend('isochores','isochoric','isobaric','isothermic','adiabatic i = 3','adiabatic i = 6','polytropic g = 1.2');
%%set(gca,'Xdir','reverse');
title('T-P diagram (3D from behind)');
