Path: news.mathworks.com!not-for-mail From: "Muhamad " <madz_doank@yahoo.com> Newsgroups: comp.soft-sys.matlab Subject: Re: Newton-Raphson Date: Thu, 8 Apr 2010 23:03:05 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 49 Message-ID: <hplnb9$mgb$1@fred.mathworks.com> 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> <hpllok$hac$1@canopus.cc.umanitoba.ca> Reply-To: "Muhamad " <madz_doank@yahoo.com> NNTP-Posting-Host: webapp-02-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1270767785 23051 172.30.248.37 (8 Apr 2010 23:03:05 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Thu, 8 Apr 2010 23:03:05 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 2305000 Xref: news.mathworks.com comp.soft-sys.matlab:624861 Walter Roberson <roberson@hushmail.com> wrote in message <hpllok$hac$1@canopus.cc.umanitoba.ca>... > 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) why but still error ? ------ ??? Input argument 'teta' is undefined. Error in ==> C:\Documents and Settings\madz\My Documents\Downloads\elda\func.m On line 4 ==> f = cos(A)-sin(teta)*e^(-(180+A-teta)/W*R); Error in ==> C:\Documents and Settings\madz\My Documents\Downloads\elda\Newton_Raphson.m On line 11 ==> while (iterations<30) & (abs(func(x))>tolerance) ----