Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168727
Image: ubuntu2004
#The following on-line book might be useful #http://sage.math.washington.edu/home/wdj/teaching/DiffyQ/des-book.pdf y,x=var('y x') y=function('y',x) # Declares x to be the independent variable, and y to be the dependent one
phi=desolve(diff(y,x)+3*y==2*x, y) #Solves for y in the differential equation dy/dx+3y=2x show(phi) #Notice that the solution involves a constant
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{9} \, {\left(2 \, {\left(3 \, x - 1\right)} e^{\left(3 \, x\right)} + 9 \, c\right)} e^{\left(-3 \, x\right)}
phi=desolve(diff(y,x)+3*y==2*x, y,[3,5]) #Solves for y in the Initial Value Problem # dy/dx+3y=2x, when x=3, and y=5; i.e. y(3)=5 show(phi) #Notice that the solution does not involve a constant
\frac{1}{9} \, {(2 \, {(3 \, x - 1)} e^{3 \, x} + 29 \, e^{9})} e^{-3 \, x}
\newcommand{\Bold}[1]{\mathbf{#1}}
phi=desolve(diff(y,x,2)+diff(y,x)-y==cos(x),y) #Solves for y in the ODE #d^2/dx^2 +dy/dx-y=cos(x) #Notice that the solution involves two constants show(phi)
\newcommand{\Bold}[1]{\mathbf{#1}}k_{1} e^{\left(\frac{1}{2} \, {\left(\sqrt{5} - 1\right)} x\right)} + k_{2} e^{\left(-\frac{1}{2} \, {\left(\sqrt{5} + 1\right)} x\right)} + \frac{1}{5} \, \sin\left(x\right) - \frac{2}{5} \, \cos\left(x\right)
phi=desolve(diff(y,x,2)+diff(y,x)-y==cos(x),y,[0,1,2]) #Solves for y in the Initial value problem #d^2/dx^2 +dy/dx-y=cos(x) #When x=0,y=2,dy/dx=3 #That is, when y(0)=1, and y'(0)=3 show(phi)
\newcommand{\Bold}[1]{\mathbf{#1}}-\frac{1}{10} \, {\left(5 \, \sqrt{5} - 7\right)} e^{\left(-\frac{1}{2} \, {\left(\sqrt{5} + 1\right)} x\right)} + \frac{1}{10} \, {\left(5 \, \sqrt{5} + 7\right)} e^{\left(\frac{1}{2} \, {\left(\sqrt{5} - 1\right)} x\right)} + \frac{1}{5} \, \sin\left(x\right) - \frac{2}{5} \, \cos\left(x\right)
#In general, for first degree equations, try x,y=var('x y') y=function('y',x) def pp(eq): p=str(eq).replace('D[0](y)(x)', r'\frac{d y}{d x}') p=p.replace('D[0, 0](y)(x)', r'\frac{d^2y}{dx^2}') p=p.replace('y(x)','y') p=p.replace('*',' ') return '$'+p+'$' @interact def m274(eq='diff(y,x)+y==x*y^2',IVP=False,x0=0,y0=1): eq=sage_eval(eq,locals={'x':x,'y':y}) html('The equation that we try to solve is :') html(pp(eq)) if IVP: html('$y(%s)=%s$'%(x0,y0)) if IVP: phi=desolve(eq,y,ics=[x0,y0], show_method=True, contrib_ode=True) else: phi=desolve(eq,y, show_method=True, contrib_ode=True) html(r'method used was:'+str(phi[1])) html(r'solution found is: '+'$'+latex(phi[0])+'$')
#For second degree #In general, for first degree equations, try x,y=var('x y') y=function('y',x) def pp(eq): p=str(eq).replace('D[0](y)(x)', r'\frac{d y}{d x}') p=p.replace('D[0, 0](y)(x)', r'\frac{d^2y}{dx^2}') p=p.replace('y(x)','y') p=p.replace('*',' ') return '$'+p+'$' @interact def m274(eq='x^2*diff(y,x,2)+y==0',IVP=False,x0=1,y0=1,dy0=1): eq=sage_eval(eq,locals={'x':x,'y':y}) html('The equation that we try to solve is:') html(pp(eq)) if IVP: html('$y(%s)=%s$'%(x0,y0)) html(r"$y'(%s)=%s$"%(x0,dy0)) if IVP: phi=desolve(eq,y,ics=[x0,y0,dy0], show_method=True, contrib_ode=True) else: phi=desolve(eq,y, show_method=True, contrib_ode=True) html('method used was:\n'+str(phi[1])) html('solution given was: '+'$'+latex(phi[0])+'$')
desolve(diff(y,x)+y==x*y^3,y,show_method=True)
[e^(-x)/sqrt(1/2*(2*x + 1)*e^(-2*x) + c), 'bernoulli']