简体   繁体   中英

Boundary conditions for a differential equation using sympy

I am trying to specify boundary condition for the differential equation.

*y"= 900(y - 1 + 2x) ; y(0)=5, y(2)=10*

from sympy import *
x=symbols('x')
y, g = symbols('y g', cls=Function)
diffeq = (Eq(y(x).diff(x, x) - 900*y(x) + 900, 1800*x),y(0):5,y(2)=10)
A=dsolve(diffeq, y(x))
print A

But it is showing the error

diffeq = (Eq(y(x).diff(x, x) - 900*y(x) + 900, 1800*x),y(0):5,y(2)=10)
                                                           ^
SyntaxError: invalid syntax

Kindly help.

The boundary conditions are passed to dsolve as a dictionary, through the ics named argument.

Thus:

from sympy import *
x=symbols('x')
f=symbols('f', cls=Function)
dsolve(Eq(f(x).diff(x,x), 900*(f(x)-1+2*x)), f(x), ics={f(0):5, f(2):10})

You can paste the last line to sympy live to verify that it works. The answer is:

f(x) = C1*e^−30x + C2*e^30x − 2x + 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM