MATLAB Answers

Newton Raphson method

52 views (last 30 days)
Durgga Rajendren
Durgga Rajendren on 19 Apr 2011
Answered: Meysam Mahooti on 5 Dec 2019
Given f(x) = x^3-8*x^2-200*x+1000
Locate the maximum of f(x) for x[-10,10]. The maximum must be located by finding the root of derivative of f(x).Use Newton Raphson method to perform root finding.
The question asks us to select the initial guess buy ourself after looking at the f(x) graphically. The solution must have a precision of 0.01%. Then, plot of f'(x) and the root must b done on the same figure.
I have the function for Newton Raphson method,but I think I'm missing an importance sentence because I can't get the iterations printed on the command window. Plus,I do not know how to plot the f'(x) and the root. I googled for hours but nothing helped.
Here is my function:
function root = newraph(f,df,xi,precision)
% comments on input and output
%Calculate f(xi) and f'(xi)
fxi=f(xi);
dfxi=df(xi);
%Iteration for Newton Raphson method begins
while abs(fxi)>precision
%Calculate the new estimated root,x_i_+_1
xi=xi-fxi/dfxi;
fxi=f(xi); %recalculate f(x_i_+_1)
dfxi =df(xi); %recalculate f'(x_i_+_1)
end
%The final xr value is the root
root = xi;
I hope someone can help me fix the mistakes. Any help is much appreciated. Thanks :)

  0 Comments

Sign in to comment.

Answers (2)

Matt Tearle
Matt Tearle on 19 Apr 2011
  1. Please format your code to make it more readable
  2. Why do you want to display the iterations? But either way, just add a disp or fprintf statement in your loop, after updating xi. (Or even just leave off the semicolon.)
  3. To plot the functions, make a vector of x values in [-10,10] (try linspace), then evaluate the functions at these x values. If f is a function handle, you can simply evaluate f(x).

  0 Comments

Sign in to comment.



Translated by