Lab 6
Lab 6
method
Objectives:
Use python
Perform 5 iterations.
x=Symbol('x')
f=lambdify(x , g )
c=(a*f(b)-b*f(a))/(f(b)-f(a))
if((f(a)*f(c)<0)):
b=c
else :
a=c
output:
Enter the function x**3-2*x-5
Enter a valus :2
Enter b valus :3
Enter number of iterations :5
itration 1 the root 2.059 function value -0.391
x=Symbol('x')
f=lambdify(x , g)
x=a ;
c=b ;
i=0
x=c
b=c
else :
a=c
i=i+1
print ('itration %d \t the root %0.3f \t function value %0.3f \n'%(i ,c , f ( c ))) ;
Find a root of the equation 3x = cos x+ 1, near 1, by Newton Raphson method. Perform 5 iterations
x=Symbol('x')
f=lambdify(x , g)
dg=diff( g ) ;
df=lambdify(x , dg)
x0 = x1
output:
Enter the function3*x-cos(x)-1
Enter the intial approximation1
Enter the number of iterations5
itration 1 the root 0.620 function value 0.046