Open in CoCalc with one click!
sage: y = function('y')(x) sage: fig1 = plot(desolve(diff(y,x)+2*y==9,y,[0,-2]),x,[0,1.5], color='black') sage: fig2 = plot(desolve(diff(y,x)+2*y==9,y,[0,-1]),x,[0,1.5], color='blue') sage: fig3 = plot(desolve(diff(y,x)+2*y==9,y,[0,0]),x,[0,1.5], color='red') sage: fig4 = plot(desolve(diff(y,x)+2*y==9,y,[0,1]),x,[0,1.5], color='green') sage: f(x,y) = (1, 9 - 2*y) sage: fig5 = plot_vector_field(f,(x,0,1.5),(y,-2,4),figsize=[6,6], ticks=[[0,0.5,1,1.5],[-1,-2,0,1]], color='gray') sage: show(fig1+fig2+fig3+fig4+fig5,frame=False,aspect_ratio=0.15)
sage: y = function('y')(x) sage: fig1 = plot(desolve(diff(y,x)+2*y==9,y,[0,-2]),x,[0,1.5], color='gray') sage: fig2 = plot(desolve(diff(y,x)+2*y==9,y,[0,-1]),x,[0,1.5], color='blue') sage: fig3 = plot(desolve(diff(y,x)+2*y==9,y,[0,0]),x,[0,1.5], color='red') sage: fig4 = plot(desolve(diff(y,x)+2*y==9,y,[0,1]),x,[0,1.5], color='green') sage: f(x,y) = (1, 9 - 2*y) sage: fig5 = plot_vector_field(f,(x,0, 0.5,1.5),(y,-2,4),figsize=[6,6], ticks=[[0,0.5,1,1.5],[-1,-2,0,1]]) sage: show(fig1 + fig2 + fig3 + fig4 + fig5, frame = False, aspect_ratio=0.15)
sage: y = function('y')(x) sage: fig1 = plot(desolve(diff(y,x)+2*y==9,y,[0,-2]),x,[0,1.5], color='gray', thickness=1) sage: fig2 = plot(desolve(diff(y,x)+2*y==9,y,[0,-1]),x,[0,1.5], color='blue',thickness=2) sage: fig3 = plot(desolve(diff(y,x)+2*y==9,y,[0,0]),x,[0,1.5], color='red',thickness=3) sage: fig4 = plot(desolve(diff(y,x)+2*y==9,y,[0,1]),x,[0,1.5], color='green', thickness=4) sage: f(x,y) = (1, 9 - 2*y) sage: fig5 = plot_vector_field(f,(x,0,1.5),(y,-2,4),figsize=[6,6], ticks=[[-1,0,1,2],[-1,-2,0,1,2]]) sage: show(fig1 + fig2 + fig3 + fig4 + fig5, frame = False )
sage: y = function('y')(x) sage: fig1 = plot(desolve(diff(y,x)+2*y==9,y,[0,6]),x,[0,1.5], color='green') sage: fig2 = plot(desolve(diff(y,x)+2*y==9,y,[0,4.5]),x,[0,1.5], color='blue') sage: fig3 = plot(desolve(diff(y,x)+2*y==9,y,[0,0]),x,[0,1.5], color='red') sage: f(x,y) = (1, 9 - 2*y) sage: z,w=var('z,w') sage: fig4=plot_slope_field( 9-2*w, (z,0.1,1.5), (w,0,6),figsize=[6,6], ticks=[[0,1,2],[0.0,4.5,6]], color='gray') sage: show(fig1 + fig2 + fig3 + fig4, frame = False , aspect_ratio=0.17)
sage: x, y = polygens(QQ,'x, y') sage: fig1 = list_plot(eulers_method(y, 0, 1, 1/3, 5, algorithm = 'none'), marker = 's') sage: fig2 = list_plot(eulers_method(y, 0, 1, 1/10, 5, algorithm = 'none'), marker = 'x') sage: fig3 = list_plot(eulers_method(y, 0, 1, 1/25, 5, algorithm = 'none'), marker = 'o') sage: t = var('t'); z = function('z')(t) sage: fig4 = plot(desolve(diff(z, t) == z, z, [0, 1]), t, [0.5, 5]) sage: show(fig1 + fig2 + fig3 + fig4, figsize=[6,3])
scatter_plot
sage: var('s,t') sage: y=function('y')(t) sage: eq=diff(y,t,2)+4*diff(y,t)+5*y==(exp(-3*t))*cos(t) sage: eq.laplace(t,s)
(s, t) s^2*laplace(y(t), t, s) + 4*s*laplace(y(t), t, s) - s*y(0) + 5*laplace(y(t), t, s) - 4*y(0) - D[0](y)(0) == (s + 3)/(s^2 + 6*s + 10)
_
s^2*laplace(y(t), t, s) + 4*s*laplace(y(t), t, s) - s*y(0) + 5*laplace(y(t), t, s) - 4*y(0) - D[0](y)(0) == (s + 3)/(s^2 + 6*s + 10)
_.subs(y(0)=2, D[0](y)(0)=1)
Error in lines 1-1 Traceback (most recent call last): File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 995, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "<string>", line 1 SyntaxError: keyword can't be an expression
eq2 = s^2*laplace(y(t), t, s) + 4*s*laplace(y(t), t, s) - s*y(0) + 5*laplace(y(t), t, s) - 4*y(0) - D[0](y)(0) == (s + 3)/(s^2 + 6*s + 10)
sage: eq2=s^2*laplace(y(t), t, s) + 4*s*laplace(y(t), t, s) - s*2 + 5*laplace(y(t), t, s) - 4*2 -1 == (s + 3)/(s^2 + 6*s + 10) sage: sol = solve(eq2,laplace(y(t), t, s)); show(sol)
[L(y(t),t,s)=2s3+21s2+75s+93s4+10s3+39s2+70s+50\displaystyle \mathcal{L}\left(y\left(t\right), t, s\right) = \frac{2 \, s^{3} + 21 \, s^{2} + 75 \, s + 93}{s^{4} + 10 \, s^{3} + 39 \, s^{2} + 70 \, s + 50}]
_
s^2*laplace(y(t), t, s) + 4*s*laplace(y(t), t, s) - s*y(0) + 5*laplace(y(t), t, s) - 4*y(0) - D[0](y)(0) == (s + 3)/(s^2 + 6*s + 10)
sage: t=var('t');y=function('y')(t) sage: show(desolve_laplace(diff(y,t,2)+4*diff(y,t)+5*y== (e^(-3*t))*cos(t),y))
15((5y(0)1)cos(t)+(10y(0)+5D0(y)(0)+3)sin(t))e(2t)+15(cos(t)2sin(t))e(3t)\displaystyle \frac{1}{5} \, {\left({\left(5 \, y\left(0\right) - 1\right)} \cos\left(t\right) + {\left(10 \, y\left(0\right) + 5 \, \mathrm{D}_{0}\left(y\right)\left(0\right) + 3\right)} \sin\left(t\right)\right)} e^{\left(-2 \, t\right)} + \frac{1}{5} \, {\left(\cos\left(t\right) - 2 \, \sin\left(t\right)\right)} e^{\left(-3 \, t\right)}
sage: t=var('t'); y=function('y')(t) sage: show(desolve_laplace(diff(y,t,2)+4*diff(y,t)+5*y== (exp(-3*t))*cos(t),y,[0,2,1]))
15(9cos(t)+28sin(t))e(2t)+15(cos(t)2sin(t))e(3t)\displaystyle \frac{1}{5} \, {\left(9 \, \cos\left(t\right) + 28 \, \sin\left(t\right)\right)} e^{\left(-2 \, t\right)} + \frac{1}{5} \, {\left(\cos\left(t\right) - 2 \, \sin\left(t\right)\right)} e^{\left(-3 \, t\right)}
sage: t,r,k=var('t,r,k') sage: y=function('y')(t) sage: show(desolve_laplace(diff(y,t)==r*y*(1-(y/k)),y,ivar=t))
L1(rL(y(t)2,t,g13120)ky(0)g13120kkr,g13120,t)\displaystyle \mathcal{L}^{-1}\left(-\frac{r \mathcal{L}\left(y\left(t\right)^{2}, t, g_{13120}\right) - k y\left(0\right)}{g_{13120} k - k r}, g_{13120}, t\right)
var('t s')
(t, s)
sage: y=function('y')(t) sage: show((diff(y,t,2)+4*y).laplace(t,s))
s2L(y(t),t,s)sy(0)+4L(y(t),t,s)D0(y)(0)\displaystyle s^{2} \mathcal{L}\left(y\left(t\right), t, s\right) - s y\left(0\right) + 4 \, \mathcal{L}\left(y\left(t\right), t, s\right) - \mathrm{D}_{0}\left(y\right)\left(0\right)
sage: s,t = var('s,t') sage: g = piecewise([[(-infinity,5),0],[[5,10],(t-5)/5],[(10,infinity),1]]);g
piecewise(t|-->0 on (-oo, 5), t|-->1/5*t - 1 on [5, 10], t|-->1 on (10, +oo); t)
sage: eq = s^2*laplace(y(t), t, s) + 4*laplace(y(t), t, s)==g.laplace(t,s) sage: show(eq)
s2L(y(t),t,s)+4L(y(t),t,s)=(5s+1)e(10s)5s2+e(10s)s+e(5s)5s2\displaystyle s^{2} \mathcal{L}\left(y\left(t\right), t, s\right) + 4 \, \mathcal{L}\left(y\left(t\right), t, s\right) = -\frac{{\left(5 \, s + 1\right)} e^{\left(-10 \, s\right)}}{5 \, s^{2}} + \frac{e^{\left(-10 \, s\right)}}{s} + \frac{e^{\left(-5 \, s\right)}}{5 \, s^{2}}
show(solve(eq,laplace(y(t), t, s)))
[L(y(t),t,s)=(e(5s)1)e(10s)5(s4+4s2)\displaystyle \mathcal{L}\left(y\left(t\right), t, s\right) = \frac{{\left(e^{\left(5 \, s\right)} - 1\right)} e^{\left(-10 \, s\right)}}{5 \, {\left(s^{4} + 4 \, s^{2}\right)}}]
sage: y=function('y')(x) sage: sol = desolve(diff(y,x)+2*y==9,y,[0,1]) sage: fig1=plot(sol,x,[-0.5,1]) sage: f(x,y)=(1,9-2*y) sage: fig2=plot_vector_field(f, (x,-0.6,1), (y,-5,4), color='gray') sage: show(fig1 + fig2, aspect_ratio = 0.11, axes=False)
sage: t=var('t'); x=function('x')(t); y=function('y')(t) sage: desolve_system([diff(x,t) == -y,diff(y,t)==x],[x,y])
[x(t) == cos(t)*x(0) - sin(t)*y(0), y(t) == sin(t)*x(0) + cos(t)*y(0)]
sage: sol=desolve_system([diff(x,t)==y,diff(y,t)==-x],[x,y],[0,1,0]); sage: solx=sol[0].rhs();soly=sol[1].rhs() sage: parametric_plot3d((t,solx,soly),(0,2*pi))
3D rendering not yet implemented
sage: t=var('t') sage: x,y=function('x')(t),function('y')(t) sage: desolve_system([diff(x,t)==-y,diff(y,t)==x],[x,y],[0,1,0])
[x(t) == cos(t), y(t) == sin(t)]
sage: sol=desolve_system([diff(x,t)==-y,diff(y,t)==x],[x,y],[0,1,0]) sage: solx=sol[0].rhs();soly=sol[1].rhs() sage: p1 = parametric_plot((solx,soly),(0,2*pi)) sage: p2=plot(solx,t,(0,4*pi));p3 = plot(soly,t,(0,4*pi), color='green') sage: G = graphics_array([p1,p2+p3]) sage: G.show(figsize=[10,3])
G = graphics_array([p1,p2+p3])
G.show(figsize=[10,3])
G.show(figsize=[10,3])
sage: sol=desolve_system([diff(x,t)==y,diff(y,t)==-x],[x,y],[0,1,0]) sage: solx=sol[0].rhs();soly=sol[1].rhs() sage: parametric_plot3d((t,solx,soly),(0,4*pi), thickness=3, aspect_ratio=(0.25,1,1))
sage: x,y=PolynomialRing(QQ,2,"xy").gens()
sage: x,y = polygens(QQ, 'x,y') sage: eulers_method(9-2*y,0,1,1/3,2,algorithm='none')
[[0, 1], [1/3, 10/3], [2/3, 37/9], [1, 118/27], [4/3, 361/81], [5/3, 1090/243], [2, 3277/729], [7/3, 9838/2187]]
sage: pts=_ sage: fig1=list_plot(pts);fig2=line(pts, linestyle='--') sage: t=var('t');z=function('z')(t) sage: fig3=plot(desolve(diff(z,t)==9-2*z,z,[0,1]),t,[0,7/3]) sage: show(fig1+fig2+fig3)
desolve_laplace?
File: /projects/sage/sage-7.5/local/lib/python2.7/site-packages/sage/calculus/desolvers.py Signature : desolve_laplace(de, dvar, ics=None, ivar=None) Docstring : Solve an ODE using Laplace transforms. Initial conditions are optional. INPUT: * "de" - a lambda expression representing the ODE (eg, de = diff(y,x,2) == diff(y,x)+sin(x)) * "dvar" - the dependent variable (eg y) * "ivar" - (optional) the independent variable (hereafter called x), which must be specified if there is more than one independent variable in the equation. * "ics" - a list of numbers representing initial conditions, (eg, f(0)=1, f'(0)=2 is ics = [0,1,2]) OUTPUT: Solution of the ODE as symbolic expression EXAMPLES: sage: u=function('u')(x) sage: eq = diff(u,x) - exp(-x) - u == 0 sage: desolve_laplace(eq,u) 1/2*(2*u(0) + 1)*e^x - 1/2*e^(-x) We can use initial conditions: sage: desolve_laplace(eq,u,ics=[0,3]) -1/2*e^(-x) + 7/2*e^x The initial conditions do not persist in the system (as they persisted in previous versions): sage: desolve_laplace(eq,u) 1/2*(2*u(0) + 1)*e^x - 1/2*e^(-x) sage: f=function('f')(x) sage: eq = diff(f,x) + f == 0 sage: desolve_laplace(eq,f,[0,1]) e^(-x) sage: x = var('x') sage: f = function('f')(x) sage: de = diff(f,x,x) - 2*diff(f,x) + f sage: desolve_laplace(de,f) -x*e^x*f(0) + x*e^x*D[0](f)(0) + e^x*f(0) sage: desolve_laplace(de,f,ics=[0,1,2]) x*e^x + e^x AUTHORS: * David Joyner (1-2006,8-2007) * Robert Marik (10-2009)
sage: t = var('t') sage: psi = function('psi',t) sage: a = 3 * diff(psi)^2 - 2 * diff(psi) + 1 sage: show(a)
3tψ(t)22tψ(t)+1\displaystyle 3 \, \frac{\partial}{\partial t}\psi\left(t\right)^{2} - 2 \, \frac{\partial}{\partial t}\psi\left(t\right) + 1
sage: a.substitute(diff(psi)==t)
3*t^2 - 2*t + 1