您好,我想解决以下第一个ODE:
dt / dr = +-cos(t)^ 2 / cos(r)^ 2
我知道解决方案是:t(r)= t(r)= arctan(tan(r)+ _ C1),其中:
pi / 2 我想知道如何改善下面的代码,使我的解决方案类似于图像中t轴趋于+无穷大的曲线: 我的代码是: 和我当前的图形输出是: import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
"""
Equations to be solved:
boundary conditions:
-pi/2 << t << pi/2
0 <= r <= pi/2
Equation:
dt/dr = +- cos^2(t)/cos^2(r)
Solution :
t(r) = arctan(tan(r) +_C1)
"""
def dt_dr(t,r):
return (cos(t)**2)/(cos(r)**2)
rs = np.linspace(0,pi/2,1000)
t0 = 0.0 #the initial condition
ts = odeint(dt_dr,t0,rs)
ts = np.array(rs).flatten()
plt.rcParams.update({'font.size': 14})
plt.xlabel("r")
plt.ylabel("t")
plt.plot(rs,ts);