function hw3solutions
clc
clear all
time=0:10;
temps=[72.5 78.1 86.4 92.3 110.6 111.5 109.3 110.2 110.5 109.9 110.2];
plot(time,temps,'o')
xlabel('Time (s)')
ylabel('Temperature (F)')
timegoal=1.7;
y=interp1(time,temps,timegoal,'linear');
fprintf('Temperature at %f seconds is %f F\n',timegoal,y)
y=interp1(time,temps,timegoal,'spline');
fprintf('Temperature at %f seconds is %f F (spline) \n',timegoal,y)
disp('Press any key to continue')
pause 

guess=3.5;
goal=100;
f=@(x) interp1(time, temps, x, 'spline')-goal
timeto100=fzero(f,guess);
fprintf('The time to reach %f F is %f seconds\n',goal, timeto100)
disp('Press any key to continue')
pause 

eps=8.85e-12;
z=0.05;
R=0.06;
sig=300e-6;
field=sig*z/4/eps*quadl(@(r) 2*r./(z.^2+r.^2).^(3/2),0,R);
fprintf('The electric field at %f cm is %e\n',z*100, field)
disp('press any key to continue')
pause

Ts=-15; Ti=20;
T=0; alpha=1.38e-7;
t=60*24*3600;
f=@(x) (T-Ts)/(Ti-Ts)-erf(x/2/sqrt(alpha*t));
fplot(f,[0 2])
depth=fzero(f,1);
fprintf('The depth to bury the pipe is %f meters\n', depth)

