Saltar al contenido principal
LibreTexts Español

36.3: Aproximación de funciones

  • Page ID
    115523
  • \( \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}\)
    Definición

    Dejar\(C[a,b]\) ser un espacio vectorial de todas las funciones continuas posibles a lo largo del intervalo\([a,b]\) con producto interno:\(\langle f,g \rangle = \int_a^b f(x)g(x) dx.\)

    Ahora dejemos\(f\) ser un elemento de\(C[a,b]\), y\(W\) ser un subespacio de\(C[a,b]\). La función\(g \in W\) tal que\(\int_a^b \left[ f(x) - g(x) \right]^2 dx\) es un mínimo se llama la aproximación de mínimos cuadrados a\(f\).

    La aproximación de mínimos cuadrados a\(f\) en el subespacio se\(W\) puede calcular como la proyección de\(f\) sobre\(W\):

    \[g = proj_Wf \nonumber \]

    Si\(\{g_1, \ldots, g_n\}\) es una base ortonormal para\(W\), podemos reemplazar el producto punto de\(R^n\) por un producto interno del espacio funcional y obtener:

    \[prog_Wf = \langle f,g_1 \rangle g_1 + \ldots + \langle f,g_n \rangle g_n \nonumber \]

    Aproximaciones polinomiales

    Se\(n\) pueden calcular bases ortogonales para todos los polinomios de grado menor o igual a mediante el proceso de ortogonalización Gram-schmidt. Primero comenzamos con los siguientes vectores de base estándar en\(W\)

    \[ \{ 1, x, \ldots, x^n \} \nonumber \]

    El proceso Gram-Schmidt puede ser utilizado para hacer estos vectores ortogonales. Los polinomios resultantes\([−1,1]\) son llamados polinomios de Legendre. Las seis primeras bases polinómicas de Legendre son:

    \[1 \nonumber \]

    \[x \nonumber \]

    \[x^2 -\frac{1}{3} \nonumber \]

    \[x^3 - \frac{3}{5}x \nonumber \]

    \[x^4 - \frac{6}{7}x^2 + \frac{3}{35} \nonumber \]

    \[x^5 - \frac{10}{9}x^3 + \frac{5}{12}x \nonumber \]

    Pregunta

    ¿Cuáles son las aproximaciones lineales de mínimos cuadrados a\(f(x)=e^x\) lo largo del intervalo\([−1,1]\)? En otras palabras, lo que es la proyección\(f\) sobre\(W\), donde\(W\) es un polinomal de primer orden con vectores base\(\{1, x\} (\textit{i.e. } n=1)\).

    (Pista: Se puede dar la respuesta en integrales sin computar las integrales. Tenga en cuenta que los polinomios de Legendre no están normalizados).

    Aquí hay una gráfica de la ecuación\(f(x)=e^x\):

    %matplotlib inline
    import matplotlib.pylab as plt
    import numpy as np
    
    #px = np.linspace(-1,1,100)
    #py = np.exp(px)
    #plt.plot(px,py, color='red');
    import sympy as sym
    from sympy.plotting import plot
    x = sym.symbols('x')
    f = sym.exp(x)
    plot(f,(x,-1,1))

    Podemos usar sympy para calcular la integral. El siguiente código computa la integral definida de\(\int_{-1}^1 e^x dx\). De hecho, sympy también puede calcular la integral indefinida eliminando el intervalo.

    sym.init_printing()
    x = sym.symbols('x')
    sym.integrate('exp(x)',(x, -1, 1))
    #sym.integrate('exp(x)',(x))

    Usa sympy para calcular el polinomio de primer orden que se aproxima a la función\(e^x\). A continuación se calcula la aproximación anterior escrita en sympy:

    g_0 = sym.integrate('exp(x)*1',(x, -1, 1))/sym.integrate('1*1',(x,-1,1))*1
    g_1 = g_0 + sym.integrate('exp(x)*x',(x,-1,1))/sym.integrate('x*x',(x,-1,1))*x
    g_1

    Trazar la función original\(f(x)=e^x\) y su aproximación.

    p2 = plot(f, g_1,(x,-1,1))
    #For fun, I turned this into a function:
    x = sym.symbols('x')
    
    def lsf_poly(f, gb = [1,  x], a =-1, b=1):
        proj = 0
        for g in gb:
    #        print(sym.integrate(g*f,(x,a,b)))
            proj = proj + sym.integrate(g*f,(x,a,b))/sym.integrate(g*g,(x,a,b))*g
        return proj
    
    lsf_poly(sym.exp(x))
    Pregunta

    ¿Cómo sería una aproximación de segundo orden para esta función? ¿Qué tal una aproximación de quinto orden?

    #####Start your code here #####
    x = sym.symbols('x')
    g_2 = 
    g_2
    #####End of your code here#####
    p2 = plot(f, g_2,(x,-1,1))

    This page titled 36.3: Aproximación de funciones 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.