Last active
October 29, 2015 04:05
-
-
Save Rokt33r/c7c68ec5b9bda1bc2cb3 to your computer and use it in GitHub Desktop.
誘導制御課題1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Python3で書かれました。
使うには
numpy
が必要です。