Math 22 Fall 2004
Linear Algebra with Applications
Crash Course in Doing Linear Algebra with Maple
September 29, 2004
Load the package for doing Linear Algebra
> | with(LinearAlgebra): |
Column vectors and row vectors
> | v1 := <1|2|3|4>:
v2 := <5,4,3,1>: v3 := Vector[row](5): v4 := Vector(4, symbol = x): v5 := Vector[row](5, i -> sin(Pi / i)): v1, v2, v3, v4, v5; |
Matrix is a row of column vectors or a column of row vectors
> | M1 := <<1,2,3,4> | <3,4,5,6> | <5,6,7,8>>:
M2 := <<3|2|1>, <-4|3|2>, <5|3|-1>, <6|-2|4>>: u1 := Vector(3, symbol = x): u2 := Vector(3, symbol = y): u3 := Vector(3, symbol = z): u4 := Vector([4, -2, 1]): M3 := <u1 | u2 | u3 | u4>: M4 := Matrix(4, 3, symbol = a): M1, M2, M3, M4; |
Elements of vectors and matrices can be accessed by their indices
> | v5[2]; M3[2, 3]; M4[3, 2]; v5[5] := evalf(v5[5]): v5; |
We can apply a map to the whole vector or matrix
> | Map(exp, v1), Map(x -> x^2, M3); |
Operations with vectors and matrices
> | M1 + 2 * M4, v2.v4, M3.M2; |
Conversion from a linear system to a matrix, and back
> | eqsys := [2*x[1] - x[3] = 5, -x[1] + x[2] + x[3] = -2, 2*x[2]+x[3]=3];
vars := [x[1], x[2], x[3]]; |
> | A, b := GenerateMatrix(eqsys, vars):
A1 := GenerateMatrix(eqsys, vars, augmented=true ): A, b, A1, <A|b> - A1; |
> | M5 := Transpose(M1);
GenerateEquations(M5, [x, y, z]); GenerateEquations(M5, [x, y, z, w], <10, -3, 2>); |
Transform matrices to echelon and reduced echelon forms
> | GaussianElimination(A1), GaussianElimination(A1, method=FractionFree), ReducedRowEchelonForm(A1); |
> | A[1, 2] := h:
GaussianElimination(<A | b>); |
Solve a linear system given by a matrix
> | LinearSolve(A, b);
LinearSolve(A1); |
Error, (in LinearSolve) inconsistent system
> | A1[1, 2] := h:
LinearSolve(A, b), LinearSolve(A1); |
Use help for more help
> | ?LinearAlgebra |
> |