I created a matrix A, which is 300x4 array. And in the objective, i should minimize A*x, where x is a 1x4 vector. and my code is the following:
k = 3
m = length(u)
n = k + 1
A = zeros(m,k+1)
for i = 1:m
for j = 1:k+1
A[i,j] = u[i]^(k+1-j)
end
end
display(A)
using JuMP,Gurobi
m = Model(Gurobi.Optimizer)
@variable(m, x[1:k+1])
@objective(m, Min, sum((y - (A*x).^2) ))
optimize!(m)
uopt = value.(x)
println(x)
Output:
DimensionMismatch("dimensions must match")
Stacktrace:
[1] promote_shape at .\indices.jl:154 [inlined]
[2] promote_shape at .\indices.jl:145 [inlined]
[3] -(::Array{Int64,1}, ::Array{GenericQuadExpr{Float64,VariableRef},1}) at .\arraymath.jl:38
\]
If dim(A) = 300x4, and dim(x) = 1x4 (dimensions taken from your question), then A*x (as in "the product of the matrix multiplication") is not defined as the dimensions do not match. Note that it would work if you changed x to be of dimension 4x1, and the result would have a dimension of 300x1.
In case this does not solve your issue, find line 154 (and maybe 145) in your code, as the dimension mismatch happens in these lines, and check your code in that lines for plausibility.
I did not actually verify your code (and it seems like it is not the full code, also?), and I know there are more capable people who may help you there. Anyway, I hope this helps.
Happy coding.