Skip to content

Instantly share code, notes, and snippets.

@dsaint31x
Created September 1, 2022 04:43
Show Gist options
  • Save dsaint31x/72fa6d150b869c561eded8f745004913 to your computer and use it in GitHub Desktop.
Save dsaint31x/72fa6d150b869c561eded8f745004913 to your computer and use it in GitHub Desktop.
LA_Ch01_02_Ex03.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyOBs74Cglm03n8f87kNBsl8",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/dsaint31x/72fa6d150b869c561eded8f745004913/la_ch01_02_ex03.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"source": [
"import sympy as sp\n",
"\n",
"def custom_latex_printer(exp, **options):\n",
" from google.colab.output._publish import javascript\n",
" url = \"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=default\"\n",
" javascript(url=url)\n",
" return sp.printing.latex(exp, **options)\n",
"\n",
"sp.init_printing(use_latex=\"mathjax\", latex_printer=custom_latex_printer)"
],
"metadata": {
"id": "Ci5iemI-WHkq"
},
"execution_count": 29,
"outputs": []
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 78
},
"id": "eVLYwK6zE2Gl",
"outputId": "158171ca-4a9c-4b6a-ad66-f8dbfee99559"
},
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"<IPython.core.display.HTML object>"
],
"text/html": [
"<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=default'></script>"
]
},
"metadata": {}
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"⎛⎡1 0 -2.0 3.0 0 -24.0⎤ ⎞\n",
"⎜⎢ ⎥ ⎟\n",
"⎜⎢0 1 -2.0 2.0 0 -7.0 ⎥, (0, 1, 4)⎟\n",
"⎜⎢ ⎥ ⎟\n",
"⎝⎣0 0 0 0 1 4.0 ⎦ ⎠"
],
"text/latex": "$\\displaystyle \\left( \\left[\\begin{matrix}1 & 0 & -2.0 & 3.0 & 0 & -24.0\\\\0 & 1 & -2.0 & 2.0 & 0 & -7.0\\\\0 & 0 & 0 & 0 & 1 & 4.0\\end{matrix}\\right], \\ \\left( 0, \\ 1, \\ 4\\right)\\right)$"
},
"metadata": {},
"execution_count": 30
}
],
"source": [
"import numpy as np\n",
"import sympy as sp\n",
"\n",
"A = np.array([\n",
" [0 , 3, -6, 6, 4,-5],\n",
" [3 ,-7 , 8,-5, 8, 9],\n",
" [3 ,-9 ,12,-9, 6,15]\n",
"], dtype=float)\n",
"\n",
"A = sp.Matrix(A)\n",
"rref_A = A.rref()\n",
"rref_A # rref and pivot columns\n"
]
},
{
"cell_type": "code",
"source": [
"np.array(rref_A[0].tolist(), dtype=float)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "jBGbf72LGAuJ",
"outputId": "0bb4f6aa-39ba-4cb5-8eae-10ce9b69a7ef"
},
"execution_count": 34,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([[ 1., 0., -2., 3., 0., -24.],\n",
" [ 0., 1., -2., 2., 0., -7.],\n",
" [ 0., 0., 0., 0., 1., 4.]])"
]
},
"metadata": {},
"execution_count": 34
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment