Skip to content

Instantly share code, notes, and snippets.

@Rokt33r
Last active October 29, 2015 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rokt33r/c7c68ec5b9bda1bc2cb3 to your computer and use it in GitHub Desktop.
Save Rokt33r/c7c68ec5b9bda1bc2cb3 to your computer and use it in GitHub Desktop.
誘導制御課題1
import numpy as np
from math import *
dt = 0.1
a11 = (2 * e ** -dt) - (e ** -(2 * dt))
a12 = (e ** -dt) - (e ** -(2 * dt))
a21 = (-2 * e ** -dt) + (2 * e ** -(2 * dt))
a22 = (-e ** -dt) + (2 * e ** -(2 * dt))
eA = np.matrix([[a11, a12], [a21, a22]])
invA = np.matrix([[0, 1], [-2, -3]]) ** -1
B = np.matrix([[0], [1]])
x0 = np.matrix([[0], [-1]])
def u(t):
return sin(2*t)
i = 0
xn = x0
print('i, xk, x')
while i < 10.0:
# 漸化式を用いた解
tmp_xn = xn
xn = eA * tmp_xn + invA * (eA - np.matrix([[1,0],[0,1]])) * B * sin(2 * (i + dt))
# 解析解
x = (-sin(2*i) - 3*cos(2*i) - 12 * e**(-i) + 15 * e**(-2*i))/20
print(str(round(i, 2)) + ', ' + str(tmp_xn.item(0)) + ', ' + str(x))
i += dt
@Rokt33r
Copy link
Author

Rokt33r commented Oct 28, 2015

Python3で書かれました。
使うにはnumpyが必要です。

pip3 install numpy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment