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}}\)

    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; a detailed edit history is available upon request.