initial guess in a loop

9 ビュー (過去 30 日間)
B
B 2015 年 5 月 6 日
コメント済み: B 2015 年 5 月 6 日
the initial guess in the following loop is actually inside the loop, why is that?
function [root,ea,iter]=newtraph(func,dfunc,xr,es,maxit,varargin)
if nargin<3,error('at least 3 input arguments required'),end
if nargin<4|isempty(es),es=0.0001;end
if nargin<5|isempty(maxit),maxit=50;end
iter = 0;
while (1)
xrold = xr;
xr = xr - func(xr)/dfunc(xr);
iter = iter + 1;
if xr ~= 0, ea = abs((xr - xrold)/xr) * 100; end
if ea <= es | iter >= maxit, break, end
end
root = xr;
=======================
thanks a lot
  1 件のコメント
B
B 2015 年 5 月 6 日
that is xrold = xr;

サインインしてコメントする。

回答 (1 件)

Mischa Kim
Mischa Kim 2015 年 5 月 6 日
編集済み: Mischa Kim 2015 年 5 月 6 日
B, the initial guess is provided through the newtraph call. In other words, in order to execute/call this function you need to provide an xr value. That is the initial value that is then updated in the loop.
  4 件のコメント
B
B 2015 年 5 月 6 日
Thanks a lot Stephen and Mischa. I got now :)

サインインしてコメントする。

カテゴリ

Find more on Loops and Conditional Statements in Help Center and File Exchange

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by