Determine the first positive root of fx sinx cos1x2 1 whe
Determine the first positive root of f(x) = sin(x) + cos(1+x^2) - 1, where x is in radians. Graphically and using a built-in function. (MATLAB). Using the bisection method. Iterate until the estimated error (sigma a) falls below a level of sigma s = 1%.
Solution
a) Matlab code to plot the graph of given function is
x = -10:0.1:10;
for i = 1:size(x,2)
y(i) = sin(x(i)) + cos(1 + (x(i))^2) - 1;
end
plot(x,y)
xlabel(\'x\')
ylabel(\'y\')
So, from the graph, we can see that the function has a root in [2,5] interval
b)
So set a = 2, and b = 5
Matlab code for bisection methode
format long;
a = 2;
b = 5;
c = a;
EPSILON = 0.001;
iter = 1;
while ((b-a) >= EPSILON)
c = (a+b)/2;
if (sin(c) + cos(1 + (c)^2 ) - 1 == 0.0)
break;
elseif ((sin(c) + cos(1 + (c)^2 ) - 1)*(sin(a) + cos(1 + (a)^2 ) - 1) < 0)
b = (a+b)/2;
else
a = (a+b)/2;
end
a
b
iter = iter + 1;
end
root=c
Output:
Root = 2.532470703125000
