We can use the Newton-Raphson method to find the square root of 5. The idea is to find a function that has a root at the square root of 5 and apply the NR method to that function.
We can use the function f(x) = x^2 - 5, which has roots at +/-sqrt(5). We will use the positive root. Also, the derivative of f(x) is f'(x) = 2x, so we can use this in the NR formula.
The NR method is given by the following recursion:
main.m31 chars2 lines
We start by guessing a value for the root, say x_0 = 2. Then we apply the NR method until the absolute error is small enough.
Here's the Matlab code:
main.m369 chars13 lines
This should output:
main.m55 chars3 lines
which shows that the function is very close to zero at x=sqrt(5). Therefore, the value of 2.23606797749441 is the square root of 5.
gistlibby LogSnag