0% found this document useful (0 votes)
33 views4 pages

Practical No. 10

This document describes 6 numerical analysis problems solved using the Newton-Raphson and false position root finding methods in Python. Each problem finds the root of an equation: 1) finds the root of f(x) = x^3 - 5x + 1, 2) finds the root of xlog10(x) = 12.34, 3) finds the approximate value of √5, 4-5) find the roots of functions in given intervals using false position, and 6) finds the approximate value of √5 to 10 decimal places using false position. Python code and output are provided for each problem.

Uploaded by

Tushar Dimble
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views4 pages

Practical No. 10

This document describes 6 numerical analysis problems solved using the Newton-Raphson and false position root finding methods in Python. Each problem finds the root of an equation: 1) finds the root of f(x) = x^3 - 5x + 1, 2) finds the root of xlog10(x) = 12.34, 3) finds the approximate value of √5, 4-5) find the roots of functions in given intervals using false position, and 6) finds the approximate value of √5 to 10 decimal places using false position. Python code and output are provided for each problem.

Uploaded by

Tushar Dimble
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

NAME : - Supriya Suresh Wadkar

STD. :- SY BSc CS (Computer Science)


PRACTICAL NO. 10
1. Using newton-Raphson method find root of equation
3
𝑓(𝑥) = 𝑥 − 5𝑥 + 1 with 𝑥0 = 0. 5 correct to three decimal
places(error e=0.00001).
Input :
import numpy as np
def func(x):
return ((x*x*x) - (5*x) + 1)
def derivfunc(x):
return ((3*x*x)-5)
def newtonRaphson(x):
h = func(x)/derivfunc(x)
while abs(h) >= 0.00001 :
h = func(x)/derivfunc (x)
x = x-h
print("The value of the root is : ", "%.3f"% x)
x0 = 0.5
newtonRaphson(x0)
Output :
The value of the root is : 0.202

2. Using newton-Raphson method find root of equation


𝑥𝑙𝑜𝑔10(𝑥) = 12. 34 with 𝑥0 = 10.

Input :
def func(x):
return (x*np.log(x)-12.34)
def derivfunc(x):
return (1 + np.log(x))
def newtonRaphson(x):
h = func(x)/derivfunc(x)
while abs(h) >= 1.17 :
h = func(x)/derivfunc (x)
x = x-h
print("The value of the root is : ", "%.4f"% x)
x0 = 10
newtonRaphson(x0)
Output :
The value of the root is : 6.5613
3. Using newton-Raphson method find approximate value of √5
correct to ten decimal places.
Input :
import numpy as np
def func(x):
return ((x*x)-5)
def derivfunc(x):
return (2*x)
def newtonRaphson(x):
h = func(x)/derivfunc(x)
while abs(h) >= 0.00001 :
h = func(x)/derivfunc (x)
x = x-h
print("The value of the root is : ", "%.10f"% x)
x0 = 2.2
newtonRaphson(x0)
Output :
The value of the root is : 2.2360679775

4. Using false-position method find approximate root of


𝑥
𝑓(𝑥) = 𝑥𝑒 − 𝑐𝑜𝑠⁡(𝑥) in interval (0, 1).
Input :
MAX_ITER = 1000000
import math
def func(x):
return (x*math.exp(x)-math.cos(x))
def regulaFalsi(a,b):
if func(a)*func(b) >= 0:
print("You have not assumed right a and b")
return - 1
c=a
for i in range(MAX_ITER):
c = (a*func(b) - b*func(a)) / (func(b) -
func(a))
if func(c) == 0:
break
elif func(c) * func(a) < 0:
b = c
else :
a = c
print("The value of root is : ", '%.4f'%c)

a = 0
b = 1
regulaFalsi(a,b)
Output :
The value of root is : 0.5178

5. Using false-position method find approximate root of


𝑓(𝑥) = tan 𝑡𝑎𝑛 (𝑥) − 2𝑥 in interval (1.1, 1.2).
Input :
MAX_ITER = 1000000
import math
def func(x):
return (math.tan(x)-2 * x)
def regulaFalsi(a,b):
if func(a)*func(b) >= 0:
print("You have not assumed right a and b")
return - 1
c=a
for i in range(MAX_ITER):
c = (a*func(b) - b*func(a)) / (func(b) -
func(a))
if func(c) == 0:
break
elif func(c) * func(a) < 0:
b = c
else :
a = c
print("The value of root is : ", '%.4f'%c)
a = 1.1
b = 1.2
regulaFalsi(a,b)
Output :
The value of root is : 1.1656
6. Using false-position method find approximate value of √5 correct to
ten decimal places.
Input :
MAX_ITER = 1000000
import math
def func(x):
return (x*x - 5)
def regulaFalsi(a,b):
if func(a)*func(b) >= 0:
print("You have not assumed right a and b")
return - 1
c=a
for i in range(MAX_ITER):
c = (a*func(b) - b*func(a)) / (func(b) -
func(a))
if func(c) == 0:
break
elif func(c) * func(a) < 0:
b = c
else :
a = c
print("The value of root is : ", '%.10f'%c)
a = 2.2
b = 2.3
regulaFalsi(a,b)
Output :
The value of root is : 2.2360679775

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy