import matplotlib.pyplot as plt
from numpy.linalg import inv
# Define the system parameters
m1 = 2
m2 = 3
k1 = 100
k2 = 200
c = 1
# Define the system matrices
A = np.array([[0, 0, 1, 0],
[(k2 - k1) / m2, -k2 / m1, 0, 0],
[0, 0, 0, 1],
[k2 / m2, -(k2 + k1) / m2, 0, -c / m2]])
B = np.array([[0], [0], [0], [1 / m2]])
C = np.array([[1, 0, 0, 0]])
# Define an initial state for simulation
x0 = np.zeros(shape=(4, 1))
# Define the number of time-samples used for the simulation
time = 30000
# Discretization constant
h = 0.001
# Define an input sequence for the simulation
input_seq = 10 * np.ones(shape=(1, time))
#plt.plot(input_sequence)
I = np.identity(A.shape[0]) #this is an identy matrix
A_D = inv(I - h * A)
B_D = h * np.matmul(A_D, B)
C_D = C
# Check the eigenvalues
# Continuous-time system
eigen_A = np.linalg.eig(A)[0]
# Discrete-time system
print(eigen_A)
eigen_A_D = np.linalg.eig(A_D)[0]
def simulate(Am, Bm, Cm, initial_state, input_sequence, time_steps):
Xm = np.zeros(shape=(Am.shape[0], time_steps + 1))
Ym = np.zeros(shape=(Cm.shape[0], time_steps + 1))
for i in range(0, time_steps):
if i == 0:
Xm[:, [i]] = initial_state
Ym[:, [i]] = np.matmul(Cm, initial_state)
input_tmp = input_sequence[0, i].reshape(Bm.shape[1], 1)
x = np.matmul(Am, initial_state) + np.matmul(Bm, input_tmp)
else:
Xm[:, [i]] = x
Ym[:, [i]] = np.matmul(Cm, x)
input_tmp = input_sequence[0, i].reshape(Bm.shape[1], 1)
x = np.matmul(Am, x) + np.matmul(Bm, input_tmp)
Xm[:, [-1]] = x
Ym[:, [-1]] = np.matmul(Cm, x)
return Xm, Ym
states, output = simulate(A_D, B_D, C_D, x0, input_seq, time)
plt.plot(states[1, :], color='blue', linewidth=2)
plt.xlabel('Discrete time instant-k')
plt.ylabel('State')
plt.title('System Response')
plt.savefig('step_response_Euler.png', dpi=600)
plt.show()
여기에서 시뮬을 돌리고 싶은데 혹시 어떻게 돌려야 하는지 알려주실 수 있을까요...?
시뮬을 돌린다는게 실행하고싶다는 뜻인가요?
넵 그렇습니다
import numpy as np import matplotlib.pyplot as plt from numpy.linalg import inv 이게 오류라고 떠요...
#python main.py
pip install numpy, matplotlib
해당 댓글은 삭제되었습니다.
을 어디에다가 적어야 해요?
장난치려했다가 울까봐 지운거임 오류면 오류메시지 같이 올려
등록했어요
윗댓 pip install numpy, matplotlib 해봤음?
방금 다 깔았어요
이제 실행 ㄱㄱ
Error in the AREPL extension! Error running python with command: Phython interperpreter -u c:\Users\User\.vscode\extensions\almenon.arepl-2.0.5\node_modules\arepl-backend\python\arepl_python_evaluator.py Error: spawn Phython interperpreter ENOENT at ChildProcess._handle.onexit (node:internal/child_process:283:19) at NT (node:internal/child_process:476:16) at process.processTicksAndReject
Error in the LiveCode extension! err code: 101 Print Output: Unable to create process using 'C:\Users\User\AppData\Local\Programs\Python\Python312\python.exe -u c:\Users\User\.vscode\extensions\xirider.livecode-1.3.10\node_modules\arepl-backend\python\arepl_python_evaluator.py': ??? ??? ?? ? ????.
이런 오류가 떠요... 이미지 캡져 해서 올렸어요
터미널에 python -V 치면 뭐라고 나옴 ?
터미널이 맨 위에 있는 검색창 말씀하시는 거죠? 아무것도 안나와요... 확장 프로그램 창에다가 검색해도 안나와요
아니 하단에 TERMINALS 누르고 거기에 python -V 치면 뭐라고 나올텐데 뭐라 나오는지 알려줘
python ps c:/users/user>
그게 다야?
spq
넵
https://www.python.org/downloads/
파이썬
설치했니
네
그 > 오른쪽에 python -V 치고 엔터 누른거 맞아? Python 3.10.10 이런 문구가 떠야 정상임
뭐지... 다시 설치해볼까요?
ㅇㅇ 다시 설치하고 vsc 껐다키고 해보셈
vsc가 뭔지 여쭤봐도 될까요?
너가 코딩하는 프로그램 비주얼스튜디오코드
컴퓨터 껏다 키니
"": "Phython interperpreter" 이런게 뜨네요...
2023-11-29 01:20:35.011 [info] ����: ���μ��� "12872"��(��) ã�� �� �����ϴ�. Python����: ���μ��� "15264"��(��) ã�� �� �����ϴ�.
컨트롤 + 시프트 + p 누르면 나오는 검색창에 python: select interpreter 치고 누르면 인터프리터 목록 나옴 "Python 3.10 ~ 64-bit"라고 써있고 우측에 python.exe 경로 뜸?
아니요...... 그냥 아애 지웠다가 해야 하는데 오늘까지 과제 제출이여서 코드는 짰다는 거만 보여드릴라고요...
늦은 시간까지 도와주셔서 감사합니다.