You are on page 1of 7

NUMERICAL AND STATISTICAL METHOD

ASSIGNMENT 1

NAME:- Tejas Dashrath Kalvankar


CLASS:- SE MECH A
ROLL NO:- 62 PRN NO:- 72164110F

ANALYTICAL SOLUTION:-
FLOWCHART:-
PROGRAM:-

def f(x):
return x**3-x**2-x-62

a=float(input("first approximation: "))


b=float(input("second approximation: "))
n=int(input("no of iterations: "))

if f(a)*f(b)>0:
print("invalid approximation.")
print("Try another values.")
elif f(a)>0:
temp = a
a=b
b=temp
for i in range(n):
x=(a+b)/2
if f(x)<0:
a=x
else:
b=x
print("iteration",i+1,"x=",x,"f(x)=",f(x))

print("required root is:",x)


else:
for i in range(n):
x = (a+b)/2
if f(x)<0:
a=x
else:
b=x
print("iteration",i+1,"x=",x,"f(x)=",f(x))

print("required root is:",x)

RESULT:-

You might also like