0% found this document useful (0 votes)
15 views4 pages

Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

P= zeros(1,100);

V= zeros(1,100);
T= zeros(1,100);
n= input('enter moles: ');
P(1)= input('enter initial pressure: ');
V(1)= input ('enter initial volume: ');
T(1)= (P(1)*V(1))/(n*0.082); ipoint= 1;
fontSize = 20;xlabel('V', 'FontSize', fontSize);
ylabel('P', 'FontSize', fontSize);
hold on;
plot(V(1),P(1),'.');textString = sprintf('(%.2f;%.2f)', V(1), P(1));
text(V(1), P(1)+0.1, textString, 'FontSize', 10, 'Color', 'r');
W= 0;
SumW= 0;
msg2= "select monoatomic or diatomic or linear triatomic or non-linear triatomic" ;
opts2= ["monoatomic","diatomic","linear triatomic","non-linear triatomic"];
choice2= menu(msg2,opts2);
display('you choose: ' + opts2(choice2));
for j= 1:length(P)
SumW= SumW+W;
title('Sum of Work(s) = '+ string(SumW) + ' J');
ipoint = ipoint + 1;
fprintf('For #%g \n process',ipoint-1);
msg= "select the process";
opts= ["isobaric","isothermal","isochoric","adiabatic","quit"];
choice= menu(msg,opts);
display('you choose: ' + opts(choice));
if (opts(choice)=="isobaric")
msg1= "select New V or New P";
opts1= ["New V","New T"];
choice1= menu(msg1,opts1);
display('you choose: ' + opts1(choice1));
if(opts1(choice1)=="New V")
V(ipoint)= input('enter new volume: ');
P(ipoint)= P(ipoint-1);
T(ipoint)= V(ipoint)*P(ipoint)/(n*0.082);
W= -1*P(ipoint)*(V(ipoint)-V(ipoint-1))*101.325;
fprintf('Work= %g \n',W);
Vplot= [V(ipoint-1) V(ipoint)];
Pplot= [P(ipoint-1) P(ipoint)];
plot(Vplot,Pplot,'--');
plot(V(ipoint),P(ipoint),'.');
textString = sprintf('(%.2f;%.2f)', V(ipoint), P(ipoint));
text(V(ipoint), P(ipoint)+0.1, textString, 'FontSize', 10, 'Color', 'r');
end
if(opts1(choice1)=="New T")
P(ipoint)= P(ipoint-1);
T(ipoint)= input('enter new temperature: ');
V(ipoint)= (n*0.082*T(ipoint))/P(ipoint);
W= -1*P(ipoint)*(V(ipoint)-V(ipoint-1))*101.325;
fprintf('Work= %g \n',W);
Vplot= [V(ipoint-1) V(ipoint)];
Pplot= [P(ipoint-1) P(ipoint)];
plot(Vplot,Pplot,'--');
plot(V(ipoint),P(ipoint),'.');
textString = sprintf('(%.2f;%.2f)', V(ipoint), P(ipoint));
text(V(ipoint), P(ipoint)+0.1, textString, 'FontSize', 10, 'Color', 'r');
end
end
if (opts(choice)=="isothermal")
msg1= "select New V or New P";
opts1= ["New V","New P"];
choice1= menu(msg1,opts1);
display('you choose: ' + opts1(choice1));
if (opts1(choice1)=="New V")
V(ipoint)= input('enter new volume: ');
P(ipoint)= P(ipoint-1)*V(ipoint-1)/V(ipoint);
T(ipoint)= (P(ipoint-1)*V(ipoint-1))/(n*0.082);
disp(T(ipoint));
W= -n*8.3145*T(ipoint)*log(P(ipoint-1)/P(ipoint));
fprintf('Work= %g \n',W);
Vplot=V(ipoint-1):(V(ipoint)-V(ipoint-1))/20:V(ipoint);
Pplot=n*0.082*T(ipoint)./Vplot;
plot(Vplot,Pplot,'-');
plot(V(ipoint),P(ipoint),'.');
textString = sprintf('(%.2f;%.2f)', V(ipoint), P(ipoint));
text(V(ipoint), P(ipoint)+0.1, textString, 'FontSize', 10, 'Color', 'r');
end
if (opts1(choice1)=="New P")
P(ipoint)= input('enter new pressure: ');
V(ipoint)= V(ipoint-1)*P(ipoint-1)/P(ipoint);
T(ipoint)= (P(ipoint-1)*V(ipoint-1))/(n*0.082);
W= -n*8.3145*T(ipoint)*log(P(ipoint-1)/P(ipoint));
fprintf('Work= %g \n',W);
Pplot=P(ipoint-1):(P(ipoint)-P(ipoint-1))/20:P(ipoint);
Vplot=n*0.082*T(ipoint)./Pplot;
plot(Vplot,Pplot,'-');
plot(V(ipoint),P(ipoint),'.');
textString = sprintf('(%.2f;%.2f)', V(ipoint), P(ipoint));
text(V(ipoint), P(ipoint)+0.1, textString, 'FontSize', 10, 'Color', 'r');
end
end
if (opts(choice)=="isochoric")
msg1= "select New V or New P";
opts1= ["New P","New T"];
choice1= menu(msg1,opts1);
display('you choose: ' + opts1(choice1));
if(opts1(choice1)=="New P")
V(ipoint)= V(ipoint-1);
P(ipoint)= input('enter new pressure: ');
T(ipoint)= T(ipoint-1)*P(ipoint)/P(ipoint-1);
W= 0;
fprintf('Work= %g \n',W);
Vplot= [V(ipoint-1) V(ipoint)];
Pplot= [P(ipoint-1) P(ipoint)];
plot(Vplot,Pplot,'-.');
plot(V(ipoint),P(ipoint),'.');
textString = sprintf('(%.2f;%.2f)', V(ipoint), P(ipoint));
text(V(ipoint), P(ipoint)+0.1, textString, 'FontSize', 10, 'Color', 'r');
end
if(opts1(choice1)=="New T")
V(ipoint)= V(ipoint-1);
T(ipoint)= input('enter new temperature: ');
P(ipoint)= (n*0.082*T(ipoint))/V(ipoint);
W= -1*P(ipoint)*(V(ipoint)-V(ipoint-1))*101.325;
fprintf('Work= %g \n',W);
Vplot= [V(ipoint-1) V(ipoint)];
Pplot= [P(ipoint-1) P(ipoint)];
plot(Vplot,Pplot,'--');
plot(V(ipoint),P(ipoint),'.');
textString = sprintf('(%.2f;%.2f)', V(ipoint), P(ipoint));
text(V(ipoint), P(ipoint)+0.1, textString, 'FontSize', 10, 'Color', 'r');
end
end
if (opts(choice)=="adiabatic")
msg1= "select New V or New P or New T";
opts1= ["New V","New P","New T"];
choice1= menu(msg1,opts1);
display('you choose: ' + opts1(choice1));
if (opts2(choice2)=="monoatomic")
i=3;
ratio= (i+2)/i;
end
if (opts2(choice2)=="diatomic")
i=5;
ratio= (i+2)/i;
end
if (opts2(choice2)=="linear triatomic")
i=5;
ratio= (i+2)/i;
end
if (opts2(choice2)=="non-linear triatomic")
i=6;
ratio= (i+2)/i;
end
if (opts1(choice1)=="New V")
V(ipoint)= input('enter new volume: ');
P(ipoint)= P(ipoint-1)/((V(ipoint)/V(ipoint-1))^ratio);
T(ipoint)= T(ipoint-1)/((V(ipoint)/V(ipoint-1))^(ratio-1));
disp(T(ipoint));
W= n*((i/2)*8.314)*(T(ipoint)-T(ipoint-1));
fprintf('Work= %g \n',W);
Vplot=linspace(V(ipoint-1),V(ipoint),1000);
Pplot=P(ipoint-1)./((Vplot./V(ipoint-1)).^ratio);
plot(Vplot,Pplot,'-');
plot(V(ipoint),P(ipoint),'.');
textString = sprintf('(%.2f;%.2f)', V(ipoint), P(ipoint));
text(V(ipoint), P(ipoint)+0.1, textString, 'FontSize', 10, 'Color', 'r');
end
if (opts1(choice1)=="New P")
P(ipoint)= input('enter new pressure: ');
V(ipoint)= V(ipoint-1)*((P(ipoint-1)/P(ipoint))^(1/ratio));
T(ipoint)= T(ipoint-1)/((V(ipoint)/V(ipoint-1))^(ratio-1));
W= n*((i/2)*8.314)*(T(ipoint)-T(ipoint-1));
fprintf('Work= %g \n',W);
Vplot=linspace(V(ipoint-1),V(ipoint),1000);
Pplot=P(ipoint-1)./((Vplot./V(ipoint-1)).^ratio);
plot(Vplot,Pplot,'-');
plot(V(ipoint),P(ipoint),'.');
textString = sprintf('(%.2f;%.2f)', V(ipoint), P(ipoint));
text(V(ipoint), P(ipoint)+0.1, textString, 'FontSize', 10, 'Color', 'r');
end
if (opts1(choice1)=="New T")
T(ipoint)= input('enter new temperture: ');
P(ipoint)= P(ipoint-1)/((T(ipoint-1)/T(ipoint))^(ratio/(ratio-1)));
V(ipoint)= V(ipoint-1)*((P(ipoint-1)/P(ipoint))^(1/ratio));
W= n*((i/2)*8.314)*(T(ipoint)-T(ipoint-1));
fprintf('Work= %g \n',W);
Vplot=linspace(V(ipoint-1),V(ipoint),1000);
Pplot=P(ipoint-1)./((Vplot./V(ipoint-1)).^ratio);
plot(Vplot,Pplot,'-');
plot(V(ipoint),P(ipoint),'.');
textString = sprintf('(%.2f;%.2f)', V(ipoint), P(ipoint));
text(V(ipoint), P(ipoint)+0.1, textString, 'FontSize', 10, 'Color', 'r');
end
end
if (opts(choice)=="quit")
break;
end
end
hold off;

You might also like