Function in abs() resolves to double but there's still an error
Afficher commentaires plus anciens
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 commentaires
Pratham Shah
le 17 Mar 2023
Can you share the snippet of code and error?
Christopher
le 18 Mar 2023
Modifié(e) : Christopher
le 18 Mar 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
le 19 Mar 2023
Modifié(e) : Christopher
le 19 Mar 2023
Christopher
le 19 Mar 2023
Réponses (0)
Catégories
En savoir plus sur Problem-Based Optimization Setup dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!