我创建了一个矩阵A,它是一个300行4列的数组。 在目标函数中,我需要将A*x最小化,其中x是一个1行4列的向量。 以下是我的代码:
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
\]