Saltar al contenido principal
LibreTexts Español

9.1: Función Sympy RREF

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

    #  Load Useful Python Libraries
    import numpy as np
    import sympy as sym
    sym.init_printing(use_unicode=True)
    from urllib.request import urlretrieve
    urlretrieve('https://raw.githubusercontent.com/colbrydi/jupytercheck/master/answercheck.py', 
                'answercheck.py');

    En clase hablamos sobre la biblioteca Python sympy que tiene una función de “forma de escalón de fila reducida” (rref) que ejecuta una versión mucho más eficiente de la función Gauss-Jordan. Para usar la función rref primero debes convertir tu matriz en un sympy.matrix y luego ejecutar la función. Por ejemplo, hagamos esto para la siguiente matriz\(B\):

    B = np.matrix([[ 50, 13, 30 ], [100, 26, 60 ],  [20.5, 25, 650]])
    sym.Matrix(B).rref()
    # 'Run' this cell to see the output

    Esta función genera dos valores (una matriz y una tupla). Para los efectos de esta clase sólo nos importa la matriz. Generalmente uso la siguiente sintaxis cuando uso rref ()

    sym.Matrix(B).rref()[0]
    # 'Run' this cell to see the output
    Pregunta

    Aunque no lo usamos a menudo en este curso, ¿qué significa la segunda salida de la rref (es decir, qué significa (0,1)?

    pista: leer la documentación para rref.

    Cómo consideremos el ejemplo de varias semanas de una asignación anterior, donde:

    Semana 1:

    \(c + b = 30\)

    \(20c + 25b = 690\)

    Semana 2:

    \(c + b = 35\)

    \(20c + 25b = 750\)

    Semana 3:

    \(c + b = 30\)

    \(20c + 25b = 650\)

    Hacer esto

    Escribe una matriz\(2 \times 5\) aumentada que represente las 6 ecuaciones anteriores. (puedes simplemente copiar y pegar esto de la pre-clase si lo tienes ahí mismo), Nombra tu Matriz\(G\) para verificar tu respuesta usando la función checkanswer a continuación.

    #Put your answer to the above question here. 

    La siguiente función aplicará la función rref a la matriz\(G\) y la almacenará en una variable llamada, espérala, rref:

    rref,_ = sym.Matrix(G).rref()
    rref
    Pregunta

    Ante lo anterior, ¿Cuántas horas trabajó Giselle como capenter durante las tres semanas y cuántas horas trabajó como herrero? Complete sus respuestas a continuación para verificar si está en lo correcto:

    #Replace the zeros with your answers
    carpenter_week1 = 0
    carpenter_week2 = 0
    carpenter_week3 = 0
    blacksmith_week1 = 0
    blacksmith_week2 = 0
    blacksmith_week3 = 0
    from answercheck import checkanswer
    
    hours = [[carpenter_week1, carpenter_week2, carpenter_week3],
             [blacksmith_week1, blacksmith_week2, blacksmith_week3]]
    hours = np.matrix(hours).astype('float')
    
    checkanswer.matrix(hours,'b2d4a73cac3c95204f5ed743b507093a');

    This page titled 9.1: Función Sympy RREF 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.