Jephian Lin
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Sage: 矩陣、線性方程組 Sage: Matrices and linear equations ![Creative Commons License](https://i.creativecommons.org/l/by/4.0/88x31.png) This work by Jephian Lin is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/). $\newcommand{\trans}{^\top} \newcommand{\adj}{^{\rm adj}} \newcommand{\cof}{^{\rm cof}} \newcommand{\inp}[2]{\left\langle#1,#2\right\rangle} \newcommand{\dunion}{\mathbin{\dot\cup}} \newcommand{\bzero}{\mathbf{0}} \newcommand{\bone}{\mathbf{1}} \newcommand{\ba}{\mathbf{a}} \newcommand{\bb}{\mathbf{b}} \newcommand{\bc}{\mathbf{c}} \newcommand{\bd}{\mathbf{d}} \newcommand{\be}{\mathbf{e}} \newcommand{\bh}{\mathbf{h}} \newcommand{\bp}{\mathbf{p}} \newcommand{\bq}{\mathbf{q}} \newcommand{\br}{\mathbf{r}} \newcommand{\bx}{\mathbf{x}} \newcommand{\by}{\mathbf{y}} \newcommand{\bz}{\mathbf{z}} \newcommand{\bu}{\mathbf{u}} \newcommand{\bv}{\mathbf{v}} \newcommand{\bw}{\mathbf{w}} \newcommand{\tr}{\operatorname{tr}} \newcommand{\nul}{\operatorname{null}} \newcommand{\rank}{\operatorname{rank}} %\newcommand{\ker}{\operatorname{ker}} \newcommand{\range}{\operatorname{range}} \newcommand{\Col}{\operatorname{Col}} \newcommand{\Row}{\operatorname{Row}} \newcommand{\spec}{\operatorname{spec}} \newcommand{\vspan}{\operatorname{span}} \newcommand{\Vol}{\operatorname{Vol}} \newcommand{\sgn}{\operatorname{sgn}} \newcommand{\idmap}{\operatorname{id}} \newcommand{\am}{\operatorname{am}} \newcommand{\gm}{\operatorname{gm}} \newcommand{\mult}{\operatorname{mult}} \newcommand{\iner}{\operatorname{iner}}$ ## 建構矩陣 Construct a matrix 1. `matrix( list of lists )`:把 `list of lists` 中的每個 `list` 當作矩陣的列。 2. `matrix(r, list)`:把 `list` 切成 `r` 個列。 3. `identity_matrix(n)`:單位矩陣。 4. `zero_matrix(n)` or `zero_matrix(m,n)`:全零矩陣。 利用 `print`(純文字)或 `show`(格式化文字)來顯示矩陣。 <!-- eng start --> 1. `matrix( list of lists )`: return the matrix whose rows are the `lists` in `list of lists` . 2. `matrix(r, list)`: split `list` into `r` rows and return the matrix. 3. `identity_matrix(n)`: the identity matrix. 4. `zero_matrix(n)` or `zero_matrix(m,n)`: the zero matrix. You may use `print` (pure text) or `show` (formatted output) to display the matrix. <!-- eng end --> ```python A = matrix([[1,2,3], [4,5,6]]) print(A) ``` ```python A = matrix(2, [1,2,3,4,5,6]) show(A) ``` ```python A = identity_matrix(3) # A = zero_matrix(3) # A = zero_matrix(3,4) show(A) ``` ## 從矩陣中選取各項或子矩陣 Select an entry or a submatrix from a matrix 若 `A` 是一個矩陣。 1. `A[i,j]`:選取第 `ij` 項。 2. `A[list1, list2]`:選取列在 `list1` 中、行在 `list2` 中的子矩陣。 也可以混合使用﹐如 `A[i, list]` 或 `A[list, j]`。 <!-- eng start --> Suppose `A` is a matrix. 1. `A[i,j]`: return the `ij`-entry. 2. `A[list1, list2]`: return the submatrix induced on rows in `list1` and columns in `list2` . You may mix the two usages, such as `A[i, list]` or `A[list, j]` . <!-- eng end --> ```python A = matrix(2, [1,2,3,4,5,6]) show(A) print(A[0,1]) show(A[[0,1],[1,2]]) ``` 選取子矩陣中 `list` 的可以用 `a:b` 的格式取代。 1. `a:b`:從 `a` 到 `b`(不包含 `b`)。 2. `a:`:從 `a` 到底。 3. `:b`:從頭到 `b`(不包含 `b`)。 4. `:`:全部。 <!-- eng start --> The `list` used for selecting the submatrix can be replaced by `a:b` . 1. `a:b`: from `a` to `b` (excluding `b`). 2. `a:`: from `a` to the end. 3. `:b`: from the beginning to `b`. 4. `:`: all. <!-- eng end --> ```python A = matrix(2, [1,2,3,4,5,6]) show(A[:,1:]) ``` 可以把選出來的子矩陣設定成給定的矩陣。 <!-- eng start --> You may assign new values to the selected submatrix. <!-- eng end --> ```python A = zero_matrix(2,3) show(A) A[0,0] = 100 show(A) A[:,1:] = identity_matrix(2) show(A) ``` ## 求解 Finding the solution(s) 若 `A` 為一矩陣﹐可以用 1. `A.right_kernel()` 或 2. `A.right_kernel().basis_matrix()` 來找到零解的基底。 <!-- eng start --> Let `A` be a matrix. You may use 1. `A.right_kernel()` or 2. `A.right_kernel().basis_matrix()` to find a basis of the homogeneous solutions. <!-- eng end --> ```python A = matrix(2, [1]*6) show(A) print(A.right_kernel()) show(A.right_kernel().basis_matrix()) ``` 可以用 `vector([list])` 來設定向量。 若 `A` 是矩陣而 `b` 是向量﹐ 則 `A \ b` 會給出一組解。 (也可以用 `A.solve_right(b)`。) <!-- eng start --> Use `vector([list])` to construct a vector. If `A` is a matrix and `b` is a vector, then `A \ b` returns a solution. (Equivalently, `A.solve_right(b)` has the same effect.) <!-- eng end --> ```python A = matrix(2, [1]*6) b = vector([1,1]) show(A) print(b) print(A \ b) print(A.solve_right(b)) ``` ## 最簡階梯形式矩陣、增廣矩陣 Reduced echelon form and augmenting matrix 若 `A` 為一矩陣﹐則 `A.rref()` 會回傳其最簡階梯形式矩陣。 <!-- eng start --> Let `A` be a matrix. Then `A.rref()` returns its reduced echelon form. <!-- eng end --> ```python A = matrix(3, list(range(12))) show(A) show(A.rref()) ``` 若 `A` 為一矩陣而 `b` 為一向量﹐則 `A.augment(b)` 會回傳相對應的增廣矩陣。 <!-- eng start --> Let `A` be a matrix and `b` a vector. Then `A.augment(b)` returns their augmenting matrix. <!-- eng end --> ```python A = matrix(3, list(range(12))) b = vector([1,5,9]) Ab = A.augment(b) show(Ab) Ab = A.augment(b, subdivide=True) show(Ab) ``` 可以用以下函數對矩陣(或增廣矩陣)`A` 執行列運算。 1. `A.swap_rows(i,j)` . 2. `A.rescale(i, k)` . 3. `A.add_multiple_of_row(i, j, k)` . 注意這些函數會直接修改矩陣本身而不會回傳任何矩陣。 <!-- eng start --> Apply the row operation to a matrix (or an augmenting matrix) `A` by the following functions. 1. `A.swap_rows(i,j)` . 2. `A.rescale(i, k)` . 3. `A.add_multiple_of_row(i, j, k)` . Notice that these functions update the matrix itself and do not return any matrix. <!-- eng end --> ```python A = matrix(3, list(range(12))) show(A) print(A.swap_rows(0,1)) show(A) ``` ## 反矩陣 Inverse matrix 若 `A` 和 `B` 都是矩陣﹐則 `A.augment(B)` 也可以建立其相對應的增廣矩陣。 藉此可以計算反矩陣。 <!-- eng start --> Let `A` and `B` be matrices. Then `A.augment(B)` also returns the corresponding augmenting matrix. We may use it to compute the inverse. <!-- eng end --> ```python A = matrix([[1,1,1], [1,2,4], [1,3,9]]) I3 = identity_matrix(3) AI = A.augment(I3, subdivide=True) show(AI) IB = AI.rref() show(IB) B = IB[:,3:] show(A * B) ``` 若 `A` 是方陣﹐ 1. `A.is_invertible()` 可以判斷其是否可逆﹐ 2. `A.inverse()` 會求出它的逆矩陣。 <!-- eng start --> Suppose `A` is a square matrix. Then 1. `A.is_invertible()` determines if `A` is invertible, and 2. `A.inverse()` returns the inverse of `A` . <!-- eng end --> ```python A = matrix([[1,1,1], [1,2,4], [1,3,9]]) print(A.is_invertible()) show(A.inverse()) ``` ## 四大基礎子空間的標準基底 The standard bases of the four fundamental subspaces `lingeo` 是為這份教材所寫的函式庫。 其內容包含在 `lingeo.py` 裡。 可以用 ```python from lingeo import random_good_matrix ``` 來匯入須要的函數。 <!-- eng start --> `lingeo` is a library written for LA-notebook. Its content can be found in `lingeo.py` , and you may use the syntax like ```python from lingeo import random_good_matrix ``` to import the necessary functions. <!-- eng end --> ```python from lingeo import random_good_matrix from lingeo import row_space_matrix, column_space_matrix, kernel_matrix, left_kernel_matrix ``` 若 `A` 為一矩陣﹐則 1. `row_space_matrix(A)` 的列是由 $\beta_R$ 組成、 2. `kernel_matrix(A)` 的行是由 $\beta_K$ 組成、 3. `column_space_matrix(A)` 的行是由 $\beta_C$ 組成、 4. `left_kernel_matrix(A)` 的列是由 $\beta_L$ 組成。 <!-- eng start --> Let `A` be a matrix. Then 1. `row_space_matrix(A)` is the matrix whose rows are vectors in $\beta_R$, 2. `kernel_matrix(A)` is the matrix whose columns are vectors in $\beta_K$, 3. `column_space_matrix(A)` is the matrix whose columns are vectors in $\beta_C$, and 4. `left_kernel_matrix(A)` is the matrix whose rows are vectors in $\beta_L$. <!-- eng end --> ```python m,n,r = 3,5,2 A = random_good_matrix(m,n,r) show(A) print("row space matrix:") show(row_space_matrix(A)) print("kernel matrix:") show(kernel_matrix(A)) ``` ```python m,n,r = 3,5,2 A = random_good_matrix(m,n,r) show(A) print("column space matrix:") show(column_space_matrix(A)) print("left kernel matrix:") show(left_kernel_matrix(A)) ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully