Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Passing constants to optimization functions
Date: Wed, 10 Oct 2007 15:36:26 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 22
Message-ID: <feirhq$o83$1@fred.mathworks.com>
References: <feiqhl$7nd$1@fred.mathworks.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
NNTP-Posting-Host: webapp-06-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1192030586 24835 172.30.248.36 (10 Oct 2007 15:36:26 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 10 Oct 2007 15:36:26 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:432243



"David Doria" <daviddoria@gmail.com> wrote in message <feiqhl$7nd
$1@fred.mathworks.com>...
> I am trying to use lsqnonlin(), but my user defined function
> needs to know a couple of constants.  The lsqnonlin expects
> my function to only accept one parameter (the one being
> optimized).  Is there a better way to "pass" these constants
> besides making them global?

Use an anonymous function.

a = 2;
f = @(x) (x-a).^2;

Obviously, the minimum occurs at x = a = 2.
Can we find it?

x = fminsearch(f,0)
x =
                         2

HTH,
John