Description
The Newton Raphson Method is one of the most used methods in mathematics.
I prepare a python code for The Newton Raphson Method.
I used symbolic mathematics in this code, so you can use it for any type of function.
Inputs :
- your function
- The number of decimal places
- the initial approximation
Outputs :
The Root
Example :
f = x*exp(x)-1
n = 10
x0 = 10.3
Result :
iteration = 0 error = 0.911501448398656 function at x0 =306244.974184782
iteration = 1 error = 0.903731643602095 function at x0 =112192.903364359
iteration = 2 error = 0.894546001894334 function at x0 =41069.2516896753
iteration = 3 error = 0.883529727542698 function at x0 =15018.1540472486
iteration = 4 error = 0.870083972492604 function at x0 =5484.13447884616
iteration = 5 error = 0.853301689235578 function at x0 =1998.70885455641
iteration = 6 error = 0.831723221401884 function at x0 =726.343565789518
iteration = 7 error = 0.802829609623967 function at x0 =262.768502243287
iteration = 8 error = 0.761971255345233 function at x0 =94.3296256600454
iteration = 9 error = 0.700215386095365 function at x0 =33.3704039045572
iteration = 10 error = 0.601051402681061 function at x0 =11.4450669206618
iteration = 11 error = 0.441478859484758 function at x0 =3.64910058924058
iteration = 12 error = 0.224542300854449 function at x0 =0.963002900523559
iteration = 13 error = 0.0501863680079808 function at x0 =0.151010648177569
iteration = 14 error = 0.00215999392011301 function at x0 =0.00598973225899946
iteration = 15 error = 3.82899743234244e-6 function at x0 =1.05804395014175e-5
The Root is =0.567143290400000
No. of Iterations is =16
Reviews
There are no reviews yet.