Boundary conditions for differential equation using sympy
I am trying to specify a boundary condition for a 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 shows an error
diffeq = (Eq(y(x).diff(x, x) - 900*y(x) + 900, 1800*x),y(0):5,y(2)=10)
^
SyntaxError: invalid syntax
Please help.
+3
source to share
1 answer
The boundary conditions are passed as dsolve
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 into sympy live to see if it works. Answer:
f (x) = C1 * e ^ -30x + C2 * e ^ 30x - 2x + 1
+1
source to share