Bill Knowlton and Wan Kuang ECE and MSE Departments Boise State University

advertisement
Bill Knowlton and Wan Kuang
ECE and MSE Departments
Boise State University
Vectors Module
Vectors are very common in Engineering and science problems. This tutorial will teach you how to use Mathematica to use
vectors.
Vectors are typically lists using { } brackets. Examples: {1,2} or {1,2,3}
Vector addition
Clear@x, y, zD
x = 8x1, x2<
y = 8x3, x4<
x + y H*adding vectors*L
x y H*Dot product of two vectors*L
à <<Calculus`VectorAnalysis`
SetCoordinates[system[names]]
Grad[f]
Div[f]
Curl[f]
Laplacian[f]
8x1, x2<
8x3, x4<
8x1 + x3, x2 + x4<
8x1 x3, x2 x4<
Vector,
load the vector analysis package
specify the coordinate system to be used (Cartesian, Cylindrical, Sp
the names of the coordinates in that system
evaluate the gradient ! f of f in the coordinate system chosen
evaluate the divergence ! × f of the list f
evaluate the curl ! ‰ f of the list f
evaluate the Laplacian !2 f of f
Vectors.nb
2
4 3 -1
5 -9 2
1 1 1
x
y
z
=
9
3
1
The three unknowns can be calculated directly with LinearSolve. LinearSolve works on both numerical and
symbolic matrices, as well as SparseArray objects. For example,
M1 = 884, 3, -1<, 85, -9, 2<, 81, 1, 1<<;
M2 = 889<, 83<, 81<<;
xyzAnswer = LinearSolve@M1, M2D;
Print@"8x,y,z< = ", xyzAnswerD
8x,y,z< = ::
114
67
>, :
25
67
>, :-
72
67
>>
in which, M1 is the coefficient matrix and M2 is a column vector representing the right-hand-side of the equations. Note
that the matrix can also be solved by multiplying the inversion of M1 and M2, however such an approach is far slower and
sometimes inaccurate when the determinant of M1 is small.
We can check the result from LinearSolve by using the Dot product between the two matrices, M1 and
x
y
z
to obtain
M2:
M1.xyzAnswer
889<, 83<, 81<<
It agrees with the value in M2. It is important to remember that LinearSolve will return one of the possible solutions
for underdetermined linear equations however Solve will return a general solution.
Again, we can apply this approach to solve problem 4-14 where the systems of equations is given by:
Cp
T
m + vΑn = -s-pvΑ
vΑm + vΒn = -pvΒ
M1 = 88Cp  T, v Α<, 8v Α, v Β<<;
M2 = 88-s - p v Α<, 8- p v Β<<;
x = LinearSolve@M1, M2D
::
sTΒ
T v Α2 - Cp Β
>, :
-s T Α - p T v Α2 + Cp p Β
T v Α2 - Cp Β
Assuming that Cp = Cv + T v Α2 ‘ Β, the solution simplifies as:
>>
Vectors.nb
3
x . 8Cp ® Cv + T v Α^2  Β<  Simplify H*replace Cp with Cv+TvΑ^2Β*L
::-
sT
Cv
>, :-p +
sTΑ
Cv Β
>>
à Inverse Approach
As mentioned previously, the Inverse Approach is far slower and sometimes inaccurate when the determinant of M1 is
small. However, since this is the approach typically used in mathematics and engineering courses, it is useful to apply it.
We will apply it to several examples.
Given two linear equations:
am+bn=e
&
cm+dn=f
and defining the unknowns, m and n,matrices can be defined:
a b
m
e
M1 = K
O, x = K O and M2 = K O
c d
n
f
The unknowns m & n can then be solved for by using the following matrix methodology:
M1·X = M2
Finding the inverse matrix of M1, which is M1-1 , then we can solve for X :
X = M1-1 · M2
In this example, we use a 3x3 matrices. That is, 3 equations and 3 unknowns.
Clear@a, b, c, d, M1, M2, M3, IM1, x1, x2, x1x2, M2, m,
x
4 3 -1
9 0
M1 = 5 -9 2 ; IM1 = Inverse@M1D; b = y ; M2 = 3 0
z
1 1 1
1 0
PrintA"Inverse of M1, M1-1 = ", MatrixForm@IM1DE
Inverse of M1, M1-1 =
11
4
3
67
3
67
67
13
67
14
-
Solving for X using :
X = M1-1 × M2
We have :
67
-
5
67
1
67
51
67
67
nD
0
0 ;
0
Vectors.nb
4
PrintA"b = M1-1 ×M2 = ", MatrixForm@IM1.M2D, " =
",
MatrixForm@FullSimplify@IM1.M2DDE
114
b = M1-1 ×M2 =
0 0
67
72
-
0 0
67
0 0
67
25
=
0 0
67
72
-
114
0 0
67
25
0 0
67
We can apply this approach to sovle problem Problem 4 14 in DeHoff where 2 x2 matrices are used.
Clear@y, yi, m, n, z, Cp, Cv, mn, Α, Β, v, T, pD
Cp
y=
T
; yi = Inverse@yD; x = K
vΑ
vΑ vΒ
m
-s - p v Α
O; z = K
O;
n
-p v Β
Print@"M1 = ", MatrixForm@yD, ";
X = ", MatrixForm@xD, "; M2 = ",
MatrixForm@zDD
PrintA"M1-1 = ", MatrixForm@yiD, " = ", MatrixForm@FullSimplify@yiDDE
mn = yi.z; Cp = Cv +
T v Α2
Β
;
PrintA"X=M1-1 ×M2 = ", MatrixForm@mnDE
Cp
M1 =
T
vΑ
X = K
;
vΑ vΒ
vΒ
M1-1 =
vΑ
-
Cp v Β
-v2 Α2 +
T
vΑ
Cp v Β
-v2 Α2 +
T
m
-s - p v Α
O; M2 = K
O
n
-p v Β
Cp v Β
-v2 Α2 +
T
Cp
Cp v Β
T -v2 Α2 +
T
p v2 Α Β
-v2 Α2 +
-1
X=M1 ×M2 =
-
T v Α2
v Cv+
Β
-v2 Α2 +
TΑ
T v Α2 -Cp Β
TΑ
v J-T v Α2 +Cp ΒN
Cp
T v Α2 -Cp Β
v H-s-p v ΑL Β
Β
v Cv+
-v2 Α2 +
v Α H-s-p v ΑL
T v Α2
Β
=
+
T
v Cv+
TΒ
-T v Α2 +Cp Β
T v Α2
Β
T
p v Cv+
Β
T
Simplifying X = M1-1 × M2, we have :
T v Α2
Β
v Cv+
T -v2 Α2 +
Β
Β
T v Α2
Β
T
Β
Vectors.nb
5
PrintA"X=M1-1 ×M2 = ", MatrixForm@FullSimplify@mnDDE
X=M1-1 ×M2 =
-
sT
Cv
-p +
sTΑ
Cv Β
Download