```Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: minimizing a dynamic function
Date: Sun, 15 Aug 2010 16:23:04 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 49
Message-ID: <i49498\$haf\$1@fred.mathworks.com>
References: <i48snb\$fjt\$1@fred.mathworks.com> <i491f8\$i98\$1@fred.mathworks.com> <i492f4\$lj5\$1@fred.mathworks.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1281889384 17743 172.30.248.35 (15 Aug 2010 16:23:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 15 Aug 2010 16:23:04 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:662197

"Dominik Ballreich" <dominik.ballreich@gmail.com> wrote in message <i492f4\$lj5\$1@fred.mathworks.com>...
> Hi John,
>
>
> that you very much for the answer. It's true. I really don't know how to use function handles.
>
> I don't know where to pass in the parameter i. It's confusing to me.

So learn. Maybe start here.

doc function_handle

Or try something.

fun = @(x,k) sin(x+k);

Can we minimize this function for k = 2?

[x,fval] = fminbnd(@(x) fun(x,2),0,10)
x =
2.71238413719389

fval =
-0.999999999988272

Or, try this.

funlist = {@sin, @cos};
i = 1;
[x,fval ] = fminbnd(funlist{i},0,10)

x =
4.71238236854635
fval =
-0.999999999978142

i = 2;
[x,fval ] = fminbnd(funlist{i},0,10)
x =
3.14159317188068
fval =
-0.999999999999866

Of course, you could also trivially pass in i to a function
that would then perhaps use a switch/case to switch
between a choice of functions.

John
```