Solutions to the following problems should consist of progra
Solutions to the following problems should consist of program codes, computed results, and short write-ups. In the write-up, discuss the results you have obtained and explain them from the numerical point of view. Use SINGLE PRECISION ONLY. Insert COMMENTS in your programs.
As always provide a short description of the equations and a short discussion of obtained results (e.g., are the empirical error estimates close to the true errors?), with the source-code, and the printed computer results.
nSolution
Equation: F(x) = x*x - 9
We know, solution for above equatinon is x = 3;
Python code for Newton rapson methode:
import math
def func(x):
return x*x - 9;
def deriv(x):
return 2*x;
def nr(x):
h = float(func(x)) / float(deriv(x))
i = 1;
while(abs(h) >= 0.5*10**-9):
h = float(func(x)) / float(deriv(x))
print \"Iteration \", i, \"X= \", x, \"F(x) = \",float(func(x)), \"F\'(x)= \", float(deriv(x))
x = x - h
i=i+1
print \"Root\", x
nr(5)
Sample Output:
Iteration 1 X= 5 F(x) = 16.0 F\'(x)= 10.0
Iteration 2 X= 3.4 F(x) = 2.56 F\'(x)= 6.8
Iteration 3 X= 3.02352941176 F(x) = 0.141730103806 F\'(x)= 6.04705882353
Iteration 4 X= 3.00009155413 F(x) = 0.00054933317044 F\'(x)= 6.00018310826
Iteration 5 X= 3.0000000014 F(x) = 8.38190317154e-09 F\'(x)= 6.00000000279
Iteration 6 X= 3.0 F(x) = 0.0 F\'(x)= 6.0
Root 3.0
