我创建了一个矩阵 A,它是 300x4 数组。在目标中,我应该最小化 A*x,其中 x 是一个 1x4 向量。我的代码如下:
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)
输出:
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
\]