@ LutzL
Я бы использовал пакет tenorflow, потому что он был обязан профессору.
Итак, я нашел ответ с помощью друзей:
'''
Inital DOE:
vc'' + R/L * vc' + vc/LC = E/LC
Using state variables:
x1 = vc
x1' = vc'
x2 = vc' = x1'
x2' = vc''
a b c
x2' = E/LC - R/L*x2 - 1/LC*x1
x1' = x2
y = x1
'''
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
graph = tf.Graph()
with graph.as_default():
E = 10.0 #Source Voltage
R = 2.5 #Resistor
L = 0.01 #inductor
C = 0.001 #capacitor
a = E / (L * C)
b = R / L
c = 1.0 / (L * C)
x1 = tf.constant(0.0)
x2 = tf.constant(0.0)
t = np.linspace(0, 1.0, num=1000)
def SecondOrderDev(state, t):
x1, x2 = tf.unstack(state)
dx1 = x2
dx2 = -c*x1 - b*x2 + f
return tf.stack([dx1, dx2])
tensor_state, tensor_info = tf.contrib.integrate.odeint(SecondOrderDev, [x1, x2], t, full_output=True)
with tf.Session() as sess:
state, info = sess.run([tensor_state, tensor_info])
y, _ = state.T
tf.summary.FileWriter('/tmp/logs', tf.get_default_graph()).close()
plt.plot(t, y)
Это только если вы используете colab и хотите увидеть график:
!wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
!unzip ngrok-stable-linux-amd64.zip
LOG_DIR = '/tmp/logs'
get_ipython().system_raw(
'tensorboard --logdir {} --host 0.0.0.0 --port 6006 &'
.format(LOG_DIR)
)
get_ipython().system_raw('./ngrok http 6006 &')
! curl -s http://localhost:4040/api/tunnels | python3 -c \
"import sys, json; print(json.load(sys.stdin)['tunnels'][0]['public_url'])"