Question

In: Computer Science

Using MATLAB, Consider the polynomial f(x) = 3x^3 + 5x^2 − 58x − 40. Find the...

Using MATLAB, Consider the polynomial f(x) = 3x^3 + 5x^2 − 58x − 40. Find the three roots of the polynomial, i.e, x where f(x) = 0, using: (i) Bisection method, and (ii) Newton’s method. Report the number of iterations taken by each algorithm using a tolerance of 10^−8 .

Solutions

Expert Solution

main_script.m

clc;clear;close all;
f = @(x) 3*x^3 + 5*x^2 - 58*x - 40; %function
df = @(x) 9*x^2 + 10*x - 58; %derivative
eps = 1e-8;
max_iter=100;
hold on;
fplot(f,[-10,10]); %graph to guess roots
fplot(@(x) 0, [-10,10]); %x axis
[root1, iter1] = newton(f,df,-6,eps,max_iter); %first root
[root2, iter2] = newton(f,df,0,eps,max_iter); %second root
[root3, iter3] = newton(f,df,6,eps,max_iter); %third root

fprintf("Newton Method\n");
fprintf("Root: %f, Iterations:%d\n",root1,iter1);
fprintf("Root: %f, Iterations:%d\n",root2,iter2);
fprintf("Root: %f, Iterations:%d\n",root3,iter3);


[root1, iter1] = bisection(f,-6,-3,eps,max_iter); %first root
[root2, iter2] = bisection(f,-3,1,eps,max_iter); %second root
[root3, iter3] = bisection(f,3,10,eps,max_iter); %third root

fprintf("Bisection Method\n");
fprintf("Root: %f, Iterations:%d\n",root1,iter1);
fprintf("Root: %f, Iterations:%d\n",root2,iter2);
fprintf("Root: %f, Iterations:%d\n",root3,iter3);

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

newton.m

function [ root, iter ] = newton( f, df, x0, epsilon, max_iter )
%function, derivative,initial guess, epsilonerance, max iteration
x(1) = x0 - (f(x0)/df(x0));
error(1) = abs(x(1)-x0);
k = 2;
while (error(k-1) >= epsilon) && (k <= max_iter) %while we have a reasonable root
x(k) = x(k-1) - (f(x(k-1))/df(x(k-1))); %formula
error(k) = abs(x(k)-x(k-1)); %error
k = k+1;
end
root = x(length(x));
iter=k-2;
end

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

bisection.m

function [p,iter] = bisection(f,a,b, eps, max_iter)

prev=1000;
p = (a + b)/2;
err = 100;
iter=1;
while err >= eps && iter<max_iter
if f(a)*f(p)<0
b = p;
else
a = p;
end
prev=p;
p = (a + b)/2;
err = abs((prev-p));
%fprintf("%d Error:%.4f\n",iter,err);
iter = iter+1;
end

%fprintf("%d Error:%f\n",iter,err);
end


Related Solutions

Consider the polynomial f(x) = 3x 3 + 5x 2 − 58x − 40. Using MATLAB....
Consider the polynomial f(x) = 3x 3 + 5x 2 − 58x − 40. Using MATLAB. Find the three roots of the polynomial, i.e, x where f(x) = 0, using Newton’s method. Report the number of iterations taken by each algorithm using a tolerance of 10−8 .
Consider f(x) = 2 + 3x^2 − x^3
Consider f(x) = 2 + 3x2 − x3 a) Find local max and min values b) Find intervals of concavity and infection points
. Let f(x) = 3x^2 + 5x. Using the limit definition of derivative prove that f...
. Let f(x) = 3x^2 + 5x. Using the limit definition of derivative prove that f '(x) = 6x + 5 Then, Find the tangent line of f(x) at x = 3 Finally, Find the average rate of change between x = −1 and x = 2
Consider the following real 3rd order polynomial f (x)= x^3− 5.5 x^2− 5x+ 37.5 A) Use...
Consider the following real 3rd order polynomial f (x)= x^3− 5.5 x^2− 5x+ 37.5 A) Use the bisection method to determine one of the roots, employing initial guesses of xl = - 10, xu = -1, and a stopping criterion εs=12% . B) Use the false position method to determine a root, employing initial guesses of xl = - 1, xu = 4, and a stopping criterion εs=3%. Was this method the best for these initial guesses? C) Use the...
Question1: Find the interval of increase and decrease of given function f(x)=3x^5-5x^3 f(x)=1/3 x^3-9x+2
Question1: Find the interval of increase and decrease of given function f(x)=3x^5-5x^3 f(x)=1/3 x^3-9x+2
consider the function f(x)=3x-5/sqrt x^2+1. given f'(x)=5x+3/(x^2+1)^3/2 and f''(x)=-10x^2-9x+5/(x^2+1)^5/2 a) find the local maximum and minimum...
consider the function f(x)=3x-5/sqrt x^2+1. given f'(x)=5x+3/(x^2+1)^3/2 and f''(x)=-10x^2-9x+5/(x^2+1)^5/2 a) find the local maximum and minimum values. Justify your answer using the first or second derivative test . round your answers to the nearest tenth as needed. b)find the intervals of concavity and any inflection points of f. Round to the nearest tenth as needed. c)graph f(x) and label each important part (domain, x- and y- intercepts, VA/HA, CN, Increasing/decreasing, local min/max values, intervals of concavity/ inflection points of f?
if f(x) = -5x^2 sin(5x) and g(x) = x^2 -3x +9 are defined over the interval...
if f(x) = -5x^2 sin(5x) and g(x) = x^2 -3x +9 are defined over the interval (2,4) write the full MATLAB commands to plot the two functions above two functions on the same set of axes 2 find the x and y coordinate of all points of intersections (x,y) that you can clearly see between the two graphs. Round up to 4 decimal
if f(x)=5x(x+4)^3 , find f'(x) and f"(x)
if f(x)=5x(x+4)^3 , find f'(x) and f"(x)
How do you find the domain of: f(g)= 5x^2+4 f(g)= 3x; -2<x<6 f(g)= (1) / 3x-6...
How do you find the domain of: f(g)= 5x^2+4 f(g)= 3x; -2<x<6 f(g)= (1) / 3x-6 f(g)= (x+2) / x^2-1 f(g)= x^4 / x^2+x-6 f(g)= sqrt (x+1) f(g)= sqrt (x^2+9)
Using Matlab, consider the function f(x) = x^3 – 2x + 4 on the interval [-2,...
Using Matlab, consider the function f(x) = x^3 – 2x + 4 on the interval [-2, 2] with h = 0.25. Write the MATLAB function file to find the first derivatives in the entire interval by all three methods i.e., forward, backward, and centered finite difference approximations. Could you please add the copiable Matlab code and the associated screenshots? Thank you!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT