Function in abs() resolves to double but there's still an error
Show older comments
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 Comments
Pratham Shah
on 17 Mar 2023
Can you share the snippet of code and error?
Christopher
on 18 Mar 2023
Edited: Christopher
on 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
on 19 Mar 2023
Edited: Christopher
on 19 Mar 2023
Christopher
on 19 Mar 2023
Answers (0)
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!