J(x)=x 7x2+15x-9 (15) 2.2 Consider the function - a) Can you use the bisection m
ID: 3282144 • Letter: J
Question
J(x)=x 7x2+15x-9 (15) 2.2 Consider the function - a) Can you use the bisection method to find the root at x=1? How about the root at x=3? Explain! b) If you use the bisection method, how many steps would you need at most to find the root in the interval [0.3, 1.3] with tolerance 101°? Demonstrate this in MATLAB! c) Use the MATLAB fzero function to find the roots with starting intervals [O, 5), [2, 4] and [0, 2] Plot in the same figure: the function, the line y 0 and the roots in the interval [-1, 5]. Roots carn be visualized using the command scatter. Comment the results. d) In the textbook, page 161, thre is an implementation of Newton-Raphsons method in MATLAB. Use this function to solve f(x)-0 starting in x.-0.5 and set the tolerance to 0, while enforcing maximum number of iterations to 6. Make the method tell the value of the guess in each iteration with 10 digits precision. Compare fzero and newtraph. Make a table of iterations. Does fzero give results that converge quadratically? e) Find all roots of the function in a single command line using the command rootsExplanation / Answer
%Part a
f = @(x)(x.^3 - 7*x.^2 + 15*x - 9);
fprintf('It will calculate zeroes nearest to 1 ');
disp( fzero(f,1));
fprintf('it will calculate zeroes nearest to 3 ');
disp(fzero(f,3));
%Part b
z0 = 0.3;
z1 = 1.3;
tol = 10^(-10);
counter = 0;
if(f(z0)*f(z1)<0)
while(abs(z0 - z1)>tol)
counter = counter +1;
z3 = (z0 + z1)/2;
if(f(z0)*f(z3)<0)
z1 = z3;
else
z0 = z3;
end
end
end
fprintf('The no of steps required are %d ',counter);
%Part c
I1 = [0 5];
fprintf('zeros in the interval [0,5] is ');
disp(fzero(f,I1));
I2 = [2 4];
fprintf('zeros in the interval [2,4] is ');
%disp(fzero(f,I2)); %--->this wont work because root doesnot lie in this interval
fprintf('i.e, Roots does not lie in this interval ');
I3 = [0 2];
fprintf('zeros in the interval [0,2] is ');
disp(fzero(f,I3));
plot([-1,5],fzero(f,[-1 5]),'r');
hold on
x = linspace(-1,5,200);
y = x.^3 - 7*x.^2 + 15*x - 9 ;
scatter(x,y);
%Part e
p = [1 -7 15 -9];
fprintf('All roots of the fn are ');
disp(roots(p));
Please provide page 161 of the book for part d
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.