Newton Raphson on Mathlab

조회 수: 16 (최근 30일)
Sunny 2014년 11월 3일
답변: Meysam Mahooti 2019년 12월 5일
I was wondering how to solve this equation in matlab? the abc would be replaced by 742. Any help would be deeply appreciated.

답변 (7개)

Torsten 2014년 11월 3일
p=[0.5 1 -10 14.742];
Best wishes
  댓글 수: 2
Sunny 2014년 11월 5일
Yes I have the root now to solve the equation, the root is -6 how do I now plug this into the equation and solve it?
Matt Tearle
Matt Tearle 2014년 11월 5일
What do you mean? The roots in r already solve the equation. The real root near -6 is the first element of r:
>> fprintf('%10.6f\n',r(1))
You can use the polyval function to evaluate a polynomial at a given value of x. For example:
x = linspace(-8,6);
y = polyval(p,x);
grid on
If you evaluate at x = r(1) you'll see that it solves the equation (to within ~10^-13):

댓글을 달려면 로그인하십시오.

Matt Tearle
Matt Tearle 2014년 11월 5일
Torsten showed how to find the roots of a polynomial. More generally, to find the zeros of any function:
f = @(x) 0.5*x.^3 + x.^2 - 10*x + 14.742; % define the function
x0 = -4; % initial guess for the solution
xroot = fzero(f,x0) % solve
(If you're interested in the details, according to the doc, "the [fzero] algorithm, created by T. Dekker, uses a combination of bisection, secant, and inverse quadratic interpolation methods")
  댓글 수: 2
Sunny 2014년 11월 5일
So to complete this manually x0=-4?
Matt Tearle
Matt Tearle 2014년 11월 5일
편집: Matt Tearle 2014년 11월 5일
I don't understand what you mean by "complete this manually". The assignment problem says to solve the equation. One way is to do N-R by hand. The other is "repeat using MATLAB". So I guess the question is what "repeat" entails. Repeat the solving of the equation? Or repeat solving the equation with N-R?
We've shown two ways you can solve the equation in MATLAB: roots (for solving polynomial equations) and fzero (for solving general nonlinear equations), but neither of these use N-R.
If you want to implement Newton-Raphson in MATLAB then that's a bigger issue. That requires knowing the basics of MATLAB programming. Given that this is a homework problem, you'll need to show what you've attempted and ask for some specific pointers.

댓글을 달려면 로그인하십시오.

Sunny 2014년 11월 13일
I've done the newton raphson manually on paper and I done it on matlab, Can someone help me compare the two on similarities or the differences?

Torsten 2014년 11월 13일
As Matt already mentioned, neither MATLAB's "fzero" nor MATLAB's "roots" uses N-R.
So it's difficult to compare the two methods.
You should ask your supervisor what he/she means by
"Repeat using MATLAB and compare the two methods.".
Best wishes

Farhad Sedaghati
Farhad Sedaghati 2015년 8월 3일
The following link is the matlab code to perform Newton-Raphson's Method:

sabik EL YATIM
sabik EL YATIM 2019년 7월 27일
hello, Recently, a part of the Matlab code I found on the resolution system of nonlinear equations using the method of Newton-Raphson with the Jacobian matrix (I also left it in my comments). However, although he provides me with the basic code, I can not make it work, no matter how hard I try. I spent many hours trying to present function func, but to no avail, I often did not understand how I used it if you can help me
function [x,F, niter] = newtonsys(Ffun ,Jfun,x0 ,tol ,...
nmax, varargin )
% NEWTONSYS cherche un zéro d’un système non linéaire
% tente de trouver le vecteur ZERO, racine d’ un
% système non linéaire défini dans FFUN et dont
% la matrice jacobienne est définie dans la
% fonction JFUN. La racine est cherchée autour
% du vecteur X0.
% La variable F renvoie le résidu dans ZERO
% NITER renvoie le nombre d’ itérations nécessaires
% pour calculer ZERO. FFUN et JFUN sont des fonctions
% MATLAB définies dans des M- files.
niter = 0; err = tol + 1; x = x0;
while err >= tol & niter < nmax
J = feval(Jfun ,x , varargin {:});
F = feval(Ffun ,x , varargin {:});
delta = - J\F;
x = x + delta;
err = norm( delta );
niter = niter + 1;
F = norm( feval( Ffun,x, varargin {:}));
if (niter == nmax & err > tol)
fprintf ([Pas de convergence dans le nombre ,...
d’’ iterations imparti \n ]);
fprintf ([La valeur retournée a un résidu ,...
relatif de %e\n’],F);
fprintf ([La méthode a convergé à l’’ itération,...
%i avec un résidu %e\n’],niter,F);

Meysam Mahooti
Meysam Mahooti 2019년 12월 5일


Help CenterFile Exchange에서 Newton-Raphson Method에 대해 자세히 알아보기


Community Treasure Hunt

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

Start Hunting!

Translated by