Saltar al contenido principal
LibreTexts Español

8.4: Ejemplo de Ajuste de Curva de Práctica

  • Page ID
    115129
  • \( \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}\)

    Considere el siguiente polinomio con escalares constantes\(a\),\(b\), y\(c\), que cae en el\(xy\) plano -:

    \[f(x) = ax^2 + bx + c \nonumber \]

    Pregunta

    ¿Esta función es lineal? ¿Por qué o por qué no?

    Supongamos que no conocemos los valores de\(a\),\(b\) y\(c\), pero sí sabemos que los puntos (1,2), (-1,12) y (2,3) están en el polinomio. Podemos sustituir los puntos conocidos en la ecuación anterior. Por ejemplo, usando el punto (1,2) obtenemos la siguiente ecuación:

    \[2 = a1^2 + b1 + c \nonumber \]

    \[\text{or} \nonumber \]

    \[2 = a + b + c \nonumber \]

    Pregunta

    Genere dos ecuaciones más sustituyendo los puntos (-1,12) y (2,3) en la ecuación anterior:

    Pregunta

    Si lo hicimos bien, deberíamos tener tres ecuaciones y tres incógnitas (\(a\),\(b\),\(c\)). Obsérvese también que estas ecuaciones son lineales (¿cómo sucedió eso?). Transformar este sistema de ecuaciones en dos matrices\(A\) y\(b\) como hicimos anteriormente.

    #Put your answer to the above question here.
    from urllib.request import urlretrieve
    
    urlretrieve('https://raw.githubusercontent.com/colbrydi/jupytercheck/master/answercheck.py', 
                'answercheck.py');
    from answercheck import checkanswer
    
    checkanswer.matrix(A,'1896041ded9eebf1cba7e04f32dd1069');
    from answercheck import checkanswer
    
    checkanswer.matrix(b,'01e594bb535b4e2f5a04758ff567f918');
    Pregunta

    Escribe el código a resolver para\(x\) (es decir, (\(a\),\(b\),\(c\))) usando numpy.

    #Put your answer to the above question here.
    from answercheck import checkanswer
    
    checkanswer.vector(x,'1dab22f81c2c156e6adca8ea7ee35dd7');
    Pregunta

    Dado el valor de su matriz x derivado en la pregunta anterior, ¿para qué sirven los valores\(a\),\(b\), y\(c\)?

    #Put your answer to the above question here.
    a = 0
    b = 0
    c = 0

    Suponiendo que lo anterior es correcto, el siguiente código imprimirá su polinomio de 2do orden y trazará los puntos originales:

    import numpy as np
    import matplotlib.pylab as plt
    x = np.linspace(-3,3)
    y = a*x**2 + b*x + c
    
    #plot the function. (Transpose is needed to make the data line up).
    plt.plot(x,y.transpose())
    
    #Plot the original points
    plt.scatter(1, 2)
    plt.scatter(-1, 12)
    plt.scatter(2, 3)
    plt.xlabel('x-axis')
    plt.ylabel('y-axis')
    Pregunta

    El siguiente programa está destinado a tomar cuatro puntos como entradas (\(p1\),\(p2\),\(p3\),\(p4\)\( \in R^2 \)) y calcular los coeficientes\(a\),\(b\),\(c\), y\(d\) para que la gráfica de\(f(x) = ax^3 + bx^2 + cx + d\) pase suavemente por los puntos. Pruebe la función con los siguientes puntos (1,2), (-1,6), (2,3), (3,2) como entradas e imprima los valores para\(a\)\(b\),\(c\), y\(d\).

    def fitPoly3(p1,p2,p3,p4):
        A = np.matrix([[p1[0]**3, p1[0]**2, p1[0], 1],
                       [p2[0]**3, p2[0]**2, p2[0], 1],
                       [p3[0]**3, p3[0]**2, p3[0], 1],
                       [p4[0]**3, p4[0]**2, p4[0], 1]])
        
        b = np.matrix([p1[1],p2[1],p3[1],p4[1]]).T
    
        X = np.linalg.solve(A, b)
        a = X[0]
        b = X[1]
        c = X[2]
        d = X[3]
        #Try to put your figure generation code here for the next question 
        #####Start your code here #####
        
        
        #####End of your code here#####       
        return (a,b,c,d)
    #put your answer to the above question here
    Pregunta

    Modificar la función fitpoly3 anterior para generar también una figura de los puntos de entrada y el polinomio resultante en rango x =( -3,3).

    # Put the answer to the above question above or copy and paste the above function and modify it in this cell. 
    Pregunta

    Dale cuatro puntos\(R^2\) de entrada a FitPoly3, ¿siempre hay una solución única? Explica tu respuesta.


    This page titled 8.4: Ejemplo de Ajuste de Curva de Práctica 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.