Math Programming Examples1
Math Programming Examples1
Defining a function....
Thermostat ( T) if ( T 23 1 if ( T 25 1 0) )
Thermo ( T) RV 0
RV 1 if T 23
RV 1 if T 25
T 24
Thermos RV "unchanged"
RV 1 if T 23
RV 1 if T 25
1
c 2
3
last ( c) 2
countw w wa wb s 0
for i 0 last ( w)
s s 1 if wi wa
s s 1 if wi wb
1.65
1.45
1.72
v
2.01 countw ( v 1.55 1.95) 3
1.55
1.5
Programming Operations
Resultant ( fx fy) Fx
fx
Fy
fy
2 2
FR Fx Fy
Fy
atan
Fx
FR
180
25
400 cos ( 20deg)
V1
34
fx
200 cos ( 45deg) 52
108
400 sin ( 20deg)
fy 12
200 sin ( 45deg)
V2 57
100
363.842
Resultant ( fx fy)
49.88
276.626
Resultant ( V1 V2)
37.657
Using the If Statement
MassofSolids D h
D
R
2
R
Hc
tan
h tan h if h Hc
1 2
Vs
3
1 2 2
Vs R Hc R h Hc otherwise
3
Mass Vs
Vs
Mass
1591.48
MassofSolids ( 12 30 deg 20 21)
31829.65
For Loop in Mathcad
addnumbers ( n) s 0
for k 0 n
s sk
s
addnumbers ( 5) 15
addnumbers ( 10) 55
addOdds ( n) s 0
for k 0 n
continue if mod ( k 2) 0
s sk
s
addOdds ( 5) 9
addOdds ( 10) 25
addelem ( M) s 0
for i 0 ( rows ( M) 1)
for j 0 ( cols ( M) 1)
s s Mi j
s
1 2 3
M 4 5 6
7 8 9
addelem ( M) 45
2 4 6
S
8 10 12
addelem ( S) 42
Problem 6.10
2
x 28
F ( x)
11
DS ( F 1) 4 DS ( F 0) 4