Friday, 24 June 2022

Solving an equation by Iteration

Solving an equation by iteration


I am solving an equation by iteration. In this case, I am going to solve x2 - x - 5 = 0 by iteration. 
First of all, I am rearranging it in the iterative form:
Suppose you have to solve x2 - x - 5 = 0 by iteration.
Let's rearrange it in iterative form first.
x = √(x + 5)
xn+1 = √(xn + 5)
Let's take the initial value, x0 = 1 and iterate in the following programme:



Now, you can change the initial value and the number of iterations in the code and play with it.
Much to your surprise, you will notice that the solution or root is going to be the same regardless of the initial value!
This is the beauty of iteration.😂