close all
clear all

P1 = 20;  %psi


dV = 1;  %Change in Volume
V2 = 1:.11:10;  %final volume (L)


V1 = V2+dV;

V1 = V1/1000;  %Convert to m^3
V2 = V2/1000;  %Convert to m^3
P1 = 4.45*P1/(0.0254^2);  %Convert to Pa

W = -P1*V1.*log(V2./V1);  %Joules



for i = 1:length(V2)
    V = V1(i):(V2(i)-V1(i))/100:V2(i);
    I = P1*(V1(i)./V).^(7/5);
    Wiso(i) = -trapz(V,I);
end

plot(1000*V2/dV,W,1000*V2/dV,Wiso)
xlabel('Final Volume (L)');
ylabel('Energy (J)');
legend('Adiabatic','Isothermal');