function hw1solutions
clear all
%%
disp('Problem 1a')
radius=15 %cm
spherearea=4*pi*radius^2
cubeside=sqrt(spherearea/6)
disp('Press a key to continue')
pause
clc
%%
disp('Problem 1b')
spherevol=4/3*pi*radius^3 %cm^3
cubeside=spherevol^(1/3)
disp('Press a key to continue')
pause
clc
%%
disp('Problem 2')
e=@(M,Enot) Enot*10^(3/2*M)
Enot=10^4.4
ratio=e(6.9,Enot)/e(7.1,Enot)
disp('Press a key to continue')
pause
clc
%%
disp('Problem 3')
global n
out=powersin(pi/2)
fprintf('Series needed %i terms to converge\n',n) 
error=(abs(out-1))
disp('Press a key to continue')
pause
clc
%%
disp('Problem 4')
nbounce=8;
hnot=2; %meters
ht=bouncing(hnot, nbounce);
fprintf('The height is %f after %i bounces\n',ht,nbounce)
disp('Press a key to continue')
pause
clc
%%
disp('Problem 5')
n=1;
R=0.08206;
a=1.39;
b=0.0391;
T=300;
vol=0.08:0.0001:6;
preal=n*R*T./vol;
pvanderwaals=n*R*T./(vol -n*b)-n^2*a./vol.^2;
semilogx(vol,preal,vol,pvanderwaals,'r')
xlabel('V (liters)')
legend('real', 'van der Waals')
ylabel('P (atm)')
%
function s=powersin(x)
global n
s=0;
t=x;
n=1;
while s+t~=s
  	s=s+t;
  	t=-x.^2/((n+1)*(n+2)).*t;
 	n=n+2;
end
%
function r=bouncing(hnot, n)
g=9.81;
h=hnot;
for i=1:n
   vhit=sqrt(2*g*h);
   vup=0.85*vhit;
   h=vup^2/2/g;
end
r=h;