MATLAB Assignment 3 (1)
MATLAB Assignment 3 (1)
OUTPUT
enter non linear equations:x^3-x-1
enter first guess1
enter second guess2
tollerable error0.0001
c=
1.5000
fc =
0.8750
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 =
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
c =
0.5000
fc =
0.0532