zlq178
#1
```
using JuMP,Gurobi
n=4
a=[0;0;50;50]
b=[0;0;351;389]
c=[0;0;44.4;40.6]
model=Model(Gurobi.Optimizer)
@variable(model, P[1:n,1])#julia中创建一个全参数决策变量的方式
f=@expression(model,a'*(P.*P)+b'*P+sum(c))
@objective(model,min,f)
```

Errors:

How can I solve this problem?

odow
#2
The issue is `P .* P`

when `P`

is a `DenseAxisArray`

.

Option one is to make the variable just a `Array`

:

```
@variable(model, P[1:n])
```

Here is the documentation: https://jump.dev/JuMP.jl/v0.21.1/variables/#Variable-containers-1

Option two is to write out the sum

```
@expression(model, sum(a[i] * P[i]^2 for i = 1:n))
```

zlq178
#3
I get it. Thank you very much.

1 Like