Boundary conditions for 2nd order DEs

457 days ago by simonjtyler

Examples of boundary conditions for 2nd order des for this ask.sagemath question.

Here's the appropriate documentation: http://www.sagemath.org/doc/reference/sage/calculus/desolvers.html

var('x x_0 x_1 y_0 y_1') dy0 = var('dy0', latex_name="y'_0") dy1 = var('dy1', latex_name="y'_1") y = function('y', x) 
       
sge = desolve(diff(y,x,2) + y == 0, y, [0,y0,dy0]) mma = mathematica("y[x] /. DSolve[{y''[x] + y[x] == 0, y[0] == y0, y'[0] == dy0}, y, x]//First") show( (sge, mma.sage(), (sge - mma.sage()).trig_simplify()) ) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(y'_0 \sin\left(x\right) + y_{0} \cos\left(x\right), y'_0 \sin\left(x\right) + y_{0} \cos\left(x\right), 0\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(y'_0 \sin\left(x\right) + y_{0} \cos\left(x\right), y'_0 \sin\left(x\right) + y_{0} \cos\left(x\right), 0\right)
sge = desolve(diff(y,x,2) + y == 0, y, [0,y0,1,y1]) mma = mathematica("y[x] /. DSolve[{y''[x] + y[x] == 0, y[0] == y0, y[1] == y1}, y, x]//First") show( (sge, mma.sage(), (sge - mma.sage()).trig_simplify()) ) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(y_{0} \cos\left(x\right) - \frac{{\left(y_{0} \cos\left(1\right) - y_{1}\right)} \sin\left(x\right)}{\sin\left(1\right)}, -y_{0} \sin\left(x\right) \cot\left(1\right) + y_{1} \sin\left(x\right) \csc\left(1\right) + y_{0} \cos\left(x\right), 0\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(y_{0} \cos\left(x\right) - \frac{{\left(y_{0} \cos\left(1\right) - y_{1}\right)} \sin\left(x\right)}{\sin\left(1\right)}, -y_{0} \sin\left(x\right) \cot\left(1\right) + y_{1} \sin\left(x\right) \csc\left(1\right) + y_{0} \cos\left(x\right), 0\right)

mixed boundary condition...

show( mathematica("y[x] /. DSolve[{y''[x] + y[x] == 0, y[0] == y0, y'[1] == dy1}, y, x]//First").sage()) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}y'_1 \sin\left(x\right) \sec\left(1\right) + y_{0} \sin\left(x\right) \tan\left(1\right) + y_{0} \cos\left(x\right)
\newcommand{\Bold}[1]{\mathbf{#1}}y'_1 \sin\left(x\right) \sec\left(1\right) + y_{0} \sin\left(x\right) \tan\left(1\right) + y_{0} \cos\left(x\right)

in sage, would have to get general solution then fix constants 'manually'

ysoln = desolve(diff(y,x,2) + y == 0, y); ysoln 
       
k1*sin(x) + k2*cos(x)
k1*sin(x) + k2*cos(x)
var('k1 k2') bndrySoln = solve( [ysoln(x=0) == y0, ysoln.diff(x)(x=1) == dy1], [k1, k2]) show(bndrySoln) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left[\left[k_{1} = \frac{y_{0} \sin\left(1\right) + y'_1}{\cos\left(1\right)}, k_{2} = y_{0}\right]\right]
\newcommand{\Bold}[1]{\mathbf{#1}}\left[\left[k_{1} = \frac{y_{0} \sin\left(1\right) + y'_1}{\cos\left(1\right)}, k_{2} = y_{0}\right]\right]
ysoln.subs_expr(*bndrySoln[0]).expand().trig_reduce().show() 
       
\newcommand{\Bold}[1]{\mathbf{#1}}y'_1 \sin\left(x\right) \sec\left(1\right) + y_{0} \sin\left(x\right) \tan\left(1\right) + y_{0} \cos\left(x\right)
\newcommand{\Bold}[1]{\mathbf{#1}}y'_1 \sin\left(x\right) \sec\left(1\right) + y_{0} \sin\left(x\right) \tan\left(1\right) + y_{0} \cos\left(x\right)