Can python solve differential equations?

爱喝马黛茶的安东尼
Release: 2019-06-18 15:11:10
Original
5372 people have browsed it

Sympy

Sympy is a mathematical symbol library (sym stands for symbol, symbol), including various mathematical operation methods such as integrals and differential equations, and is provided for python Provides powerful mathematical operation support. For images, although they are all doing discrete calculations, and the most operations are arrays in numpy, but in fact, this library contains the most basic mathematical operations such as integral differential, trigonometry, etc. It can be said to be the most basic in engineering. Use It's comparable to matlab.

Can python solve differential equations?

sympy installation

sudo pip install sympy or sudo pip3 install sympy

If you use anaconda then conda install sympy

Related recommendations:《python视频

odeint() function

odeint() function is a scipy library A function that numerically solves differential equations
odeint() function requires at least three variables. The first is the differential equation function, the second is the initial value of the differential equation, and the third is the independent variable of the differential.

Example:

#y"+a*y'+b*y=0 
from scipy.integrate import odeint        #使用odeint之前,首先从scipy.integrate中调用它from pylab import *
def deriv(y,t):        # 返回值是y和y的导数组成的数组
    a = -2.0
    b = -0.1
    return array([ y[1], a*y[0]+b*y[1] ])
time = linspace(0.0,50.0,1000)
yinit = array([0.0005,0.2])     # 初值
y = odeint(deriv,yinit,time)
 
figure()
plot(time,y[:,0],label='y')    #y[:,0]即返回值的第一列,是y的值。label是为了显示legend用的。
plot(time,y[:,1],label="y'")     #y[:,1]即返回值的第二列,是y’的值
xlabel('t')
ylabel('y')
legend()
show()
Copy after login

The output results are as follows:

Can python solve differential equations?

The above is the detailed content of Can python solve differential equations?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template