%FINDING Z xvec=0.1:0.1:5.0; jmax=10; jvec=0:1:jmax; [xmat,jmat]=meshgrid(xvec,jvec); summandvec=(2.*jmat+1).*exp(-jmat.*(jmat+1).*xmat); Z=sum(summandvec); Zapp=1./xvec; DZ=abs(Zapp-Z)./Z; %difference in Zapproximate and Z"exact" %Plotting things: subplot(3,2,1); plot(xvec,Z,xvec,Zapp,'x'); title('Z "exact" and Z approx'); a=legend('Z "exact"','Z approx'); xlabel('X'); ylabel('Z'); subplot(3,2,2); plot(xvec,DZ); xlabel('X'); ylabel('D'); title('Difference (D) in Zexact and Zapp'); %FINDING U xvec1=0.1:0.1:4.9; U=0.-diff(reallog(Z)); Uapp=0.-diff(reallog(Zapp)); DU=abs(Uapp-U)./U; %difference in Uapproximate and U"exact" %Plotting things: subplot(3,2,3); plot(xvec1,U,xvec1,Uapp,'x'); title('U "exact" and U approx'); b=legend('U "exact','U approx'); xlabel('X'); ylabel('U'); subplot(3,2,4); plot(xvec1,DU); xlabel('X'); ylabel('D'); title('Difference (D) in Uexact and Uapp'); %FINDING Cv xvec2=0.1:0.1:4.8; C=diff(1./xvec1).*diff(U); %My attempt to take dU/dT. I'm not sure this is correct, because the graphs are very different. Capp=1; DC=abs(Capp-C)./C; %Plotting things: subplot(3,2,5); plot(xvec2,C,xvec2,Capp,'x'); title('Cv "exact" and Cv approx'); h=legend('Cv "exact"', 'Cv approx'); xlabel('X'); ylabel('Cv'); subplot(3,2,6); plot(xvec2,DC); xlabel('X'); ylabel('D'); title('Difference (D) in Cv,exact and Cv,app');