Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: fminsearch matab problem
Date: Thu, 20 Mar 2008 18:41:02 +0000 (UTC)
Organization: Univ of Cambridge
Lines: 50
Message-ID: <frub3u$s2u$1@fred.mathworks.com>
References: <26104615.1205870768015.JavaMail.jakarta@nitrogen.mathforum.org>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1206038462 28766 172.30.248.35 (20 Mar 2008 18:41:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 20 Mar 2008 18:41:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 503430
Xref: news.mathworks.com comp.soft-sys.matlab:458355



Even simpler, use a nested program structure!

Your m-file should read like this:


function [output] = my_optimisation(inputs)
% MY_OPTIMISATION does blah blah (header description)


% Make an initial guess
guess = make_first_guess(inputs);

% Calculate some other stuff
things_i_want_constant = some_computations();

% Perform the search, passing a handle to your nested
function as the evaluation function
x = fminsearch(@evaluation_fun,guess);


% Define the nested evaluation function
function [score] = evaluation_function(guess);

% Insert code to return a score as a function of guess. 
% Note that this nested function also has access to the
% variables in the main function, 
% e.g. the things_i_want_constant
score = ... your code....

% End the nested function
end
% End the main function
end



jimpx <falloncolm@gmail.com> wrote in message
<26104615.1205870768015.JavaMail.jakarta@nitrogen.mathforum.org>...
> Hello,
> 
> I want to pass a number of variables through fminsearch.
Because of the structure of the program, some of those
variables must be held constant while the others are
minimized. Is there a way to do this with fminsearch, or is
there another minimization program which allows this?
> 
> Thanks,
> 
> jimpx