MATLAB problem. Please attach or write the code for this problem The bisection m
ID: 3695646 • Letter: M
Question
MATLAB problem. Please attach or write the code for this problem
The bisection method in mathematics is a squareroot-finding method that repeatedly bisects an interval and then selects a subinterval in which a squareroot must lie for further processing. It is also one of the most fundamental numerical methods. The basic algorithm of a bisection method is: Determine the initial interval where the squareroot lies Find the mid-point of the interval Evaluate if the squareroot should lies in the left subinterval or right subinterval The subinterval that the squareroots should be in becomes the interval for the next iteration Repeat Steps 1) through 4), until the size of the interval is small enough (usually it will be compared to a preset tolerance) Write a MATLAB program that uses the bisection method to find the squareroots of this function: f(x) = x^2 + 2.5x - 59 Initial evaluation of the function indicates that and (0,10), respectively. Specifications: You cannot solve the quadratic equation analytically. You may hardcode the intervals. The tolerance is set to be le-6. The numerical squareroot is the midpoint when the interval is narrower than the tolerance. Output the result with 4 decimal places. Name your script "Bisection_Lastname.m".Explanation / Answer
I have written the bisection method in matlab for the same.
The tolerance in the function is set to 1e-6 as stated in the problem.
working code:
function p = bisection_lastname(f,a,b)
if f(a)*f(b)>0
disp('Wrong values entered')
else
p = (a + b)/2;
err = abs(f(p));
while err > 1e-6
if f(a)*f(p)<0
b = p;
else
a = p;
end
p = (a + b)/2;
err = abs(f(p));
end
end
bisection_lastname(x^2+2.5x-59,0,10)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.