From: Walter Roberson <>
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$>
References: <hf6s0i$bhl$> <hpl2a7$cka$> <hpl3jj$jm7$> <hpl4no$ode$> <hpl9do$sai$> <hplhhm$qpo$> <hpljpa$ecm$> <hplkne$fbu$>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: 1270766164 17740 (8 Apr 2010 22:36:04 GMT)
NNTP-Posting-Date: Thu, 8 Apr 2010 22:36:04 +0000 (UTC)
User-Agent: Thunderbird (X11/20100317)
In-Reply-To: <hplkne$fbu$>
Xref: 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)