Path: news.mathworks.com!not-for-mail
From: "carlos lopez" <clv2clv_00000000_@adinet.com.uy>
Newsgroups: comp.soft-sys.matlab
Subject: Re: A few questions about using matlab
Date: Sun, 4 May 2008 16:29:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 43
Message-ID: <fvko8f$kam$1@fred.mathworks.com>
References: <fvk68r$mct$1@fred.mathworks.com>
Reply-To: "carlos lopez" <clv2clv_00000000_@adinet.com.uy>
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 1209918543 20822 172.30.248.37 (4 May 2008 16:29:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 4 May 2008 16:29:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 870136
Xref: news.mathworks.com comp.soft-sys.matlab:466521


Hello amutka@welho.com:
Aside of the answer by dbp, you might want to consider using
a free toolbox named ADMAT. It allows to evaluate
numerically (not analytically) any function derivative. It
also deals with vector-valued functions, which leads to
Jacobians.

To illustrate the behavior I might use this script:
>> x=deriv(17,1)  
val =
    17
deriv =
     1
>> y=x.*x+3*log(x)
val =
  297.4996
deriv =
   34.1765

The first statement defines the variable x as the one which
against the derivatives should be performed. It is
initialized with 17, and a second field is specified as "1". 
The second statement defines the formula to be analyzed,
which value should be stored in variable "y". 
Notice that Matlab reports that y has two fields; y.val
which is the value you expect to get (17*17+3*log(17)) and
the interesting one: y.deriv, which is numerically equal to
2*17+3/17 (i.e. the exact formula for the derivative.
The technology behind this miracle is "operator
overloading", and fortunately for use we need not to know
anything about it.

To illustrate something else, if you want to use your
example you should modify it a bit:
Function out = fun(f,x)
x=deriv(x,ones(size(x)));
dummy = feval(f,x);
out=dummy.val;

If you want to test this workaround, I can provide a copy of
the ADMAT toolbox. Just ask me off the list.
Regards
Carlos