Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Matlab Problem!!!
Date: Wed, 3 Dec 2008 06:40:19 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 43
Message-ID: <gh59kj$hrr$1@fred.mathworks.com>
References: <6200318.1228278241565.JavaMail.jakarta@nitrogen.mathforum.org>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1228286419 18299 172.30.248.37 (3 Dec 2008 06:40:19 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 3 Dec 2008 06:40:19 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:504594


Matt <mcushi2@gmail.com> wrote in message <6200318.1228278241565.JavaMail.jakarta@nitrogen.mathforum.org>...
> I'm trying to run the program:
> 
> function [x,numIts]=newton(f,x)
> EPSILON = 1.0e-6;
> MAXITS  = 500;
> 
> for numIts=1:MAXITS
>   [y,yprime] = feval(f,x);
>   increment = y\yprime;
>   x = x - increment;
> 
>   if norm(increment)<EPSILON
>     break;
>   end
> end
> 
> But cannot seem to get it to run.  What commands do I need
> to enter to get this thing to run?!?!?!  Thank you for the
> help

Matt <mcushi2@gmail.com> wrote in message <23500797.1228280941124.JavaMail.jakarta@nitrogen.mathforum.org>...
> I've tried many things.  I already have it saved as newton.m file.  And I'm trying multiple things in the M-File Configuration Box.  I've tried:
> 
> x = 1;
> f = [@(x)x.^2, @(x)2*x];
> newton(f, 0.2);
> 
> f = 'x^2';
> newton(f, 0.2);
> 
> newton('x^2', 0.2);
> 
> And all of them give crazy errors :(
----------
  The "increment = y\yprime" line is wrong.  It should be a forward slash.  As it stands, you are dividing the derivative by the function value instead of visa versa.

  Also, if x is intended to be a scalar quantity, and therefore 'increment' also a scalar, why do you say "norm(increment)" instead of just plain "abs(increment)"?  It will still give the correct answer but is misleading to anyone who reads the code.

  As to the three attempts to call 'newton' in your second article, the second two tries are bound to fail since they don't return the desired derivative.  'feval' is certainly not smart enough to furnish a derivative of its own accord.  Also what was the point in writing "x = 1;" there?

Roger Stafford