MathCAD worksheet 7

advertisement
MathCAD worksheet 7 – Vectors & Matrices
The aim of this worksheet is to introduce you to vectors and matrices in MathCAD.
By the end of the sheet you will know how to:
 Create vectors and matrices
 Perform simple matrix and vector mathematics
 Use matrices to plot and analyse experimental data
This worksheet takes the form of a number of examples which illustrate and introduce
these principles. Work through them all.
Exercise 1 – Creating vectors and matrices and doing simple
maths with them
In this exercise we will create some vectors and matrices, which will then form the basis
for our later investigations.



VA
MA
Start MathCAD and create a new, blank worksheet
Display the Matrix Toolbar by selecting View|Toolbars|Matrix from the menu
Use the [:::] button on the matrix toolbar to create the following matrices:
o The vectors VA and VB are defined with 2 rows and 1 column
o The matrices MA and MB are defined with 2 rows and 2 columns
1
VB
2
1 2
MB
3 4
3
4
5 6
7 8
Simple operators and matrix math
Having created these arrays, we can use them to perform simple matrix maths.
Vectors and matrices may be added or subtracted, if they are of the same size.
VA
VB 
MA MB 
4
VA
6
6
8
10 12
© dpl 2001,3,5
VB 
MB MA 
2
Addition and subtraction of vectors
2
4 4
Addition and subtraction of matrices
4 4
1
PH15720
MathCAD Example Sheet 7
MathCAD enforces rules of matrix maths and will not allow addition of matrices or
vectors of different sizes.
MA VA 
The number of rows and/or columns
in these arrays do not match
MathCAD will allow addition or multiplication of an array by a scalar. In this case the
scalar is added or multiplied by each element of the matrix in turn:
VA
1
2
MA 1 
3
3
VA  3 
MA 3 
6
2 3
Addition of constant
4 5
3 6
Multiplication by scalar
9 12
MathCAD will also calculate the dot products of vectors and matrices, providing the
inner dimensions are compatible…
VA  VB  11
Dot product of 2 vectors
MA MB 
19 22
MA VA 
5
Dot product of 2 matrices
43 50
Dot product of matrix and vector
11
The ‘dot’ operator for matrix multiplication is the same ‘*’ as is used for conventional
multiplication, alternatively you can select the ‘dot product’ operator from the matrix
toolbar.
For practice, create the following arrays and matrices:
3
Vec3DA
4
5
Vec3DB
7
MC
1
7
Vec3DC
11
1.2
3.4
5.6
7.8
9.0
1.2
© dpl 2001,3,5
MD
2
3
0 1
3
5 0
5
ME
9 11 13
1 1
1
2 4
8
3 9 27
4 16 64
2
PH15720
MathCAD Example Sheet 7
Exercise 2 – Statistical functions and arrays
MathCAD has a range of statistical and related functions which operate on arrays.
As a simple example, take the series of measurements of wire diameter you were
introduced to in an earlier laboratory exercise. These can be placed into a vector and the
mean and standard deviation calculated:
2.55
2.5
2.6
2.42
2.31
Diameters
2.53
2.56
2.62
2.28
2.44
2.41
2.49
mean( Diameters)  2.476
stdev( Diameters)  0.103
The mean and stdev functions may be selected from the f(x) dialog box, under the
function category ‘statistics’.
Note that you can add units to a vector. If all elements of a vector have the same units,
the easiest way to do this is to select the entire matrix and multiply it by the appropriate
unit. The units will then propagate through to the answers as shown below:
© dpl 2001,3,5
3
PH15720
MathCAD Example Sheet 7
2.55
2.5
2.6
2.42
2.31
Diameters
2.53
2.56
 mm
2.62
2.28
2.44
2.41
2.49
mean( Diameters)  2.476  10
© dpl 2001,3,5
3
m
stdev( Diameters)  1.029  10
4
4
m
PH15720
MathCAD Example Sheet 7
Assessed Exercise
The following part of the worksheet will form part of your assessment for this module.
You should email it to dpl@aber.ac.uk before midnight on 24/11/2003
Start a blank worksheet and attempt the following two problems.
Problem 1 – Basic statistics
The masses of 12 jars of jam were measured on a production line were measured and the
following masses (in grams) obtained.
457.66
453.27
456.69
451.42
449.82
451.11
454.28
451.93
450.98
456.23
456.79
453.02
Create a vector to hold the masses and use it to calculate the mean and standard deviation
(in grams) of the readings.
Problem 2 – Expansion coefficient of air column
The following table gives the length (in cm) of a column of air a different temperatures.
The temperatures are recorded in K above 0C
Temp Length of
Above 0C column
(K)
(cm)
23
7.1
32
7.3
41
7.5
53
7.8
62
8
71
8.2
87
8.6
99
8.9
Create an input table to hold this data and from this use the column extract operator to
form two vectors with suitable names and units to hold the sets of readings.
Plot the values of length obtained against temperature on a graph. Format these as points.
© dpl 2001,3,5
5
PH15720
MathCAD Example Sheet 7
Calculate the coefficient of expansion () and the ‘zero-temperature’ length of the
column l0, given that the length and temperature are connected by the following formula:
l  l0  (1    T )
You will need to multiply out the formula to see how to derive l0 and  from the slope
and intercept functions applied to the experimental data.
Create a function lPredicted(t) which gives the predicted length of the column at and
temperature, t.
Create a vector holding predicted values for the length
Plot the vector of predicted lengths on the same graph as the experimental points.
© dpl 2001,3,5
6
Download