Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Determine the largest root in the interval [2, 5 of f(x) = e-r2 + sin x (a) b

ID: 3873046 • Letter: 1

Question

1. Determine the largest root in the interval [2, 5 of f(x) = e-r2 + sin x (a) by using MATLAB to plot y = f(x) over the given interval. As part of your answer include a printout of the graph. (b) using the Bisection method (by hand) and four iterations on the interval 3,3.4]. At each iteration give the maximum true error of the estimate of the root, as well as the absolute value of the approximate percent relative error (c) How many iterations would be required in part (b) to ensure that the true error is less than 10-15? (d) Verify your anser in (c) using MATLAB

Explanation / Answer

a) Matlab code to plot the function

f = @(x) (exp(-x^2) + sin(x));
fplot(f,[-10,10])
xlabel('x');
legend('f(x)')

Output plot:

b)

Actual answer is

So,

iter = 1


c = (a+b)/2 = 3.200000000000000


error = mod(c - ans) = 0.058355640025260


percentage_error = mod(c - ans)*100 = 5.835564002526006


iter = 2


c =3.100000000000000


error = 0.041644359974740


percentage_error = 4.164435997474003


iter =3


c = 3.150000000000000


error =0.008355640025260


percentage_error =0.835564002526024


In iter = 4


c = 3.125000000000000


error = 0.016644359974740


percentage_error = 1.664435997474012


root = 3.125000000000000

c) It will take arount 50 iterations

d)

format long;
f = @(x) (exp(-x^2) + sin(x));
a = 0;
b = 4;
c = a;
EPSILON = 10^(-15);
iter = 1;
while ((b-a) >= EPSILON)
c = (a+b)/2;
if ((f(c)) == 0.0)
break;
elseif ((f(c))*(f(a)) < 0)
b = (a+b)/2;
else
a = (a+b)/2;
end
iter = iter + 1;
end
root=c

Sample Output:

root =

3.141644359974742