function [k, lambda] = linwavNum( T,d ) %LINWAVNUM finds the wave number of a wave with given period, T based on %linear wave dispersion %Input: % d=h - [m] water depth (good to separate h from capital H if converting to other code language) % T - [s] wave period %Output: % k - [-] wave number % lambda - [m] wave length g=9.81; % Manual version how you do it by hand % -wave dispersion to get wave number: omega=2*pi.*1./T; lambda=10; %first guess of wavelength, 10m k0=2*pi./lambda; %initial wave no., k conv=1; %initial value of convergence criterion (i.e. not met) while conv>0.001 k=omega.^2./(g.*tanh(k0.*d)); conv=abs(k-k0); k0=k; %update initial guess of k lambda=2*pi./k; end end % How to do it with function: %f=@(lambda)g/2/pi*T^2*tanh(2*pi*h/lambda)-lambda; %lambda=fzero(f,50); %k=2*pi/lambda