Search code examples
matlabmathequationequation-solving

Solve a numeric equation


I would like to solve the following equation in MATLAB:

L=(9.81.*P.^2)./(2.*pi).*tanh(2.pi.(d./L))

The P and d are predefined vectors. L is the variable to be solved to.

I try to solve this problem with:

%First guess
L0 = 1.56 * P;
fsolve( @(L)  L - (9.81.*P.^2)./(2.*pi).*tanh(2.*pi.*(d./L), L0 )

The upper code doesn't work.


Solution

  • The problem is with your unbalanced statement - you are missing a ). Try this:

    L0 = 1.56 * P;
    your_function = @(L)  L - (9.81.*P.^2)./(2.*pi).*tanh(2.*pi.*(d./L))
    fsolve(your_function, L0)