Is there a way to use base::apply and a CVXR elementwise function to apply an elementwise function to every column of a matrix? Assuming the length of the vector matches the number of rows of the matrix, I'd like to be able to make my objective function the following:
new_matrix <- apply(constant_matrix, 2, function(x) x * variable_vector)
objective <- sum_entries( max_entries( as.matrix(new_matrix), axis = 2 ) )
I get the following error when solving the problem: Error in min(constant) : invalid 'type' (list) of argument
(In case my code is unclear, my goal is to multiply a variable vector by every column of a constant matrix, then get the max of each of those scaled columns, and then sum all of those maxes.)
Thanks!
Below I work out an example using
base::apply
and element-wise multiplication withCVXR
along with the output. For a more involved example, see the Pliable Lasso.Here is the output: