% 13.00 pset 6
g=9.8;
lambda=[0:.01:5];
k=2*pi./lambda;
h=1.2
cp1 =sqrt(g*lambda/(2*pi))
cg1=0.5*cp1;
cp2=sqrt(g./k.*tanh(k*h));
cg2=sqrt(g).*((tanh(k*h)+k.*h./(cosh(k*h).^2))./(2*sqrt(k.*tanh(k*h))));

figure(1);
clf;
plot(lambda, cp1);
hold on
plot(lambda, cg1, 'b--');
plot(lambda, cp2, 'r');
plot(lambda, cg2, 'r--');
grid on;
zoom on;
title('velocity vs. wavelength for inf. water depth and for h=1.2 meters');
xlabel('wavelength (m)');
ylabel('velocity (m/s)');

clear lambda k
lambda=[0:.1:200];
k=2*pi./lambda;

cp1 =sqrt(g*lambda/(2*pi))
cg1=0.5*cp1;
cp2=sqrt(g./k.*tanh(k*h));
cg2=sqrt(g).*((tanh(k*h)+k.*h./(cosh(k*h).^2))./(2*sqrt(k.*tanh(k*h))));

figure(2);
clf;
plot(lambda, cp1);
hold on
plot(lambda, cg1, 'b--');
plot(lambda, cp2, 'r');
plot(lambda, cg2, 'r--');
grid on;
zoom on;
title('velocity vs. wavelength for inf. water depth and for h=1.2 meters');
xlabel('wavelength (m)');
ylabel('velocity (m/s)');
