1. Determine the largest root in the interval [2,5 of (a) by using MATLAB to plo
ID: 3168193 • Letter: 1
Question
1. Determine the largest root in the interval [2,5 of (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 maximu re error of the estimate of the root, as well as the absolute value of the approximate percent relative error (e) How many iterations would be recquired in part (b) to ensure that the trueerror is less than 10-152 (d) Verify your anser in (c) using MATLABExplanation / Answer
f = @(x) (exp(-x^2) + sin(x));
fplot(f,[-10,10])
xlabel('x');
legend('f(x)')
Output plot:
b)
Actual answer is
root = 3.14164435997474, a = 3, b = 3.4
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
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.