Attempting to write a function using MatLab to find the root of the given polyno
ID: 3028501 • Letter: A
Question
Attempting to write a function using MatLab to find the root of the given polynomal, which is given in vector form at the bottom of the picture attached (x^4 -6x^2 + x + 5).
Functions [val, count] = NewtonMethod(poly, guess)
Thank you in advance for any insight.
Newtons method is a procedure for finding numerical approximations to zeros of functions. Numerical approximations are important because it is often impossible to find the zeros exactly For example f(z) z5 1 has one real root, but has no exact algebraic solution y f(x) (x, f(x,)) Root of fox) Law of Cosines f(zo)-0 0 a 1 f(zo) f (zo) Write a function, NewtonMethod, that has two inputs, a vector containing the coefficients of a polynomial, and a scalar value for an initial guess for the root. The function should have two inputs, val, the approximate root location, and count, the number of iterations required to return the result within an accuracy 10 -8 for example NewtonMethod( 1 0 -6 1 5, 2) should return root 2.093064357681244 count Basic Steps 1. Calculate a function value, fx1 at x guess 2. Calculate a function value fx2 at guess 0.001 (22)-f(21) 3. Calculate fprime at x guess using m 0.001 (guess) 4. Calculate a new guess newGuess gues 8 f (guess) 5. While newGuess guess 10A-8, repeat with guess replaced by newGuessExplanation / Answer
a=input('Enter the function in the form of variable x:','s');
x(1)=input('Enter Initial Guess:');
error=input('Enter allowed Error:');
f=inline(a)
dif=diff(sym(a));
d=inline(dif);
for i=1:100
x(i+1)=x(i)-((f(x(i))/d(x(i))));
err(i)=abs((x(i+1)-x(i))/x(i));
if err(i)<error
break
end
end
root=x(i)
you can directly write the polynomial here and the guess, i have made it more generalised for the error one.
if there is any doubt comment below.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.