Path: news.mathworks.com!newsfeed-00.mathworks.com!solaris.cc.vt.edu!news.vt.edu!elk.ncren.net!newsflash.concordia.ca!canopus.cc.umanitoba.ca!not-for-mail From: Walter Roberson <roberson@hushmail.com> Newsgroups: comp.soft-sys.matlab Subject: Re: Newton-Raphson Date: Thu, 08 Apr 2010 17:36:01 -0500 Organization: Canada Eat The Cookie Foundation Lines: 37 Message-ID: <hpllok$hac$1@canopus.cc.umanitoba.ca> References: <hf6s0i$bhl$1@fred.mathworks.com> <hpl2a7$cka$1@fred.mathworks.com> <hpl3jj$jm7$1@canopus.cc.umanitoba.ca> <hpl4no$ode$1@fred.mathworks.com> <hpl9do$sai$1@canopus.cc.umanitoba.ca> <hplhhm$qpo$1@fred.mathworks.com> <hpljpa$ecm$1@canopus.cc.umanitoba.ca> <hplkne$fbu$1@fred.mathworks.com> NNTP-Posting-Host: ibd-nat.ibd.nrc.ca Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: canopus.cc.umanitoba.ca 1270766164 17740 192.70.172.18 (8 Apr 2010 22:36:04 GMT) X-Complaints-To: abuse@cc.umanitoba.ca NNTP-Posting-Date: Thu, 8 Apr 2010 22:36:04 +0000 (UTC) User-Agent: Thunderbird 2.0.0.24 (X11/20100317) In-Reply-To: <hplkne$fbu$1@fred.mathworks.com> Xref: news.mathworks.com comp.soft-sys.matlab:624851 Muhamad wrote: > %func_prime.m > > function [value] = func_prime(x) > value = sin(A)-(sin(teta)*e^(-(180+A-teta)/WRC); > > x = 1; > > for j = 1:10 > x = x - func(x)/func_prime(x); > end When you have a function, the only values that are returned to the calling routine are the ones named before the '=' on the 'function' line. In this code, 'value' is the only variable named there. Once you have computed value, there is no point in doing any further work (unless it has to with graphics or outputs to a file or the display), because whatever you do will just be thrown away. Thus the 'for' loop is not contributing anything to this routine and can be discarded, just as the assignment to 'x' can be. When you have a function, the only values that you can use in the function are numeric constants, named constants such as pi, values you have already computed in the routine, and values that you have named after the '(' on the 'function' line. [I'm simplifying slightly; there are some more advanced facilities.] You name x in that position, but you do not use x. You do, though, attempt to use A, teta, and WRC, none of which fall into the categories I describe. Thus A, teta, and WRC are undefined as far as this routine is concerned. If you want to use the values that you input from the user, then you need to give names for them on the 'function' line, and you need to pass the values in when you call the routine. For example, you could call func_prime(A, WRC, teta) and your corresponding 'function' line would be function value = func_prime(A, WRC, teta)