how to multiply a gekko array of FV or variables to a gekko intermediate array if both have different dimensions without changing the amount of FV?

Viewed 32

of course there is code afterwards but to keep it simple and to express my problem I will only share this. everything is working fine I basically just need the array "x" to change from size 24 to the number of my other array (in this case 100). The array can't be changed in the beginning because it is an hour factor so I just want to optimize 24 values and not create a new array and optimize 100 different values. The 24 values need to repeat eachother because the array of size 100 or basically 4 days and 4 hours (4*24+4=100). Of course I will be happy too if someone just know a way without changing dimension but I think this is not possible.

f=[1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06]
x4= [0.045930370209, 0.043303258083, 0.039624317151, 0.039318197146, 0.037919352547, 0.037661007306, 0.034399522806, 0.034002995811, 0.033886332129, 0.037339258323, 0.037931042705, 0.038383778229, 0.038823242557, 0.040123255664, 0.040823891738, 0.04379281023, 0.043943821635, 0.045684085291, 0.046003064191, 0.046954569286, 0.048654216051, 0.049955602478, 0.048859969614, 0.046682038822]
T_g=[10.22025, 10.22025, 10.22025, 10.22025, 10.22025, 10.22025, 10.22025, 10.22025, 10.22025, 10.22025, 10.22025, 10.22025, 10.22025, 10.22025, 10.22025, 10.22025, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 10.424666667, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 10.101444444, 12.065722222, 12.065722222, 12.065722222, 12.065722222, 12.065722222, 12.065722222, 12.065722222, 12.065722222, 12.065722222, 12.065722222, 12.065722222, 12.065722222]
x = m.Array(m.FV,24)
for i in range(24):
            x[i].value = x4[i]
            x[i].lower = 0.01
            x[i].upper = 0.15
            x[i].STATUS=1
e= m.Var(2.7,lb=1,ub=4)
l = m.Var(-35.1,lb=-38,ub=-30)
g = m.Var(7.1,lb=5,ub=9)
h = m.Var(0.142,lb=0.0,ub=1.5)
xop=[None]*1
ysimm=[None]*1
a=[None]*1
index = np.ones(N,int)
for i in range(N):
            index[i]= int(i%24)

a[0]=m.Intermediate((e / (1 + (l / (T_g - 40)) ** g) + h))
ysimm[0]=m.Intermediate(a[0]*f)
xop[0]=m.Intermediate(x[index]*ysimm[0])

1 Answers

Use list comprehensions to convert a and ysimm to lists.

import numpy as np
from gekko import GEKKO
m = GEKKO()
f=[1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, \
   1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, \
   1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, \
   1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, \
   0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, \
   0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, \
   0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, \
   0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, \
   0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 1.06, 1.06, 1.06, \
   1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06, 1.06]
x4= [0.045930370209, 0.043303258083, 0.039624317151, 0.039318197146, \
     0.037919352547, 0.037661007306, 0.034399522806, 0.034002995811, \
     0.033886332129, 0.037339258323, 0.037931042705, 0.038383778229, \
     0.038823242557, 0.040123255664, 0.040823891738, 0.04379281023, \
     0.043943821635, 0.045684085291, 0.046003064191, 0.046954569286, \
     0.048654216051, 0.049955602478, 0.048859969614, 0.046682038822]
T_g=[10.22025, 10.22025, 10.22025, 10.22025, 10.22025, 10.22025, \
     10.22025, 10.22025, 10.22025, 10.22025, 10.22025, 10.22025, \
     10.22025, 10.22025, 10.22025, 10.22025, 10.424666667, \
     10.424666667, 10.424666667, 10.424666667, 10.424666667, \
     10.424666667, 10.424666667, 10.424666667, 10.424666667, \
     10.424666667, 10.424666667, 10.424666667, 10.424666667, \
     10.424666667, 10.424666667, 10.424666667, 10.424666667, \
     10.424666667, 10.424666667, 10.424666667, 10.424666667, \
     10.424666667, 10.424666667, 10.424666667, 9.1760277778, \
     9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, \
     9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, \
     9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, \
     9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, \
     9.1760277778, 9.1760277778, 9.1760277778, 9.1760277778, \
     9.1760277778, 9.1760277778, 9.1760277778, 10.101444444, \
     10.101444444, 10.101444444, 10.101444444, 10.101444444, \
     10.101444444, 10.101444444, 10.101444444, 10.101444444, \
     10.101444444, 10.101444444, 10.101444444, 10.101444444, \
     10.101444444, 10.101444444, 10.101444444, 10.101444444, \
     10.101444444, 10.101444444, 10.101444444, 10.101444444, \
     10.101444444, 10.101444444, 12.065722222, 12.065722222, \
     12.065722222, 12.065722222, 12.065722222, 12.065722222, \
     12.065722222, 12.065722222, 12.065722222, 12.065722222, \
     12.065722222, 12.065722222]
N = 24
x = m.Array(m.FV,N)
for i in range(N):
   x[i].value = x4[i]
   x[i].lower = 0.01
   x[i].upper = 0.15
   x[i].STATUS=1
e = m.Var(2.7,lb=1,ub=4)
l = m.Var(-35.1,lb=-38,ub=-30)
g = m.Var(7.1,lb=5,ub=9)
h = m.Var(0.142,lb=0.0,ub=1.5)
M = len(f)
index = np.ones(M,int)
for i in range(M):
    index[i]= int(i%24)
a=[(e / (1 + (l / (T_g[i] - 40)) ** g) + h) for i in range(len(T_g))]
ysimm=[a[i]*f[i] for i in range(M)]
xop=[x[index[i]]*ysimm[i] for i in range(M)]
m.solve()
Related