I'm trying to solve a boundary-value problem using sympy. I was able to solve the ODE but the dsolve function doesn't return the values of the constants $C_1$ and $C_2$.

Boundary-value problem:

$u''_{xx}+u+1=0$ with a boundary condition $u(0)=0, \quad u'_x(1)=1$

Python Code:

I tried the next code in jupyter notebook and sympy live

from sympy import *
u = Function('u')
x = Symbol('x')
dsolve(Derivative(u(x),x,x)+u(x)+1,u(x),ics={u(0): 0, u(x).diff(x).subs(x, 1): 1})

This return the follow result:


While expected full solution is:

$$u(x)=-1+\cos(x)+\sec(1)\sin(x)+\sin (x) \tan (1)$$

Is there something wrong with my python code? How can I contour this situation to obtain the full solution using sympy?


There doesn't seem to be anything wrong with your code, per se, but the current version of SymPy doesn't actually support the use of initial conditions and boundary values, according to sources I read a little while ago. It seems that version 1.2 will.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.