Function in abs() resolves to double but there's still an error
Mostrar comentarios más antiguos
I'm using the optimisation toolbox and my objective is to try and find a vector of length sz, x1, such that the "covariance" between the target and a different known vector, x0, also of length sz, is as close to zero as possible. To do this, I've set the objective function to be
abs( dot(x1, x0) / sz - 1/4 )
However, I get an error that says "Incorrect number or types of inputs or outputs for function 'abs'". The input is one double and the output is one double so I don't understand what the problem is. Searching for the error online doesn't help either. Please explain why this error is occuring.
Thanks.
6 comentarios
Pratham Shah
el 17 de Mzo. de 2023
Can you share the snippet of code and error?
Christopher
el 18 de Mzo. de 2023
Editada: Christopher
el 18 de Mzo. de 2023
If f1 is a double array, try
% Create optimization variables
uk1 = optimvar('uk1',2000,1,"LowerBound",lower,"UpperBound",upper);
% Set initial starting point for the solver
initialPoint15.uk1 = u0;
% Create problem
problem2 = optimproblem;
% Define problem objective
f = @(x) abs( dot(x, f1) / sz - 1/4);
obj = fcn2optimexpr(f,uk1);
problem2.Objective = obj;
or use
(dot(uk116, f1) / sz - 1/4)^2
instead of
abs( dot(uk116, f1) / sz - 1/4)
@Christopher Your problem is quite ill-posed. basically, you are trying to find an x1 that lies within the intersection of a hyperplane and a box. If the problem has a solution, there will be an infinite number of them.
Christopher
el 19 de Mzo. de 2023
Editada: Christopher
el 19 de Mzo. de 2023
Christopher
el 19 de Mzo. de 2023
Respuestas (0)
Categorías
Más información sobre Surrogate 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!