12 - EQUACOES-DIFERENCIAIS

559 days ago by jmarcellopereira

EQUAÇÕES DIFERENCIAIS

Equações diferenciais de Primeira Ordem.  desolve(de, dvar, ics=None, ivar=None, show_method=False, contrib_ode=False)

de - an expression or equation representing the ODE

dvar - the dependent variable (hereafter called y)

ics - (optional) the initial or boundary conditions

for a first-order equation, specify the initial x and y
for a second-order equation, specify the initial x, y, and dy/dx, i.e. write [x0,y(x0),y′(x0)]
for a second-order boundary solution, specify initial and final x and y boundary conditions, i.e. write [x0,y(x0),x1,y(x1)].
gives an error if the solution is not SymbolicEquation (as happens for example for a Clairaut equation)
ivar - (optional) the independent variable (hereafter called x), which must be specified if there is more than one independent variable in the equation.

show_method - (optional) if true, then Sage returns pair [solution, method], where method is the string describing the method which has been used to get a solution (Maxima uses the following order for first order equations: linear, separable, exact (including exact with integrating factor), homogeneous, bernoulli, generalized homogeneous) - use carefully in class, see below for the example of the equation which is separable but this property is not recognized by Maxima and the equation is solved as exact.

contrib_ode - (optional) if true, desolve allows to solve Clairaut, Lagrange, Riccati and some other equations. This may take a long time and is thus turned off by default. Initial conditions can be used only if the result is one SymbolicEquation (does not contain a singular solution, for example)

EQUAÇÕES DIFERENCIAIS DE PRIMEIRA ORDEM

Equações Diferenciais de Primeira Ordem Simbólicas

Ex: Resolver a seguinte equação diferencial

y' = 2*x*y

reset()
y = function('y')(x); y
 \newcommand{\Bold}[1]{\mathbf{#1}}y\left(x\right)
edo1 = diff(y, x,1) - 2*x*y == 0 edo1
 \newcommand{\Bold}[1]{\mathbf{#1}}-2 \, x y\left(x\right) + D[0]\left(y\right)\left(x\right) = 0
desolve(edo1,y)
 \newcommand{\Bold}[1]{\mathbf{#1}}C e^{\left(x^{2}\right)}
desolve( diff(y, x,1) - 2*x*y == 0,y)
 \newcommand{\Bold}[1]{\mathbf{#1}}C e^{\left(x^{2}\right)}

Utilizando show_method=true. Sage returns pair [solution, method], where method is the string describing the method which has been used to get a solution (Maxima uses the following order for first order equations: linear, separable, exact (including exact with integrating factor), homogeneous, bernoulli, generalized homogeneous) - use carefully in class, see below for the example of the equation which is separable but this property is not recognized by Maxima and the equation is solved as exact.

desolve(edo1,y,show_method=true);
 \newcommand{\Bold}[1]{\mathbf{#1}}\left[C e^{\left(x^{2}\right)}, \verb|linear|\right]
desolve( diff(y, x,1) - 2*x*y == 0,y,show_method=True)
 \newcommand{\Bold}[1]{\mathbf{#1}}\left[C e^{\left(x^{2}\right)}, \verb|linear|\right]

Equação diferencial com valores iniciais

Ex: Resolver a seguinte equação diferencial no intervalo [0,3], sendo y(0) = 1

y' = x^2 - y

reset()
y = function('y')(x) edo2 = diff(y, x , 1) - 2*x*y == 0 edo2
 \newcommand{\Bold}[1]{\mathbf{#1}}-2 \, x y\left(x\right) + D[0]\left(y\right)\left(x\right) = 0
#edo2 = diff(y, x , 1) - 2*x*y == 0 #ics =[ x0 , y ( x0 )] sol2 = desolve(edo2, y, ics=[0, 1],show_method=true) sol2
 \newcommand{\Bold}[1]{\mathbf{#1}}\left[e^{\left(x^{2}\right)}, \verb|linear|\right]

Mais um exemplo

# ics =[ x0 , y ( x0 )] y = function('y')(x) sol3 = desolve ( diff(y,x,1) == 2*x*y , y , ics =[0 , 1],show_method=true) sol3
 \newcommand{\Bold}[1]{\mathbf{#1}}\left[e^{\left(x^{2}\right)}, \verb|linear|\right]

Gráfico da solução da equação diferencial de primeira ordem

type(sol3); sol3[0];
 \newcommand{\Bold}[1]{\mathbf{#1}}\verb|| \newcommand{\Bold}[1]{\mathbf{#1}}e^{\left(x^{2}\right)}
plot(sol3[0],(x,0,1), figsize = (6,5), gridlines="minor");

Campo de direções

Ex: Resolver a seguinte equação diferencial no intervalo [0,3], sendo y(0) = 1

$y'(x)=f(x,y)$

var('y') plot_campo = plot_slope_field(2*x*y, (x,0,1), (y,0,5)) plot_campo

Resolver a equação diferencial $y'(x)=f(x,y)$

y = function('y')(x) y
 \newcommand{\Bold}[1]{\mathbf{#1}}y\left(x\right)
edoC = diff(y, x , 1) - 2*x*y == 0 solC = desolve(edoC,y) solC
 \newcommand{\Bold}[1]{\mathbf{#1}}C e^{\left(x^{2}\right)}

Alterar o valor de C, para 1 e 2

plot_campo + plot(1*e^(x^2), (x,0,1)) + plot(2*e^(x^2), (x,0,1), color= 'red')

Outra forma

reset() var('x,y')
 \newcommand{\Bold}[1]{\mathbf{#1}}\left(x, y\right)
from sage.calculus.desolvers import desolve_rk4 sol=desolve_rk4( 2*x*y ,y,ics=[0,1],ivar=x,output='slope_field',end_points=[0,1],thickness=2) # não precisa colocar limites para x, o end_point ja faz isso plot(sol); sol

Equação diferencial de primeira ordem numérica

Método de Euler

Este implementa o método de Euler para encontrar numericamente a solução da  EDO na forma  y ' = f ( x , y ) , com  valor inicial y(c) = K . A coluna " X " dos incrementos da tabela de x0 para x1 por h ( de modo ( X1- X0) / h deve ser um número inteiro ) . Na coluna " y " , o novo valor de y é igual a Y - antigo valor , mais a entrada correspondente na última coluna

Ex: Resolver a seguinte equação diferencial no intervalo [0,3], sendo y(0) = 1

y' = 2*x*y

reset()
#from sage.calculus.desolvers import eulers_method #x,y=PolynomialRing(QQ,2,'xy').gens() var ( 'x , y ') # intervalo a = 0 b = 1 # condições iniciais y0 = 1 #passo de h h = 0.1 # função fDif = 2*x*y
eulers_method( fDif , a , y0 , h , b)
  x y h*f(x,y) /home/jmarcellopereira/SageMath/local/lib/python2.7/site-packages/sage/m\ isc/decorators.py:705: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...) See http://trac.sagemath.org/5930 for details. return func(*args, **kwds) 0 1 0.000000000000000 0.100000000000000 1.00000000000000 0.0200000000000000 0.200000000000000 1.02000000000000 0.0408000000000000 0.300000000000000 1.06080000000000 0.0636480000000000 0.400000000000000 1.12444800000000 0.0899558400000000 0.500000000000000 1.21440384000000 0.121440384000000 0.600000000000000 1.33584422400000 0.160301306880000 0.700000000000000 1.49614553088000 0.209460374323200 0.800000000000000 1.70560590520320 0.272896944832512 0.900000000000000 1.97850285003571 0.356130513006428 1.00000000000000 2.33463336304214 0.466926672608428  x y h*f(x,y) /home/jmarcellopereira/SageMath/local/lib/python2.7/site-packages/sage/misc/decorators.py:705: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...) See http://trac.sagemath.org/5930 for details. return func(*args, **kwds) 0 1 0.000000000000000 0.100000000000000 1.00000000000000 0.0200000000000000 0.200000000000000 1.02000000000000 0.0408000000000000 0.300000000000000 1.06080000000000 0.0636480000000000 0.400000000000000 1.12444800000000 0.0899558400000000 0.500000000000000 1.21440384000000 0.121440384000000 0.600000000000000 1.33584422400000 0.160301306880000 0.700000000000000 1.49614553088000 0.209460374323200 0.800000000000000 1.70560590520320 0.272896944832512 0.900000000000000 1.97850285003571 0.356130513006428 1.00000000000000 2.33463336304214 0.466926672608428
# menor h h = 0.01 eulers_method(2*x*y, a , y0 , h , b)
  x y h*f(x,y) 0 1 0.000000000000000 0.0100000000000000 1.00000000000000 0.000200000000000000 0.0200000000000000 1.00020000000000 0.000400080000000000 0.0300000000000000 1.00060008000000 0.000600360048000000 0.0400000000000000 1.00120044004800 0.000800960352038400 0.0500000000000000 1.00200140040004 0.00100200140040004 0.0600000000000000 1.00300340180044 0.00120360408216053 0.0700000000000000 1.00420700588260 0.00140588980823564 0.0800000000000000 1.00561289569083 0.00160898063310534 0.0900000000000000 1.00722187632394 0.00181299937738309 0.100000000000000 1.00903487570132 0.00201806975140265 0.110000000000000 1.01105294545273 0.00222431647999600 0.120000000000000 1.01327726193272 0.00243186542863853 0.130000000000000 1.01570912736136 0.00264084373113954 0.140000000000000 1.01834997109250 0.00285137991905900 0.150000000000000 1.02120135101156 0.00306360405303468 0.160000000000000 1.02426495506459 0.00327764785620670 0.170000000000000 1.02754260292080 0.00349364484993072 0.180000000000000 1.03103624777073 0.00371173049197463 0.190000000000000 1.03474797826271 0.00393204231739828 0.200000000000000 1.03868002058010 0.00415472008232042 0.210000000000000 1.04283474066242 0.00437990591078218 0.220000000000000 1.04721464657321 0.00460774444492211 0.230000000000000 1.05182239101813 0.00483838299868339 0.240000000000000 1.05666077401681 0.00507197171528070 0.250000000000000 1.06173274573209 0.00530866372866047 0.260000000000000 1.06704140946075 0.00554861532919592 0.270000000000000 1.07259002478995 0.00579198613386573 0.280000000000000 1.07838201092382 0.00603893926117337 0.290000000000000 1.08442095018499 0.00628964151107293 0.300000000000000 1.09071059169606 0.00654426355017637 0.310000000000000 1.09725485524624 0.00680298010252668 0.320000000000000 1.10405783534876 0.00706597014623210 0.330000000000000 1.11112380549500 0.00733341711626698 0.340000000000000 1.11845722261126 0.00760550911375659 0.350000000000000 1.12606273172502 0.00788243912207514 0.360000000000000 1.13394517084710 0.00816440523009909 0.370000000000000 1.14210957607719 0.00845161086297124 0.380000000000000 1.15056118694017 0.00874426502074526 0.390000000000000 1.15930545196091 0.00904258252529511 0.400000000000000 1.16834803448621 0.00934678427588965 0.410000000000000 1.17769481876210 0.00965709751384919 0.420000000000000 1.18735191627594 0.00997375609671794 0.430000000000000 1.19732567237266 0.0102970007824049 0.440000000000000 1.20762267315507 0.0106270795237646 0.450000000000000 1.21824975267883 0.0109642477741095 0.460000000000000 1.22921400045294 0.0113087688041671 0.470000000000000 1.24052276925711 0.0116609140310168 0.480000000000000 1.25218368328813 0.0120209633595660 0.490000000000000 1.26420464664769 0.0123892055371474 0.500000000000000 1.27659385218484 0.0127659385218484 0.510000000000000 1.28935979070669 0.0131514698652082 0.520000000000000 1.30251126057190 0.0135461171099477 0.530000000000000 1.31605737768184 0.0139502082034275 0.540000000000000 1.33000758588527 0.0143640819275609 0.550000000000000 1.34437166781283 0.0147880883459412 0.560000000000000 1.35915975615877 0.0152225892689783 0.570000000000000 1.37438234542775 0.0156679587378764 0.580000000000000 1.39005030416563 0.0161245835283213 0.590000000000000 1.40617488769395 0.0165928636747886 0.600000000000000 1.42276775136874 0.0170732130164249 0.610000000000000 1.43984096438516 0.0175660597654990 0.620000000000000 1.45740702415066 0.0180718470994682 0.630000000000000 1.47547887125013 0.0185910337777516 0.640000000000000 1.49406990502788 0.0191240947843569 0.650000000000000 1.51319399981224 0.0196715219975591 0.660000000000000 1.53286552180980 0.0202338248878893 0.670000000000000 1.55309934669769 0.0208115312457490 0.680000000000000 1.57391087794344 0.0214051879400307 0.690000000000000 1.59531606588347 0.0220153617091919 0.700000000000000 1.61733142759266 0.0226426399862972 0.710000000000000 1.63997406757896 0.0232876317596212 0.720000000000000 1.66326169933858 0.0239509684704755 0.730000000000000 1.68721266780905 0.0246333049500122 0.740000000000000 1.71184597275906 0.0253353203968342 0.750000000000000 1.73718129315590 0.0260577193973385 0.760000000000000 1.76323901255324 0.0268012329908092 0.770000000000000 1.79004024554405 0.0275666197813783 0.780000000000000 1.81760686532542 0.0283546670990766 0.790000000000000 1.84596153242450 0.0291661922123071 0.800000000000000 1.87512772463681 0.0300020435941890 0.810000000000000 1.90512976823100 0.0308631022453422 0.820000000000001 1.93599287047634 0.0317502830758120 0.830000000000001 1.96774315355215 0.0326645363489657 0.840000000000001 2.00040768990112 0.0336068491903388 0.850000000000001 2.03401453909146 0.0345782471645548 0.860000000000001 2.06859278625601 0.0355797959236034 0.870000000000001 2.10417258217961 0.0366126029299253 0.880000000000001 2.14078518510954 0.0376778192579279 0.890000000000001 2.17846300436747 0.0387766414777410 0.900000000000001 2.21723964584521 0.0399103136252138 0.910000000000001 2.25714995947042 0.0410801292623617 0.920000000000001 2.29823008873278 0.0422874336326833 0.930000000000001 2.34051752236547 0.0435336259159977 0.940000000000001 2.38405114828147 0.0448201615876916 0.950000000000001 2.42887130986916 0.0461485548875140 0.960000000000001 2.47501986475667 0.0475203814033281 0.970000000000001 2.52254024616000 0.0489372807755040 0.980000000000001 2.57147752693550 0.0504009595279359 0.990000000000001 2.62187848646344 0.0519131940319761 1.00000000000000 2.67379168049542 0.0534758336099083  x y h*f(x,y) 0 1 0.000000000000000 0.0100000000000000 1.00000000000000 0.000200000000000000 0.0200000000000000 1.00020000000000 0.000400080000000000 0.0300000000000000 1.00060008000000 0.000600360048000000 0.0400000000000000 1.00120044004800 0.000800960352038400 0.0500000000000000 1.00200140040004 0.00100200140040004 0.0600000000000000 1.00300340180044 0.00120360408216053 0.0700000000000000 1.00420700588260 0.00140588980823564 0.0800000000000000 1.00561289569083 0.00160898063310534 0.0900000000000000 1.00722187632394 0.00181299937738309 0.100000000000000 1.00903487570132 0.00201806975140265 0.110000000000000 1.01105294545273 0.00222431647999600 0.120000000000000 1.01327726193272 0.00243186542863853 0.130000000000000 1.01570912736136 0.00264084373113954 0.140000000000000 1.01834997109250 0.00285137991905900 0.150000000000000 1.02120135101156 0.00306360405303468 0.160000000000000 1.02426495506459 0.00327764785620670 0.170000000000000 1.02754260292080 0.00349364484993072 0.180000000000000 1.03103624777073 0.00371173049197463 0.190000000000000 1.03474797826271 0.00393204231739828 0.200000000000000 1.03868002058010 0.00415472008232042 0.210000000000000 1.04283474066242 0.00437990591078218 0.220000000000000 1.04721464657321 0.00460774444492211 0.230000000000000 1.05182239101813 0.00483838299868339 0.240000000000000 1.05666077401681 0.00507197171528070 0.250000000000000 1.06173274573209 0.00530866372866047 0.260000000000000 1.06704140946075 0.00554861532919592 0.270000000000000 1.07259002478995 0.00579198613386573 0.280000000000000 1.07838201092382 0.00603893926117337 0.290000000000000 1.08442095018499 0.00628964151107293 0.300000000000000 1.09071059169606 0.00654426355017637 0.310000000000000 1.09725485524624 0.00680298010252668 0.320000000000000 1.10405783534876 0.00706597014623210 0.330000000000000 1.11112380549500 0.00733341711626698 0.340000000000000 1.11845722261126 0.00760550911375659 0.350000000000000 1.12606273172502 0.00788243912207514 0.360000000000000 1.13394517084710 0.00816440523009909 0.370000000000000 1.14210957607719 0.00845161086297124 0.380000000000000 1.15056118694017 0.00874426502074526 0.390000000000000 1.15930545196091 0.00904258252529511 0.400000000000000 1.16834803448621 0.00934678427588965 0.410000000000000 1.17769481876210 0.00965709751384919 0.420000000000000 1.18735191627594 0.00997375609671794 0.430000000000000 1.19732567237266 0.0102970007824049 0.440000000000000 1.20762267315507 0.0106270795237646 0.450000000000000 1.21824975267883 0.0109642477741095 0.460000000000000 1.22921400045294 0.0113087688041671 0.470000000000000 1.24052276925711 0.0116609140310168 0.480000000000000 1.25218368328813 0.0120209633595660 0.490000000000000 1.26420464664769 0.0123892055371474 0.500000000000000 1.27659385218484 0.0127659385218484 0.510000000000000 1.28935979070669 0.0131514698652082 0.520000000000000 1.30251126057190 0.0135461171099477 0.530000000000000 1.31605737768184 0.0139502082034275 0.540000000000000 1.33000758588527 0.0143640819275609 0.550000000000000 1.34437166781283 0.0147880883459412 0.560000000000000 1.35915975615877 0.0152225892689783 0.570000000000000 1.37438234542775 0.0156679587378764 0.580000000000000 1.39005030416563 0.0161245835283213 0.590000000000000 1.40617488769395 0.0165928636747886 0.600000000000000 1.42276775136874 0.0170732130164249 0.610000000000000 1.43984096438516 0.0175660597654990 0.620000000000000 1.45740702415066 0.0180718470994682 0.630000000000000 1.47547887125013 0.0185910337777516 0.640000000000000 1.49406990502788 0.0191240947843569 0.650000000000000 1.51319399981224 0.0196715219975591 0.660000000000000 1.53286552180980 0.0202338248878893 0.670000000000000 1.55309934669769 0.0208115312457490 0.680000000000000 1.57391087794344 0.0214051879400307 0.690000000000000 1.59531606588347 0.0220153617091919 0.700000000000000 1.61733142759266 0.0226426399862972 0.710000000000000 1.63997406757896 0.0232876317596212 0.720000000000000 1.66326169933858 0.0239509684704755 0.730000000000000 1.68721266780905 0.0246333049500122 0.740000000000000 1.71184597275906 0.0253353203968342 0.750000000000000 1.73718129315590 0.0260577193973385 0.760000000000000 1.76323901255324 0.0268012329908092 0.770000000000000 1.79004024554405 0.0275666197813783 0.780000000000000 1.81760686532542 0.0283546670990766 0.790000000000000 1.84596153242450 0.0291661922123071 0.800000000000000 1.87512772463681 0.0300020435941890 0.810000000000000 1.90512976823100 0.0308631022453422 0.820000000000001 1.93599287047634 0.0317502830758120 0.830000000000001 1.96774315355215 0.0326645363489657 0.840000000000001 2.00040768990112 0.0336068491903388 0.850000000000001 2.03401453909146 0.0345782471645548 0.860000000000001 2.06859278625601 0.0355797959236034 0.870000000000001 2.10417258217961 0.0366126029299253 0.880000000000001 2.14078518510954 0.0376778192579279 0.890000000000001 2.17846300436747 0.0387766414777410 0.900000000000001 2.21723964584521 0.0399103136252138 0.910000000000001 2.25714995947042 0.0410801292623617 0.920000000000001 2.29823008873278 0.0422874336326833 0.930000000000001 2.34051752236547 0.0435336259159977 0.940000000000001 2.38405114828147 0.0448201615876916 0.950000000000001 2.42887130986916 0.0461485548875140 0.960000000000001 2.47501986475667 0.0475203814033281 0.970000000000001 2.52254024616000 0.0489372807755040 0.980000000000001 2.57147752693550 0.0504009595279359 0.990000000000001 2.62187848646344 0.0519131940319761 1.00000000000000 2.67379168049542 0.0534758336099083

Método de Newton Interativo

reset() var('x y') @interact def taylor_through_Sage_interaction(df_dx = input_box(default= 2*x*y),h = slider(0.001,0.5,0.001,0.25) ): #x,y=PolynomialRing(QQ,2,"xy").gens() a =0 b =1.08 y0=1 points = eulers_method(df_dx,a,y0,h,b, algorithm = 'none') p = list_plot(points,gridlines="minor") show(p)

Click to the left again to hide and once more to show the dynamic interactive window

Método de Rage-Kutta

reset() var('x,y') #from sage.calculus.desolvers import desolve_rk4
sol=desolve_rk4(2*x*y , y , ics=[0,1] , ivar=x ,end_points=[0,1],step = 0.2) sol
 \newcommand{\Bold}[1]{\mathbf{#1}}\left[\left[0, 1\right], \left[0.2, 1.04081066667\right], \left[0.4, 1.17350953036\right], \left[0.6, 1.43332141103\right], \left[0.8, 1.89644124237\right], \left[1.0, 2.71810702942\right]\right]

EQUAÇÕES DIFERENCIAIS DE SEGUNDA ORDEM

reset()
y = function('y')(x); y
 \newcommand{\Bold}[1]{\mathbf{#1}}y\left(x\right)
edo_2ord = diff(y(x),x,2) - 4*y(x) - x == 0 edo_2ord
 \newcommand{\Bold}[1]{\mathbf{#1}}-x - 4 \, y\left(x\right) + D[0, 0]\left(y\right)\left(x\right) = 0
desolve(edo_2ord , y)
 \newcommand{\Bold}[1]{\mathbf{#1}}K_{1} e^{\left(2 \, x\right)} + K_{2} e^{\left(-2 \, x\right)} - \frac{1}{4} \, x

Equação diferencial de segunda ordem com valores iniciais

edo_2ord = diff(y(x),x,2) - 4*y(x) - x == 0 edo_2ord
 \newcommand{\Bold}[1]{\mathbf{#1}}-x - 4 \, y\left(x\right) + D[0, 0]\left(y\right)\left(x\right) = 0

# ics =[ x0 , y(x0), y'(x0)] sol_2ord = desolve ( edo_2ord , y , ics =[0, 1 , 0],show_method=true) sol_2ord
 \newcommand{\Bold}[1]{\mathbf{#1}}\left[-\frac{1}{4} \, x + \frac{9}{16} \, e^{\left(2 \, x\right)} + \frac{7}{16} \, e^{\left(-2 \, x\right)}, \verb|variationofparameters|\right]

Gráfico da solução da equação diferencial de segunda ordem

type(sol_2ord); sol_2ord[0];
 \newcommand{\Bold}[1]{\mathbf{#1}}\verb|| \newcommand{\Bold}[1]{\mathbf{#1}}-\frac{1}{4} \, x + \frac{9}{16} \, e^{\left(2 \, x\right)} + \frac{7}{16} \, e^{\left(-2 \, x\right)}
plot(sol_2ord[0],(x,0,1), figsize = (6,5), gridlines="minor");

Campo de direções

reset()
y = function('y')(x) y
 \newcommand{\Bold}[1]{\mathbf{#1}}y\left(x\right)
edo_2ord = diff(y(x),x,2) - 4*y(x) - x ==0
 /home/jmarcellopereira/SageMath/local/lib/python2.7/site-packages/sage/a\ ll_notebook.py:3: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...) See http://trac.sagemath.org/5930 for details. """ /home/jmarcellopereira/SageMath/local/lib/python2.7/site-packages/sage/all_notebook.py:3: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...) See http://trac.sagemath.org/5930 for details. """
sol_2ord = desolve(edo_2ord,y, ics=[0,1,0]) sol_2ord; print(sol_2ord)
 \newcommand{\Bold}[1]{\mathbf{#1}}-\frac{1}{4} \, x + \frac{9}{16} \, e^{\left(2 \, x\right)} + \frac{7}{16} \, e^{\left(-2 \, x\right)} -1/4*x + 9/16*e^(2*x) + 7/16*e^(-2*x) -1/4*x + 9/16*e^(2*x) + 7/16*e^(-2*x)
n(sol_2ord(1))
 \newcommand{\Bold}[1]{\mathbf{#1}}3.96555324206451
plot(sol_2ord, (x,0,1), gridlines='minor')
reset() var('x,y')
 \newcommand{\Bold}[1]{\mathbf{#1}}\left(x, y\right)
from sage.calculus.desolvers import desolve_rk4 sol=desolve_rk4(4*y(x) + x ,y,ics=[0,1,0],ivar=x,output='slope_field',end_points=[0,1.1],thickness=2) # não precisa colocar limites para x sol;plot(sol)

Equação diferencial de segunda ordem numérica

reset()

diff(y,x,2) =   4*y(x) +  x

var('x,y') x,y=PolynomialRing(QQ,2,"xy").gens() a = 0 y0 = 7 b = 1 h = 0.1
eulers_method( diff(y,x,2) -4*y - 4 , a , y0 , h , b)
  x y h*f(x,y) 0 7 -3.20000000000000 0.100000000000000 3.80000000000000 -1.92000000000000 0.200000000000000 1.88000000000000 -1.15200000000000 0.300000000000000 0.728000000000000 -0.691200000000000 0.400000000000000 0.0367999999999999 -0.414720000000000 0.500000000000000 -0.377920000000000 -0.248832000000000 0.600000000000000 -0.626752000000000 -0.149299200000000 0.700000000000000 -0.776051200000000 -0.0895795200000000 0.800000000000000 -0.865630720000000 -0.0537477120000000 0.900000000000000 -0.919378432000000 -0.0322486272000000 1.00000000000000 -0.951627059200000 -0.0193491763200000  x y h*f(x,y) 0 7 -3.20000000000000 0.100000000000000 3.80000000000000 -1.92000000000000 0.200000000000000 1.88000000000000 -1.15200000000000 0.300000000000000 0.728000000000000 -0.691200000000000 0.400000000000000 0.0367999999999999 -0.414720000000000 0.500000000000000 -0.377920000000000 -0.248832000000000 0.600000000000000 -0.626752000000000 -0.149299200000000 0.700000000000000 -0.776051200000000 -0.0895795200000000 0.800000000000000 -0.865630720000000 -0.0537477120000000 0.900000000000000 -0.919378432000000 -0.0322486272000000 1.00000000000000 -0.951627059200000 -0.0193491763200000
var('x y') @interact def taylor_through_Sage_interaction(df_dx = input_box(default= diff(y,x,2) -4*y - 4,h = slider(0.001,0.5,0.001,0.25) ): x,y=PolynomialRing(QQ,2,"xy").gens() a =0 y0=7 b =1 points = eulers_method(df_dx,a,y0,h,b, algorithm = 'none') p = list_plot(points,gridlines="minor") show(p)

Click to the left again to hide and once more to show the dynamic interactive window

Range-Kuta 4ordem

reset() var('x,y') from sage.calculus.desolvers import desolve_rk4
sol=desolve_rk4( - diff(y,x,2) + 4*y(x) + x ,y,ics=[0,1,0],ivar=x,end_points=[0,1], step=0.5) # não precisa colocar limites para x sol
 \newcommand{\Bold}[1]{\mathbf{#1}}\left[\left[0, 1\right], \left[0.5, 1.625\right], \left[1.0, 3.5\right]\right]

Sistems de equações diferenciais

t = var('t') x = function('x')(t) y = function('y')(t) de1 = diff(x,t) + y - 1 == 0 de2 = diff(y,t) - x + 1 == 0 desolve_system([de1, de2], [x,y])
 \newcommand{\Bold}[1]{\mathbf{#1}}\left[x\left(t\right) = {\left(x\left(0\right) - 1\right)} \cos\left(t\right) - {\left(y\left(0\right) - 1\right)} \sin\left(t\right) + 1, y\left(t\right) = {\left(y\left(0\right) - 1\right)} \cos\left(t\right) + {\left(x\left(0\right) - 1\right)} \sin\left(t\right) + 1\right]

%%% FIM EQUAÇÕES DIFERENCIAIS %%%