Help with Newton Raphson question.

6 次查看(过去 30 天)
My function is: f(x) = (x + 5.371)^2*(x-100) My initial guess is x0 = 0 I have to use the Newton Raphson method and 1st modified Newton Raphson method to find the root at x = -5.371 for the function. I am also asked to report the number of iterations required to reach 6 sig. figs of accuracy.
I would like to know if my code is good for the Newton Raphson method and also for the modified Newton Raphson method, what is the (m = multipiclity of root) value that I must use? I have no code for it as I am confused as to what the value of m that I must use is. Is it the 2 (aka the power for the first parenthesis) in f(x) = (x + 5.371)^2*(x-100)?
This is the modified Newton-Raphson method that I must use
Here is the code for the Newton Raphson method:
clear all; close all; clc;
SF = 6; %number of desired sig figs
z = 0; %initial value x0
i = 1; % declare (i) value first because we don't know how many (i)'s it will take to get to our desired value of iterations given the number of sig figs (which is 43)
f = @(x) ((x+5.371)^2)*(x-100); %function f(x)
df = @(x) (3*x^2)-(178.516*x)-1045.352359; %derivative of function f(x)
h = @(x) x - f(x)/df(x); %newton raphson formula
while (1)
z(i+1) = h(z(i)); %with this program, you can find out the number of iterations it takes to get to a certain amount of sig figs. This line prints out a value of z based on i and i+1
error = abs((z(i+1)-z(i))/z(i)); %you print out a bunch of numbers with your function starting with i = 1, and you use the previous value and the current value in your absolute error equation
if error < 0.5*10^-SF;
break
end
i = i + 1; %iteration counter (if your (if error < 0.5*10^-SF;) fails the condition, then it goes straight to this line and goes back to the line right after the while loop with the new (i) value
end
disp (i)

采纳的回答

Aveek Podder
Aveek Podder 2017-10-17
Your code for Newton-Raphson Method seems good and it should work perfectly.
For Modified Newton method the value of m you should use here is 2 for roots at -5.371, its the algebraic multiplicity of the root.

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by