Saltar al contenido principal
LibreTexts Español

39.2: Ejemplo LSF - Modelo Predator Pray

  • Page ID
    115110
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)
    Gato y ratón

    El siguiente ejemplo de datos proviene de Mathematica Stack Exchange y representa algunos datos experimentales time, x e y.

    \[dx = ax - bxy \nonumber \]

    \[dy = -cy + dxy \nonumber \]

    El siguiente código traza los datos

    # (* The first column is time 't', the second column is coordinate 'x', and the last column is coordinate 'y'. *)
    %matplotlib inline
    import matplotlib.pylab as plt
    import numpy as np
    
    data=[[11,45.79,41.4],
          [12,53.03,38.9],[13,64.05,36.78],
          [14,75.4,36.04],[15,90.36,33.78],
          [16,107.14,35.4],[17,127.79,34.68],
          [18,150.77,36.61], [19,179.65,37.71],
          [20,211.82,41.98],[21,249.91,45.72],
          [22,291.31,53.1],[23,334.95,65.44],
          [24,380.67,83.],[25,420.28,108.74],
          [26,445.56,150.01],[27,447.63,205.61],
          [28,414.04,281.6],[29,347.04,364.56],
          [30,265.33,440.3],[31,187.57,489.68],
          [32,128.,512.95],[33,85.25,510.01],
          [34,57.17,491.06],[35,39.96,462.22],
          [36,29.22,430.15],[37,22.3,396.95],
          [38,16.52,364.87],[39,14.41,333.16],
          [40,11.58,304.97],[41,10.41,277.73],
          [42,10.17,253.16],[43,7.86,229.66],
          [44,9.23,209.53],[45,8.22,190.07],
          [46,8.76,173.58],[47,7.9,156.4],
          [48,8.38,143.05],[49,9.53,130.75],
          [50,9.33,117.49],[51,9.72,108.16],
          [52,10.55,98.08],[53,13.05,88.91],
          [54,13.58,82.28],[55,16.31,75.42],
          [56,17.75,69.58],[57,20.11,62.58],
          [58,23.98,59.22],[59,28.51,54.91],
          [60,31.61,49.79],[61,37.13,45.94],
          [62,45.06,43.41],[63,53.4,41.3],
          [64,62.39,40.28],[65,72.89,37.71],
          [66,86.92,36.58],[67,103.32,36.98],
          [68,121.7,36.65],[69,144.86,37.87],
          [70,171.92,39.63],[71,202.51,42.97],
          [72,237.69,46.95],[73,276.77,54.93],
          [74,319.76,64.61],[75,362.05,81.28],
          [76,400.11,105.5],[77,427.79,143.03],
          [78,434.56,192.45],[79,410.31,260.84],
          [80,354.18,339.39],[81,278.49,413.79],
          [82,203.72,466.94],[83,141.06,494.72],
          [84,95.08,499.37],[85,66.76,484.58],
          [86,45.41,460.63],[87,33.13,429.79],
          [88,25.89,398.77],[89,20.51,366.49],
          [90,17.11,336.56],[91,12.69,306.39],
          [92,11.76,279.53],[93,11.22,254.95],
          [94,10.29,233.5],[95,8.82,212.74],
          [96,9.51,193.61],[97,8.69,175.01],
          [98,9.53,160.59],[99,8.68,146.12],[100,10.82,131.85]]
    data = np.array(data)
    t = data[:,0]
    x = data[:,1]
    y = data[:,2]
    plt.scatter(t,x)
    plt.scatter(t,y)
    plt.legend(('prey', 'preditor'))
    plt.xlabel('Time')
    plt.title('Population');
    Hacer esto

    Utilice la Diferenciación Numérica para calcular\(dx\) y\(dy\) desde\(x\) y\(y\). A ver si se puede trazar\(x\),\(dx\) y\(y\),\(dy\) en un par de parcelas. Usa las parcelas para probar y verificar para asegurarte de que tus resultados hagan senes.

    # Put your answer here
    Hacer esto

    Formular dos sistemas lineales (\(Ax=b\)) y resolverlos usando LSF como hicimos en la pre-clase. Usa una para resolver la primera ODE y la segunda para resolver la segunda ODE. Recuerde, estamos tratando de estimar valores para\(a\),\(b\),\(c\),\(d\)

    #Put your answer here.

    Suponiendo que todo funcionó lo siguiente debería trazar el resultado.

    from scipy.integrate import odeint
    # The above ODE model sutiable for ODEINT
    def deriv(position,t,a,b,c,d):
        x = position[0]
        y = position[1]
        dx = a*x - b*x*y
        dy = -c*y + d*x*y
        return (dx,dy)
    
    # Integrate equations over the time grid, t.
    ret = odeint(deriv, (data[0,1],data[0,2]), t, args=(a,b,c,d))
    
    #Plot the model on the data
    plt.plot(t,ret)
    plt.scatter(t, data[:,1])
    plt.scatter(t, data[:,2]);
    plt.legend(('x est', 'y est', 'x', 'y'))
    plt.xlabel('Time');

    This page titled 39.2: Ejemplo LSF - Modelo Predator Pray is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Dirk Colbry via source content that was edited to the style and standards of the LibreTexts platform.