Kristian Hertz
Basics of MathCAD
2009-01-24
Basics of MathCAD by Kristian Hertz
A text is written by prssing " or just by writing,
where the first space makes it a text
A variable is defined by pressing :
You can se the content of a variable using =
A range of variables is defined by using ; giving ...
Press F1 for Help on Commands
Press Ctl G for Greek letters in variables
for example G Ctl G : 5 gives
If you want the number press p Ctl G
If you want a variable with an index press .
2009-01-24
a 3 5
a 15
t 10 11 20
d a
F a
If you want to insert a line press Ctl F9
If you want to remove a line press Ctl F10.
OBS the content is still there but on top of each other
If youu want to delete something use Ctl x or Backspace
Header and footer is made in the Format menu
M
A matrix is made bypressing Ctl M or Insert / Matrix.
The first row or column have number 0.
M2 0 0.4
M0 1 3
x
x e dx
I 6.596 10
If you dont want := but just = in a text then highlight
the definition and right click on it and chose
View Definition as / Equal for example
here 4 8 in this text, and it is still valid outside.
11
12
13
14
15
16
17
18
19
c 8 s
1.3
v 2.236
20
3
2
M 4 2.236
0.4
20
If you want index or power in a text chose Format Text
Subscript or Suprescript for example Gi in m2 is now in a text.
If you want a formula inserted in a text then click on
the place and press Ctl Shft A or Insert / Math Region
forexample here 3 6 in this text, and it is valid outside.
F 0.188 N
2 1.30
4
.4 20
v1 2.236
10
I
0
v M 1
A vector can be made of a column by Ctl 6
10
c a 2
10 20
a 4 m b 3 kg
Units are just multiplied on the variables,
and they are taking part of the calculations
A single number in a vector or a matrix
is got by using the [ button (Alt 8)
for example v[1 or M[2,0
5
3.142
e4 2
Square root is made by \
Power is made by ^
Integral is made by &
3 6
4 8
Kristian Hertz
Basics of MathCAD
2009-01-24
Indata from a file and graphs
0.0 0.2 1.8
At first a variable is defined
Then data are read from the ASCII
file "MCD Basics 1.dat"
(To see the file you may for example
rename it "MCD Basics 1.txt")
A READPRN ( "MCD Basics 1.DAT" )
0.5
0.6
linterp A 0 A 1
Then a function is defined by linear
interpolation between the points (x,y)
WRITEPRN ( "MCD Basics 1.RES" ) A
A matrix can be written to a file by
APPENDPRN ( "MCD Basics 1.RES" ) A
It can be added to a file by
1700
0.4
0.1
A
0.2
0.4
c 1.0 10
0.80
t 0.0 6.0 360.0
7
3
The thermal difussivity is a
a 4.706 10
b c b 1.166 10
c
The opening factor O 0.04 m and the fire load q 300 MJ/m2 enclosing surface.
3 q
td ( q O) 7.80 10
T2 t q O
O
b
2
0.04
1160
td ( q O) 58.5
345 log 8 t 1
td ( q O)
t
Tf t linterp A 0 A 1
60
3.5
20
1 0.04
A graph is made using
Insert / Graph / x-y Plot
The graph can be costumized with
traces, axes etc. by
double left click.
0.989
A READPRN ( "MCD Basics 2.DAT" )
1000
0
T2 t q O
Tf ( t)
360.
500
0
0
100
200
300
400
A part of the sheat can be collapsed by Insert / Area and Format /Area/Collapse or Expand
A page break can be made by Ctl Enter or by Insert / Page Break
Kristian Hertz
Basics of MathCAD
2009-01-24
0.3
4.5
M
7.3
8.1
Solving equations
A system of equations is
defined by a matrix and
a vector.
It is solved by the function
lsolve
0.2
6.6
1.1
1.8 0.3 6.5
9.7 10.9 4.1
2.7 8.7 8.9
res lsolve ( M v)
x 2 1.9 2
A function is defined, which
has roots
0.1
v
0.01
0.001
3.937
2.975
res
0.746
1.952
f ( x) x 5 x 4
40
20
The roots are fined by the function
root between -2 and 0
f ( x)
0
root ( f ( x) x 2 0) 1
20
and between 0 amd 2
root ( f ( x) x 0 2) 0.828
T 0.0 10.0 1000.0
Graph with points
200
400
fc T linterp A 0 A 1 T
Coords
500
1
0
800
And points from a matrix:
y1 Coords
x1 Coords
Inddata from a file: A READPRN ( "MCD Basics 3.DAT" )
The x'es are added to the x-axis
the y's are added to the y-axis,
and the Type of trace 2
is set to Points.
0.4
0.6
0.9
1
0.8
fc ( T) 0.6
y1
0.4
0.2
0
200
400
600
T x1
800
0.7
1000
Kristian Hertz
Basics of MathCAD
2009-01-24
x 0 0.05 10
Linear Regression
A dataset is entered
2
6.2
Data1
2.4
5
3.7
The data are sorted in
by the x-coordinate
3.5
12
Data2 csort ( Data1 0)
5
5.6
7.3
2
2.4
Data2
3.7
5
6.2
3.5
5
7.3
5.6
12
The x- and y-coordinates are made vectors using Ctl 6
x2 Data2 0
y2 Data2 1
3.435
0.975
fit line ( x2 y2)
bf fit0
fit
bf 3.435
The line is then
The least squares line of best fit is found by
The first coordinate (use Alt 8) is the intercept
The other is the slope
af fit1
af 0.975
Lin ( x) af x bf
A coefficient of correlation can be found,
where the close to 1 the better the fit.
corr ( x2 y2) 0.652
15
y2
Lin ( x)
If the data has extreme outliers,
a median-madian
regression might be better
10
5
0
3.804
0.866
med medfit ( x2 y2) med
10
x2 x
Linm ( x) med1 x med0
15
y2
10
Lin ( x)
Linm ( x)
5
x2 x
10
Kristian Hertz
Basics of MathCAD
2009-01-24
5
a 7
9
4
d 1
0
Matrix operations
At first we define some vectors
using Ctl M
A matrix can be formed
using vectors as columns
by the function augment.
G augment ( d e f )
2
b 1
0
2
e 3
0
0
c 3
4
1
f 2
3
4 2 1
G 1 3 2
0 0 3
A long vector can be made
using the function stack
L stack ( a b c)
Or as mentioned above the matrix
can be made directly by Ctl M
4 2 1
M 1 3 2
0
0
3
The determinant (Determinanten)
can be made by | and the name
of the matrix
(The sign | | is got by Alt ccent)
A matrix can be used as any other variable
The scalar product (Skalre produkt)
is got by pressing * between the vectors
The cross product (Krydsprodukt)
is got by pressing Ctl 8 between the vectors
The space product (Rumprodukt)
is then the scalar product of a
vector and the cross product
The space product is also the determinant,
and therefore you can se that r = r1 = h.
h M
5
7
9
2
L 1
0
0
3
4
h 30
6 4 3
z ( x) x 2 z ( M) 3 5 4
2 2 5
k d e
k 11
9
g e f g 6
1
r d g r 30
or
r1 d ( e f ) r1 30
Kristian Hertz
Basics of MathCAD
2009-01-24
1
b 4
1
1
2
3
a 4 5 6
7 8 9
12
a b 30
48
How to treat elements of a matrix
as single numbers
At first we need a couple of matrices
Then we demonstrate the usual
multiplication of matrices
To multiply each element at a time
press Ctl +
or press the sign f ( M)
on the matrix toolbar
(View / Toolbars / Matrix)
2 4
4 6
1 1
13 19
34 52
55 85
1 4 12
( a b) 16 20 36
1 1 0.75
a 1 1.25 1
b
9
7 8
x 2
Programs
A program is got by adding more
lines to an expression by
] (Alt 9) or Add Line from the
Programming toolbar
(View / Toolbars / Programming).
f ( x)
z
y ( x)
The arrow is a local definition, which
is got by { (Alt 7) or from the
Programming toolbar.
g ( x)
f ( x) 9
f ( 3) 16
z 0
for i 1 x
z zi
y ( 5) 15
h ( v) 2 v
z 0
for i 1 2 x
z zi
z
zx1
g ( x)
z 0
for i 1 2 x
z h ( z) i
g ( 5) 3.249 10
g ( 5) 3.249 10
Kristian Hertz
Basics of MathCAD
2009-01-24
A function of several parameters to be altered by a loop.
k 1000
x 6
j 1 2 10
A program is made using ] or
Add Line from prog menu.
A value is assigned by { and a
for loop by Ctrl+
f ( x)
h ( v) 2 v m
g5 6
ii 0 1 5 tii ii 10
B0 0 k
B0 1 2
B3 t
B0 2 g5
Note that a value like x and a
function like h(v) defined
outside can be used in the loop
and that the matrix B is not
defined in advance but get
dimensions to suit the purpose,
but all numbers of
the matrix must have the same
unit.
g7 8
for i 1 2 x
Bi 0 10 i
Bi 1 10 i Bi1 1
Bi 2
h Bi 1
m
B
B
C f ( x)
A vector value can be used
in the loop but not written
as for example
g7
1 103
10
20
C 30
40
50
60
12
24
10
32
64
20
62
124 30
152 304 50
212 424 0
102 204 40
To write a file with the resulting matrix press WRITEPRN("progloop.res") := C
The file name may contain a path WRITEPRN("c:\data\progloop.res") := C
Kristian Hertz
Basics of MathCAD
2009-01-24
A large loop can be generated by defining the loop varable
r 1 2 10
And expressing the result as a vector using the loop variable as index by [r
p0 50
p0 50
pr r 2
pr
-1
2
100
7
14
50
23
pr
34
62
50
The variable can be changed by
another depending on the first
like for example
pr
r
1
50
-1
14
14
23
34
23
47
34
62
47
79
62
98
10
79
10
79
98
tr r 10
-1
47
100
50
p
0
50
50
t
10 98
Then it is not necessary to write the index r any more.
p is now a vector, and a single value can be called by indexing
pressing [3 and written to
p3 7
p for example by p[4.
p4 80
100
Kristian Hertz
Basics of MathCAD
2009-01-24
Statistics
0.6
0.61
1.45
0.75
v 1.30
1.00
0.92
0.92
0.93
x 0.5 0.51 1.5
n length ( v)
n9
mean ( v) 0.9422 or:
0.9422
SD ( x) stdev ( x)
Standard deviation
v0
n
n1
SD ( v) 0.2861 or:
0.2861
n1
(= sqrt of the variance)
Probability density for the normal distribution at xp:
xp 0.8
is:
dnorm xp 1.2324
Cumulative probability of x beeing smaller than xp is:
pnorm xp 0.3095
5 percentile with mean m and standard deviateon s:
qnorm 0.05 0.4717
Cumulative probability with mean 0 and variance 1
cnorm ( 0) 0.5000
xn x
Normalized values
xnp xn xp
pnorm x
1
0.5
0
0.5
xnp 0.497
cnorm xnp 0.3095
1.5
dnorm x
1
x
1.5
Kristian Hertz
Basics of MathCAD
10
2009-01-24