1. Use the bisection method with 0 and 1 as the first two guesses. 2. Use the fa
ID: 3880846 • Letter: 1
Question
1. Use the bisection method with 0 and 1 as the first two guesses.
2. Use the false-position method with 0 and 1 as the first two guesses.
3. Consider the results of Problems 1 and 2. For each method, plot (on the same graph), the approximate relative error (y-axis) versus the number of iterations (x-axis). Use a log scale for the y-axis and a linear scale for the x-axis. Do the approximate relative errors for each method decrease exponentially? Explain.
4. Explain why the false-position method tends to converge more rapidly than does the bisection method.
For Problems 1-2, you are to develop Matlab code to solve: f(x)-x-exp(-x) = 0 For each case, carry out the iterations until the magnitude of the approximate relative error is no more than 10-10 (10-8 %). Please submit a hard copy of the code (with explanatory comments embedded within) Use the bisection method with 0 and 1 as the first two guesses. 1. 2. 3. Use the false-position method with 0 and 1 as the first two guesses. Consider the results of Problems 1 and 2. For each method, plot (on the same graph), the approximate relative error (y-axis) versus the number of iterations (x-axis). Use a log scale for the y-axis and a linear scale for the x-axis. Do the approximate relative errors for each method decrease exponentially? Explain Explain why the false-position method tends to converge more rapidly than does the bisection method. 4.Explanation / Answer
Here si the code, do give me a thumb up if this helps!
function p = bisection(f,a,b)
if f(a)*f(b)>0
disp('Wrong choice')
else
p = (a + b)/2;
err = abs(f(p));
while err > 1e-7
if f(a)*f(p)<0
b = p;
else
a = p;
end
p = (a + b)/2;
err = abs(f(p));
end
end
f=@(x) x-exp(-x);
bisection(f,0,1);
False position :
x0= 0;
x1 = 1;
tolerance=0.00000001;
f =@(x) x-exp(-x);
for i=0:inf
x2= x1 - (f(x1)* (x1-x0)/(f(x1)-f(x0))) ;
c = f(x2);
absolute_c= abs(c);
if absolute_c < tolerance
break
end
if f(x0)*c <0
x1=x2;
continue
else
x0=x2;
continue
end
end
i
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.