In: Computer Science
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 .
Root of Polynomial - Newton's Method:
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
Screenshot:
Note: If you have any related doubts, queries, feel free to ask by commenting down below.
And if my answer suffice your requirements, then kindly upvote.
Happy Learning