Anda di halaman 1dari 12

Ecuaciones Diferenciales 1. Introduccin a las ecuaciones diferenciales 1.

1 Definicin y clasificacin de las Ecuaciones Diferenciales Una ED es una ecuacin que contiene las derivadas de una o ms variables dependientes con respecto a una o ms variables independientes. Ejemplos: La 2 ley de Newton
F ma mdv dt

Para el caso de un objeto que cae:

F mg v

mdv dt mg v

Para resolver la ltima ecuacin, necesitamos encontrar una funcin v=v(t) que satisfaga la ecuacin. Por ahora supongamos valores para m = 10kg y = 2kg/s, entonces:

dv dt 9.8 v

Si se le dan valores a v, se obtienen los valores dv/dt ; por ejemplo, si v=40, dv/dt=1.8. Esto significa que la pendiente de la solucin v=v(t) tiene el valor 1.8 en cualquier punto donde v=40. Grficamente, en el plano-tv se muestran segmentos cortos o flechas con pendiente 1.8 en puntos de la lnea v=40. La figura muestra un campo direccional o campo de pendientes y tiene importancia ya que cada segmento de lnea es una lnea tangente a la grfica de una solucin de la ecuacin. Por lo que aunque no se tengan soluciones, es posible dibujar conclusiones cualitativas sobre el comportamiento de las soluciones. Entonces, un valor crtico para el objeto que haga dv/dt =0, es v=59.8=49 m/s; esta solucin es llamada una solucin equilibrio que da un balance entre gravedad y arrastre. La solucin de equilibrio es v(t)=mg/ .

Clasificacin de EDs Tipo EDO: si tiene slo derivadas ordinarias de una o ms variables dependientes con respecto a una sola variable independiente.

EDP: si tiene derivadas parciales de una o ms variables dependientes con respecto a dos o ms variables independientes.

Orden

Linealidad

Los coeficientes dependen de la variable independiente x!

1.2 Concepto de solucin de las Ecuaciones Diferenciales Ordinarias Toda funcin que reduzca la ecuacin a una identidad (al substituirla), es una solucin de la ecuacin.

Familias de soluciones Curva integral, familia de soluciones de un parmetro, familia de soluciones de nparmetros (para n-derivadas en la ecuacin), solucin particular, solucin general. Ratones de campo y bhos Supongamos que los bhos matan 15 ratones por da (450 por mes), y que la medicin se hace cada 0.5 meses, entonces la ecuacin queda:

Si hacemos dp/dt=0, encontramos la solucin equilibrio; si dp/dt es positiva, las soluciones aumentan su valor, de lo contrario disminuyen.

Cookbook / LoktaVolterraTutorial
This example describes how to integrate ODEs with the scipy.integrate module, and how to use the matplotlib module to plot trajectories, direction fields and other information. You can get the source code for this tutorial here: tutorial_lokta-voltera_v4.py .

Presentation of the Lotka-Volterra Model


We will have a look at the Lotka-Volterra model, also known as the predator-prey equations, which is a pair of first order, non-linear, differential equations frequently used to describe the dynamics of biological systems in which two species interact, one a predator and the other its prey. The model was proposed independently by Alfred J. Lotka in 1925 and Vito Volterra in 1926, and can be described by

du/dt = a*u b*u*v dv/dt = -c*v + d*b*u*v


with the following notations:

u: number of preys (for example, rabbits) v: number of predators (for example, foxes) a, b, c, d are constant parameters defining the behavior of the population:

o o o o

a is the natural growing rate of rabbits, when there's no fox b is the natural dying rate of rabbits, due to predation c is the natural dying rate of fox, when there's no rabbit d is the factor describing how many caught rabbits let create a new fox

We will use X=[u, v] to describe the state of both populations. Definition of the equations:
Toggle line numbers

1 2 3 4 5 6 7 8 9 10 11

from numpy import * import pylab as p # Definition of parameters a = 1. b = 0.1 c = 1.5 d = 0.75 def dX_dt(X, t=0): """ Return the growth rate of fox and rabbit populations. """ return array([ a*X[0] b*X[0]*X[1] , -c*X[1] + d*b*X[0]*X[1] ])

Population equilibrium
Before using SciPy to integrate this system, we will have a closer look at position equilibrium. Equilibrium occurs when the growth rate is equal to 0. This gives two fixed points:
Toggle line numbers

1 X_f0 = array([ 0. , 0.]) 2 X_f1 = array([ c/(d*b), a/b]) 3 all(dX_dt(X_f0) == zeros(2) ) and all(dX_dt(X_f1) == zeros(2)) # => True
Stability of the fixed points
Near these two points, the system can be linearized: dX_dt = A_f*X where A is the Jacobian matrix evaluated at the corresponding point. We have to define the Jacobian matrix:
Toggle line numbers

1 def d2X_dt2(X, t=0): 2 """ Return the Jacobian matrix evaluated in X. """ 3 return array([[a -b*X[1], -b*X[0] ], 4 [b*d*X[1] , -c +b*d*X[0]] ])

So near X_f0, which represents the extinction of both species, we have:


Toggle line numbers

1 A_f0 = d2X_dt2(X_f0) 2
Near X_f1, we have:
Toggle line numbers

# >>> array([[ 1. , -0. ], # [ 0. , -1.5]])

Near X_f0, the number of rabbits increase and the population of foxes decrease. The origin is therefore a saddle point.

1 A_f1 = d2X_dt2(X_f1) 2 ]])

# >>> array([[ 0. , -2. # [ 0.75, 0.

],

3 # whose eigenvalues are +/- sqrt(c*a).j: 4 lambda1, lambda2 = linalg.eigvals(A_f1) # >>> (1.22474j, -1.22474j) 5 # They are imaginary numbers. The fox and rabbit populations are periodic as follows from further 6 # analysis. Their period is given by: 7 T_f1 = 2*pi/abs(lambda1) # >>> 5.130199
Integrating the ODE using scipy.integrate
Now we will use the scipy.integrate module to integrate the ODEs. This module offers a method named odeint, which is very easy to use to integrate ODEs:
Toggle line numbers

1 from scipy import integrate 2 t = linspace(0, 15, 1000) # time 3 X0 = array([10, 5]) # initials conditions: 10 rabbits and 5 foxes 4 X, infodict = integrate.odeint(dX_dt, X0, t, full_output=True) 5 infodict['message'] # >>> 'Integration successful.'
infodict is optional, and you can omit the full_output argument if you don't want it. Type "info(odeint)" if you want more information
about odeint inputs and outputs. We can now use Matplotlib to plot the evolution of both populations:
Toggle line numbers

1 2 3 4 5 6 7 8 9 10

rabbits, foxes = X.T f1 = p.figure() p.plot(t, rabbits, 'r-', label='Rabbits') p.plot(t, foxes , 'b-', label='Foxes') p.grid() p.legend(loc='best') p.xlabel('time') p.ylabel('population') p.title('Evolution of fox and rabbit populations') f1.savefig('rabbits_and_foxes_1.png')

The populations are indeed periodic, and their period is close to the value T_f1 that we computed.

Plotting direction fields and trajectories in the phase plane


We will plot some trajectories in a phase plane for different starting points between X_f0 and X_f1. We will use Matplotlib's colormap to define colors for the trajectories. These colormaps are very useful to make nice plots. Have a look at ShowColormaps if you want more information.
Toggle line numbers

1 values = linspace(0.3, 0.9, 5) # position of X0 between X_f0 and X_f1 2 vcolors = p.cm.autumn_r(linspace(0.3, 1., len(values))) # colors for each trajectory 3 4 f2 = p.figure() 5 6 #------------------------------------------------------7 # plot trajectories 8 for v, col in zip(values, vcolors): 9 X0 = v * X_f1 # starting point 10 X = integrate.odeint( dX_dt, X0, t) # we don't need infodict here 11 p.plot( X[:,0], X[:,1], lw=3.5*v, color=col, label='X0=(%.f, %.f)' % ( X0[0], X0[1]) ) 12 13 #------------------------------------------------------14 # define a grid and compute direction at each point 15 ymax = p.ylim(ymin=0)[1] # get axis limits 16 xmax = p.xlim(xmin=0)[1]

17 nb_points = 20 18 19 x = linspace(0, xmax, nb_points) 20 y = linspace(0, ymax, nb_points) 21 22 X1 , Y1 = meshgrid(x, y) # create a grid 23 DX1, DY1 = dX_dt([X1, Y1]) # compute growth rate on the gridt 24 M = (hypot(DX1, DY1)) # Norm of the growth rate 25 M[ M == 0] = 1. # Avoid zero division errors 26 DX1 /= M # Normalize each arrows 27 DY1 /= M 28 29 #------------------------------------------------------30 # Drow direction fields, using matplotlib 's quiver function 31 # I choose to plot normalized arrows and to use colors to give information on 32 # the growth speed 33 p.title('Trajectories and direction fields') 34 Q = p.quiver(X1, Y1, DX1, DY1, M, pivot='mid', cmap=p.cm.jet) 35 p.xlabel('Number of rabbits') 36 p.ylabel('Number of foxes') 37 p.legend() 38 p.grid() 39 p.xlim(0, xmax) 40 p.ylim(0, ymax) 41 f2.savefig('rabbits_and_foxes_2.png')

This graph shows us that changing either the fox or the rabbit population can have an unintuitive effect. If, in order to decrease the number of rabbits, we introduce foxes, this can lead to an increase of rabbits in the long run, depending on the time of intervention.

Plotting contours
We can verify that the function IF defined below remains constant along a trajectory:
Toggle line numbers

1 def IF(X): 2 u, v = X 3 return u**(c/a) * v * exp( -(b/a)*(d*u+v) ) 4 # We will verify that IF remains constant for different trajectories 5 for v in values: 6 X0 = v * X_f1 # starting point 7 X = integrate.odeint( dX_dt, X0, t) 8 I = IF(X.T) # compute IF along the trajectory 9 I_mean = I.mean() 10 delta = 100 * (I.max()-I.min())/I_mean 11 print 'X0=(%2.f,%2.f) => I ~ %.1f |delta = %.3G %%' % (X0[0], X0[1], I_mean, delta) 12 # >>> X0=( 6, 3) => I ~ 20.8 |delta = 6.19E-05 % 13 # X0=( 9, 4) => I ~ 39.4 |delta = 2.67E-05 % 14 # X0=(12, 6) => I ~ 55.7 |delta = 1.82E-05 % 15 # X0=(15, 8) => I ~ 66.8 |delta = 1.12E-05 % 16 # X0=(18, 9) => I ~ 72.4 |delta = 4.68E-06 %
Plotting iso-contours of IF can be a good representation of trajectories, without having to integrate the ODE
Toggle line numbers

1 #-------------------------------------------------------

2 # plot iso contours 3 nb_points = 80 # grid size 4 x = linspace(0, xmax, nb_points) 5 y = linspace(0, ymax, nb_points) 6 X2 , Y2 = meshgrid(x, y) # create the grid 7 Z2 = IF([X2, Y2]) # compute IF on each point 8 f3 = p.figure() 9 CS = p.contourf(X2, Y2, Z2, cmap=p.cm.Purples_r, alpha=0.5) 10 CS2 = p.contour(X2, Y2, Z2, colors='black', linewidths=2. ) 11 p.clabel(CS2, inline=1, fontsize=16, fmt='%.f') 12 p.grid() 13 p.xlabel('Number of rabbits') 14 p.ylabel('Number of foxes') 15 p.ylim(1, ymax) 16 p.xlim(1, xmax) 17 p.title('IF contours') 18 f3.savefig('rabbits_and_foxes_3.png') 19 p.show()

Para resolver la ecuacin

necesitamos encontrar funciones p(t) que al ser sustituidas en la ecuacin, la reduzcan a una identidad; la ecuacin se puede reescribir como:

o Por la regla de la cadena tenemos que: Integrando

(para p900)

Tomando el exponencial a ambos lados: Finalmente o

donde c eC es una constante arbitraria. La funcin constante p=900 es tambin una solucin de la ecuacin considerando que c=0. Para diferentes valores de c, la solucin tiene la forma:

donde el carcter se infiere de:

En este caso encontramos soluciones infinitas con infinitos valores de c, esto es tpico al resolver una ecuacin diferencial; el proceso incluye integracin, lo cual hace aparecer una constante arbitraria. Si requerimos de una solucin especfica, segn el punto de operacin por el cual requerimos pase la solucin, tenemos por ejemplo para t = 0: p(0)=850 850=900+c entonces c =-50 y tenemos la solucin deseada:

Lo anterior reflej el uso de una condicin inicial, lo cual mostr el problema del valor inicial. De forma general podemos tener: con la condicin inicial y(0)=y0. Resolviendo el problema de la misma forma para a0 y yb/a, tenemos: Integrando Tomando la exponencial a ambos lados encontramos la solucin general:

donde c eC es arbitraria. Para c=0 tenemos la solucin equilibrio y=b/a. La condicin inicial requiere que c y0 b a , por lo que la solucin para el valor inicial es: La representacin geomtrica de la solucin general es una familia infinita de curvas llamadas curvas integrales donde cada curva est asociada con un valor especfico de c. La satisfaccin de una condicin inicial equivale a identificar la curva integral que pasa a travs del punto inicial dado. En el caso de la poblacin de ratones, se requiere slo sustituir a por el ritmo de crecimiento r y b por el ritmo de depredacin k. La solucin queda entonces,

1.3 Uso de Modelos con Ecuaciones Diferenciales Lineales y no Lineales 2. Ecuaciones diferenciales ordinarias de 1er orden 2.1 Definicin y solucin de ED de variables separables 2.2 Definicin y solucin de EDO con coeficientes homogneos 2.3 Definicin y solucin de EDO exactas 2.4 Definicin y solucin de EDO lineales de 1er orden 2.5 Definicin y solucin de EDO de Bernoulli y Ricatti Primer parcial

Anda mungkin juga menyukai