0% found this document useful (0 votes)
2 views

MATLAB Assignment 3 (1)

The document describes three applications of the Bisection Method to find roots of different non-linear equations. The first equation is f(x)=x^3-x-1 with a root approximately at 1.324707, the second is f(x)=x^3-x^2+2 with a root approximately at -1.000977, and the third is f(x)=cos(x)-x*exp(x) with a root approximately at 0.517757. Each application includes user inputs for guesses and tolerable error, and the method checks if the guesses bracket the root.

Uploaded by

Avipsa Basu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

MATLAB Assignment 3 (1)

The document describes three applications of the Bisection Method to find roots of different non-linear equations. The first equation is f(x)=x^3-x-1 with a root approximately at 1.324707, the second is f(x)=x^3-x^2+2 with a root approximately at -1.000977, and the third is f(x)=cos(x)-x*exp(x) with a root approximately at 0.517757. Each application includes user inputs for guesses and tolerable error, and the method checks if the guesses bracket the root.

Uploaded by

Avipsa Basu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1)Find the root of f(x)=x^3-x-1 by using Bisection Method in the interview

[1,2] with a tolerance of 0.001


clc
syms x;
y= input('enter non linear equations:');
a=input('enter first guess');
b=input('enter second guess');
e=input('tollerable error');
fa=eval(subs(y,a));
fb=eval(subs(y,b));
if fa*fb<0
disp('given values do nt bracket the root');
else
c=(a+b)/2
fc=feval(subs(y,c))
while abs(fc)>e
if fa*fc <0
b=c;
fb=fc;
else
a=c;
fa=fc;
end
c=(a+b)/2;
fc=eval(subs(y,c));
end
fprintf('the root is approximately: %4f\n',c);
end

OUTPUT
enter non linear equations:x^3-x-1
enter first guess1
enter second guess2
tollerable error0.0001

c=

1.5000

fc =

0.8750

the root is approximately: 1.324707

2)Find the root of f(x)=x^3-x^2+2 by using Bisection Method in the


interview [-10,+10] with a tolerance of 0.01

clc
syms x;
y= @(x) x^3-x^2-1;
a=input('enter first guess');
b=input('enter second guess');
e=input('tollerable error');
fa=y(a);
fb=y(b);
if fa*fb>0
disp('given values do not bracket the root');
else
c=(a+b)/2
fc=y(c);
while abs(fc)>e
if fa*fc <0
b=c;
fb=fc;
else
a=c;
fa=fc;
end
c=(a+b)/2;
fc=y(c);
end
fprintf('the root is approximately: %4f\n',c);
End

OUTPUT
enter first guess-10
enter second guess10
tollerable error0.01

c =

fc =

the root is approximately: -1.000977

3)Find the root of f(x)=cos(x)-x*exp(x) by using Bisection Method in the


interval [0,1] with a tolerance of 0.00001

clc
syms x;
y= @(x) cos(x)-x*exp(x);
a=input('enter first guess');
b=input('enter second guess');
e=input('tollerable error');
fa=y(a);
fb=y(b);
if fa*fb>0
disp('given values do not bracket the root');
else
c=(a+b)/2
fc=y(c)
while abs(fc)>e
if fa*fc <0
b=c;
fb=fc;
else
a=c;
fa=fc;
end
c=(a+b)/2;
fc=y(c);
end
fprintf('the root is approximately: %4f\n',c);
end

OUTPUT

enter first guess0


enter second guess1
tollerable error0.00001

c =

0.5000

fc =

0.0532

the root is approximately: 0.517757

You might also like