The page you are reading is part of a draft (v2.0) of the "No bullshit guide to math and physics."

The text has since gone through many edits and is now available in print and electronic format. The current edition of the book is v4.0, which is a substantial improvement in terms of content and language (I hired a professional editor) from the draft version.

I'm leaving the old wiki content up for the time being, but I highly engourage you to check out the finished book. You can check out an extended preview here (PDF, 106 pages, 5MB).


from sympy.printing.latex import print_latex from sympy.matrices import * import numpy as np

def ltx(x): return print_latex(x, mat_str='bmatrix',mat_delim=None )

# http://docs.sympy.org/dev/modules/matrices.html

# wikipedia example A = Matrix( np.mat(“1 3 1 4 ; 2 7 3 9 ; 1 5 3 1 ; 1 2 0 8”) )

In [83]: A Out[83]: [1, 3, 1, 4] [0, 1, 1, 1] [0, 2, 2, -3] [0, -1, -1, 4]

In [84]: A.col A.col A.col_del A.col_insert A.col_join A.col_swap A.cols

In [84]: A.col A.col A.col_del A.col_insert A.col_join A.col_swap A.cols

In [84]: A.nullspace() Out[84]: 2] [-1] [ 1] [ 0

In [85]: ltx(A.nullspace()) \begin{bmatrix}\begin{bmatrix}2\\-1\\1\\0\end{bmatrix}\end{bmatrix}

In [86]: A.ro A.row A.row_del A.row_insert A.row_join A.row_swap A.rows

In [86]: A.rref()[0] Out[86]: [1, 0, -2, 0] [0, 1, 1, 0] [0, 0, 0, 1] [0, 0, 0, 0]

In [87]: ltx(A.rref()[0]) \begin{bmatrix}1 & 0 & -2 & 0\\0 & 1 & 1 & 0\\0 & 0 & 0 & 1\\0 & 0 & 0 & 0\end{bmatrix}

In [88]: print “Colspace”; ltx(A[:,0]); ltx(A[:,1]); ltx(A[:,3]); Colspace \begin{bmatrix}1\\0\\0\\0\end{bmatrix} \begin{bmatrix}3\\1\\2\\-1\end{bmatrix} \begin{bmatrix}4\\1\\-3\\4\end{bmatrix}

In [89]: ltx(A.rref()[0][0:2,:]) \begin{bmatrix}1 & 0 & -2 & 0\\0 & 1 & 1 & 0\end{bmatrix}

In [90]: print “Rowspace ”; ltx(A.rref()[0][0,:]); ltx(A.rref()[0][1,:]); ltx(A.rref()[0][2,:]) Rowspace \begin{bmatrix}1 & 0 & -2 & 0\end{bmatrix} \begin{bmatrix}0 & 1 & 1 & 0\end{bmatrix} \begin{bmatrix}0 & 0 & 0 & 1\end{bmatrix}

In [91]: A. A.C A.col_del A.inv A.row A.D A.col_insert A.inverse_ADJ A.row_del A.H A.col_join A.inverse_GE A.row_insert A.LUdecomposition A.col_swap A.inverse_LU A.row_join A.LUdecompositionFF A.cols A.is_lower A.row_swap A.LUdecomposition_Simple A.combine A.is_square A.rows A.LUsolve A.conjugate A.is_symbolic A.rref A.QRdecomposition A.copyin_list A.is_upper A.shape A.QRsolve A.copyin_matrix A.jacobian A.simplify A.T A.cross A.key2ij A.slice2bounds A.add A.delRowCol A.mat A.submatrix A.adjugate A.det A.minorEntry A.subs A.applyfunc A.det_bareis A.minorMatrix A.tolist A.berkowitz A.dot A.multiply A.trace A.berkowitz_charpoly A.eigenvals A.multiply_elementwise A.transpose A.berkowitz_det A.eigenvects A.norm A.vec A.berkowitz_eigenvals A.evalf A.normalized A.vech A.berkowitz_minors A.expand A.nullspace A.zero A.charpoly A.extract A.permuteBkwd A.zeronm A.clone A.eye A.permuteFwd A.zeros A.cofactor A.fill A.print_nonzero A.cofactorMatrix A.get_diag_blocks A.project A.col A.hash A.reshape

In [92]: A.eigenvals() Out[92]: {0: 1, 1: 1, 2: 1, 5: 1}

In [93]: A.eig A.eigenvals A.eigenvects

In [93]: A.eigenvects() Out[93]: [(1, 1, 1] [0] [0] [0), (2, 1, 2] [ 1),

(0, 1, [[ 2]
[-1]
[ 1]
[ 0]]),
 (5, 1, [[3/4]
 [  0]
 [ -1]
 [  1]])]
 In [94]: ltx( A.eigenvects() )
 \begin{bmatrix}\begin{pmatrix}1, & 1, & \begin{bmatrix}\begin{bmatrix}1\\0\\0\\0\end{bmatrix}\end{bmatrix}\end{pmatrix}, & \begin{pmatrix}2, & 1, & \begin{bmatrix}\begin{bmatrix}9\\\frac{3}{2}\\\frac{1}{2}\\1\end{bmatrix}\end{bmatrix}\end{pmatrix}, & \begin{pmatrix}0, & 1, & \begin{bmatrix}\begin{bmatrix}2\\-1\\1\\0\end{bmatrix}\end{bmatrix}\end{pmatrix}, & \begin{pmatrix}5, & 1, & \begin{bmatrix}\begin{bmatrix}\frac{3}{4}\\0\\-1\\1\end{bmatrix}\end{bmatrix}\end{pmatrix}\end{bmatrix}

ROTATION EXAMPLE from sympy import pi from sympy.matrices import rot_axis3

theta = pi/3 rot_axis3(theta) # [ 1/2, sqrt(3)/2, 0] # [-sqrt(3)/2, 1/2, 0] # [ 0, 0, 1]

 
home about buy book