Vector input for an objective function using MultiStart?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi All,
Assume I have three rows of the experimental data A[1x13], B[1x13], and C[1x13], and I'd like to find out the best fit for A vs. B & C using the following known equation:
A=x(1)*B+x(2)*C^2 ----- Eq(1)
A,B,C are known values, each of them is a [1x13] vector. I just need the optimization to find out the two coefficients x(1) and x(2). Specifically, I'd like to use MultiStart & Optimization. My real function that describes A vs. B & C is a lot more complex than Eq(1), and my real function has more dimensions than 3D listed here (eg. A vs B,C,D,E,etc.) But I just want to learn where I did wrong using a simple example.
I wrote a simple function that aims to return the optimized x(1) and x(2):
function [x fval R_2] = test(A,B,C,P)
myfunction=@(x,B,C) (x(1).*B+x(2).*C.^2)
fun=@(x)((myfunction([x(1),x(2)],B,C)-A).^2); opts = optimset('Algorithm','interior-point');
problem = createOptimProblem('fmincon','x0',randn(1,2),... 'objective',fun,'lb',[0 0],'ub',... [10000 30],'options',opts);
rs = RandomStartPointSet('NumStartPoints',P); % P= number of iterations
ms = MultiStart('UseParallel','always','Display','iter');
[x fval] = run(ms,problem,rs)
However, I get the error similar to "Inputs must be a scalar and a square matrix". And I read about how to write a scalar objective function, it seems my input for a scalar objective function can be vector. So I am lost.
Can anybody help? Thank you.
0 comentarios
Respuestas (1)
Alan Weiss
el 23 de Sept. de 2016
Editada: Alan Weiss
el 23 de Sept. de 2016
I believe that you settled on a tool before thinking about your problem. It seems to me that you have a linear problem, so should not be using an iterative solution.
Make a matrix M whose columns are composed of the transpose of B and the transpose of C.^2:
M = [B',(C.^2)'];
In this notation, your equations are:
M*x = A'
Then your least-squares solution vector x is given by
x = M\(A')
This reasoning extends to any number of dimensions.
Alan Weiss
MATLAB mathematical toolbox documentation
0 comentarios
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!