You are on page 1of 2

Clc

Clear

Clc

Function f=f(x)

F=x^3-x-1

Endfunction

A=input(“Enter the first point of an interval:”)

B=input(“Enter the second point of an interval:”)

If f(a)*f(b)<0 then

Printf(“The roots lies in the interval (%f,%f).\n”,a,b)

N=input(“Enter the required number of iteration:”)

E=input(“Enter the required number of decimal places:”)

Printf(“n \t c \t f©\n”)

For i=1:n

C=(a+b)/2

If f(a)*f(c)<0

B=c

Else

A=c

End

C1=(a+b)/2

Printf(“%d %1.5f %1.5f\n”,I,c,f©)

If abs(c-c1)<=10^(-e-1)

Printf(“The approximate root correct upto %d decimal place \n of an equation occurs in %d


iteration and its \n value is %1.5f.\n.”,e,I,c)

Break
End

End

Else

Printf(“The root does not lie in the interval (%f,%f).\n”,a,b)

End

You might also like