1

我尝试使用梯形搭配来解决双积分器控制问题。我在 CVXPY 做。这是一个两点边值问题。解决后,控制有一个跳跃超出限制以满足结束条件。找不到原因。我附上了下面的代码。提前致谢

import numpy as np
from cvxpy import *
import matplotlib.pyplot as plt

np.random.seed(1)
n= 2
m = 1
T = 50
alpha = 0.02
beta  = 5

A = np.zeros((2,2))
A[0,1] = 1
B= np.zeros((2,1))
B[1,0] = 1
dt = 0.02




x_0 =  np.zeros(2)

x = Variable((2,T+1))
u = Variable((1,T+1))

cost = 0
constr =[]

for t in range(T):
    cost   += sum_squares(u[:,t])



    constr += [x[0,t+1] == x[0,t] + 0.5*dt*(x[1,t+1]+x[1,t])  ]
    constr += [x[1,t+1] == x[1,t] + 0.5*dt*(u[0,t+1]+u[0,t])  ]



constr +=[x[0,T]==1,x[1,T]==0]
constr +=[x[:,0]==x_0 ]



problem = Problem(Minimize(cost),constr)
#problem.solve()
#problem.solve(solver='SCS',eps=1e-5,max_iters=1000,verbose=True)
problem.solve(verbose=True, solver='ECOS')


f = plt.figure()
ax = f.add_subplot(411)
plt.plot(u[0,:].value)
plt.subplot(4,1,3)
x1 = x[0,:].value
plt.plot(x1)
plt.subplot(4,1,4)
x2 = x[1,:].value
plt.plot(x2)
plt.show()

状态和控制图

4

0 回答 0