Optimization of multivariable function using fminunc
Mostrar comentarios más antiguos
Hi, I have a function of the form H = X*matrix(A) + Y*matrix(B) and matrix(A) and (B) are fixed. I need to optimize X and Y simultaneously, how can I do it?
For example: if I just had H=X*matrix(A) + matrix(B), I could have used fminunc. I could have created a function handle for H and pass it as an argument in fminunc. I know how to do it for single variable, but I just don't know how to do it in multiple variable. I looked up many resources, including many old post, but I got more confused. Any help would be appreciated. Thank You
1 comentario
Walter Roberson
el 10 de Jun. de 2015
are X and Y matrices or vectors? If they are matrices then H is a matrix, and in that case you need to define what it means to "optimize" H. Lowest trace? Smallest sum-of-squares?
Respuestas (1)
Drew Davis
el 10 de Jun. de 2015
Define your function handle like so:
f = @(x) x(1:a) * A + x(a+1:end) * B
where:
X = x(1:a) , Y = x(a+1:end)
then
x = fminunc(f , x0);
where:
X0 = x0(1:a) , Y0 = x0(a+1:end)
Note 'a' is the number of elements in the 'X' vector.
4 comentarios
Drew Davis
el 10 de Jun. de 2015
This is assuming the resulting 'H' is a vector
Walter Roberson
el 11 de Jun. de 2015
In the original question, X and Y could b row vectors and the result of X*A would then be a row vector the same width as A. Y could be a different length but the resulting row vector for Y*B would have to be the same length. H would then be a row vector result. This assumes that A and B are really arrays and not vectors.
If X and Y are column vectors then the result of X*A is going to be a full vector, length(x) by size(A,2), and Y and B would have to be the same size, and the result would be a full matrix that size.
However:
- it is not documented whether fmincon() uses row vectors or column vectors. Perhaps it uses the same size as the initial vector of points. Maybe not. This would have to be tested in order to determine whether we need to transpose the extracted vectors
- fmincon requires that its function returns a scalar . The above analysis shows that X*A+Y*B will not be a scalar if A and B are truly arrays and not vectors. The row-vector X and Y and column-vector A and B case would be the easiest case to return a scalar. On the other hand, that situation has an obvious minimization: make X(K) = -sign(A(K))*infinity where K is the index of the first non-zero entry in A so that the sum becomes -infinity.
Drew Davis
el 11 de Jun. de 2015
fminunc will take row vectors (depends on initial points as you suggested). Try the following:
fminunc(@(x) x(1)^2 + 0.1 * x(2)^2 , [1,1])
Walter Roberson
el 11 de Jun. de 2015
Editada: Walter Roberson
el 11 de Jun. de 2015
Okay, but we still end up with problems with the output size. The only non-trivial case of this form that fminunc can deal with has a trivial solution of letting some of the components go to infinity or negative infinity. This then gets back to the question I posed earlier about what about the matrix is to be "minimized", such as possibly the trace.
Categorías
Más información sobre Problem-Based Nonlinear Optimization en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!