LinearAlgebra.mw

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;

Vector[row]([1, 2, 3, 4]), Vector[column]([[5], [4], [3], [1]]), Vector[row]([0, 0, 0, 0, 0]), Vector[column]([[x[1]], [x[2]], [x[3]], [x[4]]]), Vector[row]([0, 1, 1/2*3^(1/2), 1/2*2^(1/2), sin(1/5*Pi...

    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;

Matrix([[1, 3, 5], [2, 4, 6], [3, 5, 7], [4, 6, 8]]), Matrix([[3, 2, 1], [-4, 3, 2], [5, 3, -1], [6, -2, 4]]), Matrix([[x[1], y[1], z[1], 4], [x[2], y[2], z[2], -2], [x[3], y[3], z[3], 1]]), Matrix([[...

   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;

1

z[2]

a[3, 2]

Vector[row]([0, 1, 1/2*3^(1/2), 1/2*2^(1/2), .5877852524])

    We can apply a map to the whole vector or matrix

> Map(exp, v1), Map(x -> x^2, M3);

Vector[row]([exp(1), exp(2), exp(3), exp(4)]), Matrix([[x[1]^2, y[1]^2, z[1]^2, 16], [x[2]^2, y[2]^2, z[2]^2, 4], [x[3]^2, y[3]^2, z[3]^2, 1]])

    Operations with vectors and matrices

> M1 + 2 * M4, v2.v4, M3.M2;

Matrix([[1+2*a[1, 1], 3+2*a[1, 2], 5+2*a[1, 3]], [2+2*a[2, 1], 4+2*a[2, 2], 6+2*a[2, 3]], [3+2*a[3, 1], 5+2*a[3, 2], 7+2*a[3, 3]], [4+2*a[4, 1], 6+2*a[4, 2], 8+2*a[4, 3]]]), 5*x[1]+4*x[2]+3*x[3]+x[4],...

    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]];

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;

Matrix([[2, 0, -1], [-1, 1, 1], [0, 2, 1]]), Vector[column]([[5], [-2], [3]]), Matrix([[2, 0, -1, 5], [-1, 1, 1, -2], [0, 2, 1, 3]]), Matrix([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])

> M5 := Transpose(M1);
GenerateEquations(M5, [x, y, z]); GenerateEquations(M5, [x, y, z, w], <10, -3, 2>);

M5 := Matrix([[1, 2, 3, 4], [3, 4, 5, 6], [5, 6, 7, 8]])

[x+2*y+3*z = 4, 3*x+4*y+5*z = 6, 5*x+6*y+7*z = 8]

[x+2*y+3*z+4*w = 10, 3*x+4*y+5*z+6*w = -3, 5*x+6*y+7*z+8*w = 2]

    Transform matrices to echelon and reduced echelon forms

> GaussianElimination(A1), GaussianElimination(A1, method=FractionFree), ReducedRowEchelonForm(A1);

Matrix([[2, 0, -1, 5], [0, 1, 1/2, 1/2], [0, 0, 0, 2]]), Matrix([[2, 0, -1, 5], [0, 2, 1, 1], [0, 0, 0, 4]]), Matrix([[1, 0, (-1)/2, 0], [0, 1, 1/2, 0], [0, 0, 0, 1]])

> A[1, 2] := h:
GaussianElimination(<A | b>);

Matrix([[2, h, -1, 5], [0, 1+1/2*h, 1/2, 1/2], [0, 0, h/(2+h), (4+3*h)/(2+h)]])

    Solve a linear system given by a matrix

> LinearSolve(A, b);
LinearSolve(A1);

Vector[column]([[(5*h+2)/h], [-2/h], [(4+3*h)/h]])

Error, (in LinearSolve) inconsistent system

> A1[1, 2] := h:
LinearSolve(A, b), LinearSolve(A1);

Vector[column]([[(5*h+2)/h], [-2/h], [(4+3*h)/h]]), Vector[column]([[(5*h+2)/h], [-2/h], [(4+3*h)/h]])

   Use help for more help

> ?LinearAlgebra

>