Boundary conditions for a differential equation using sympy
Question:
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.
Answers:
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
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