- #1
rewmck
- 3
- 0
Homework Statement
I am trying to speed up a function in MATLAB that solves the equation by simple iteration:
λ= [itex]\frac{gT^{2}\frac{\text{tanh}(2\pi h)}{λ}}{2\pi}[/itex]
Where λ is wavelength, h is wave height, T is period and g=9.81.
Also here where it's a bit easier to read.
Homework Equations
The Attempt at a Solution
Currently I'm using simple iteration so I'm guessing lambda then putting the equation in a while loop where the new value of lambda is given by putting the old value in the above equation. The while terminates when the values of lambda converge.
This is one of the slowest parts of my code and thousands of iterations are done when I run my code.
Does anyone know of a method which converges faster or would be computationally faster? I tried the Newton Raphson method and rearranged the equation by making one side zero to get f(x) and differentiated for f(x). This converges quicker but often gives the wrong answer.
Thanks
Last edited: