From: Raul on
Hi All,

I have the following issue. Suppose I have an objective function such as:

function x = myfun(a,c)
x=(a*c')^2;
end

where a and c are two vectors of size 1xN. If I want to search for the minimum of myfun, provided a given value, for example c=[1,1,1], I can simply type:

c=[1,1,1];
x = fminsearch(@(a) myfun(a,c),[1,1,1])

and matlab will minimize over the components of a. However, if I want to minimize over BOTH a and c, I don't see a way to incorporate two vectors as intial conditions into fminsearch. is this possible? Is there another function that does this?

thanks in advance

--raul
From: Yi Cao on
Raul,

You can define a vector with length 2N, then in your cost function to split it into two vectors before actual calculating the cost. For example

costf = @(x) myfun(x(1:N),x(N+1:2*N));

Then you can use fminsearch on costf to find the minimum. Although for the particular problem you gave,the solution is trivel, x=zeros(2*N,1);

HTH.
Yi

"Raul " <ragonzal(a)alum.mit.edu> wrote in message <hp1u7s$qud$1(a)fred.mathworks.com>...
> Hi All,
>
> I have the following issue. Suppose I have an objective function such as:
>
> function x = myfun(a,c)
> x=(a*c')^2;
> end
>
> where a and c are two vectors of size 1xN. If I want to search for the minimum of myfun, provided a given value, for example c=[1,1,1], I can simply type:
>
> c=[1,1,1];
> x = fminsearch(@(a) myfun(a,c),[1,1,1])
>
> and matlab will minimize over the components of a. However, if I want to minimize over BOTH a and c, I don't see a way to incorporate two vectors as intial conditions into fminsearch. is this possible? Is there another function that does this?
>
> thanks in advance
>
> --raul
From: John D'Errico on
"Raul " <ragonzal(a)alum.mit.edu> wrote in message <hp1u7s$qud$1(a)fred.mathworks.com>...
> Hi All,
>
> I have the following issue. Suppose I have an objective function such as:
>
> function x = myfun(a,c)
> x=(a*c')^2;
> end
>
> where a and c are two vectors of size 1xN. If I want to search for the minimum of myfun, provided a given value, for example c=[1,1,1], I can simply type:
>
> c=[1,1,1];
> x = fminsearch(@(a) myfun(a,c),[1,1,1])
>
> and matlab will minimize over the components of a. However, if I want to minimize over BOTH a and c, I don't see a way to incorporate two vectors as intial conditions into fminsearch. is this possible? Is there another function that does this?
>

Is it possible to pass in only one vector into
a function, then break it up into two distinct
vectors inside your function? Nah, that would
never work.

By the way, if you have more than a half dozen
or so parameters that you will be optimizing,
fminsearch is a poor choice for the optimizer.

John
From: Raul on
"John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <hp20s8$78h$1(a)fred.mathworks.com>...
> "Raul " <ragonzal(a)alum.mit.edu> wrote in message <hp1u7s$qud$1(a)fred.mathworks.com>...
> > Hi All,
> >
> > I have the following issue. Suppose I have an objective function such as:
> >
> > function x = myfun(a,c)
> > x=(a*c')^2;
> > end
> >
> > where a and c are two vectors of size 1xN. If I want to search for the minimum of myfun, provided a given value, for example c=[1,1,1], I can simply type:
> >
> > c=[1,1,1];
> > x = fminsearch(@(a) myfun(a,c),[1,1,1])
> >
> > and matlab will minimize over the components of a. However, if I want to minimize over BOTH a and c, I don't see a way to incorporate two vectors as intial conditions into fminsearch. is this possible? Is there another function that does this?
> >
>
> Is it possible to pass in only one vector into
> a function, then break it up into two distinct
> vectors inside your function? Nah, that would
> never work.
>
> By the way, if you have more than a half dozen
> or so parameters that you will be optimizing,
> fminsearch is a poor choice for the optimizer.
>
> John

Thank you guys very much!
Another question: If the number of parameters is large, would it be better to use fminunc then?

Thanks

--raul
From: Yi Cao on
Yes, I think so.

Yi

"Raul " <ragonzal(a)alum.mit.edu> wrote in message <hp21oc$jq3$1(a)fred.mathworks.com>...
>
> Thank you guys very much!
> Another question: If the number of parameters is large, would it be better to use fminunc then?
>
> Thanks
>
> --raul
 |  Next  |  Last
Pages: 1 2
Prev: problems with adquisition card
Next: bad image