Optimization problem that fails to converge

Welcome to Julia and Julia Discourse.

Because you stated that your math is rusty, I will mention that the product of a matrix and a vector is just the linear combination of the columns of the matrix, with the vector elements as the linear coefficients. Therefore, your problem looks like a nonnegative least squares problem. It can be solved very simply using the NonNegLeastSquares package. Here is a solution using random values for the vectors c1 through c7:

using NonNegLeastSquares: nonneg_lsq
using LinearAlgebra: norm
c1_to_c6 = rand(300,6) # Contains columns c1 through c6
c7 = rand(300) # Contains column 7
coefs = nonneg_lsq(c1_to_c6, c7)
@show coefs
@show norm(c1_to_c6 * coefs - c7)

This produces the following output (it will be different for you due to the random entries):

coefs = [0.17908585324436196; 0.10343518649759845; 0.09408512183744712; 0.21328999063315954; 0.2224834340815174; 0.1077332059326006;;]
norm(c1_to_c6 * coefs - c7) = 5.595322154323634
5.595322154323634
1 Like