Troubles with a loop to calculate wavelength

Hi! I want to obtain the wavelength of a water wave, this is achieved iterating the following formula:
L=(g*Tp.^2)./(2*pi).*tanh(h./L);
the problem is that i have to try with several wave periods (Tp), every time i have tried to make a loop to make it work, different mistakes have appeared:
Below are the options that i have tried
Tp is a vector with a length of 87664* all of them are positive
Option A)
g = 9.81;% (m/s^2)
for i=Tp
c = g*i.^2/(2*pi());
hp = 6.6; %depth (m)
vi=100;
Tanhip = @(LdO)tanh(2*pi()*hp./LdO);
fLdO = @(LdO)LdO-c*Tanhip(LdO);
LdO = fsolve(@(LdO)fLdO(LdO),vi)
end
LdO is only one value and I need the solution for every save period so i hope a vector of 87664 too
image.png
Option B)
for i=Tp
L0=(g*i.^2)/(2*pi);
guess=L0;
L=(g*i.^2)./(2*pi).*tanh(d./guess);
diff=abs(L-guess);
while diff>0.1
guess=L+(0.5*diff);
L=(g*i.^2)./(2*pi).*tanh(d./guess);
end
end
This option never ends, busy appears all the time and i have to close the program
Option C)
for i=Tp
L0 = (g*i.^2)/(2*pi());
syms L
assume(L>=0) % tomar soluciones positivas
sol = solve(L - L0*tanh(2*pi()*d/L)== 0,L,'Real',true); % Tomar soluciones reales
Ldo = double(sol); % default numeric data type for MATLAB
end
This last option showed this message:
"Warning: Cannot find explicit solution.
>In solve (line 316)"
I hope you can help me, in advance thank you

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 31 Oct 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!