Lecture 03
Lecture 03
"
%
*
' (%)
!
&
&
&
&
&
,-
!&
&
!
(
'
(%)
FunctionName( InputList ) :=
"function statements"
"including controls (if, for, while) if needed"
for i 1 .. 10
"this separate line separates the for loop statements"
"from the rest of the function"
"output variable or vector"
/
,
0 -" &&!
&
$
,, 1 2 #!
!
5
&
&
&
& !
&
&
"
/#/
,,
&
&
&
!
& #
&
/
#
- $
&
3
*
4& "
5$6
78#
&
&
&
&
5&
9
&
! &&
&
&
$<==
7?
;
1
!
1=,
4+
#
&
&
>+ + ,
4 1='%,
4 9>;9%'
&
&
&
&
!
*
&
&
*
&
&
&
Mathcad Basics
23
@
$ )> 4> ;,
A= :>+9 *+4( ,
>4 1= .%'= 4%'= %. A%9,
%B0=. ,
4 :>+9 '%,
4
9>;9%' >9 ,
4 1=*+4( ,
>4 )> 4> +.= 1=4%'=>*%4 =C,
.,
4; *+4( ,
>4
7? <
5&
&
#,
&
&
/
!
!
&
&
&
-1
,E
&
/ 5D
/
!
&
!
/
F
#
*
D
&
' (%)
3
1 8
- G
5&
'
'
&
&
!
!
!
@ !
'
&
&
"
5#
!$
75H I J5!I!H 6
&
K
6
K
! &&
#K
6
7K
!&
5
!
&
,
&
D
! -
&
$)
$(
$(
,.
)
)
&&
!
! & #
"D
&
" D
"
&
"
Mathcad Basics
&
&
$
$
D
!
5
&&
$
"
#! L
$
&&
24
if "condition is true"
"statement 1"
"statement 2"
* D
"
&
&
&
&
"
&
&
Mathcad Basics
25
If Condition II
If Condition III
'
(%)
5
D
D
=5 &
&
&
&
2 64> =6< !
grade ( x) :=
If grade < 60
`F'
,
*"N$
if ( x 90)
out
Mathcad Basics
26
Even if one condition is found true, all other conditions are still checke
=5 &
2 6
G
grade ( x) :=
&
if x 60
if x 70
if x 80
if x 90
=5 &
2 64
4=.
D
&
&
Mathcad Basics
D
D
!
0 -
&
&
&
A
&
"
,
,
5
#
!#
5
-
27
&
6
grade ( x) :=
if x 60
if x 90
=
.
5Q M #
0
&
%
!
&&
&
Mathcad Basics
,
*D
&
#
&&
.
&
&
& "
,
$
&&
28
R
#
&
0 B
&
for
"
* &
&
#,
%
5&
&&
" #
$' (%)
38
$
#
!
&
??
&
&
??
! & #
&
S #T"
6
3 8
&
&&
#
"$ *
for i 1.. 5
5
( &&
&
"$
6
# ##
@#
&
!#
!3
for i 1 .. 5
vector i
i
D
"$
=5 &
" $ &&
6" $
2 6)
'
&
"$
"$
&
(%)
+
"
G
D
&
U
-
#
&F
x :=
s0
i := 0.. 4
for i 0 .. 4
ss+i
x :=
s := 0
x := for i 0 .. 4
ss+i
i
x = 10
Mathcad Basics
x = 10
x= 4
29
=5 &
2 6)
' (%)-
&
&&
sum( n) :=
"E
s0
&
for i 0 .. n
!#
s0
for i begin .. end
ss+i
ss+i
sum( 4) = 10
=5 &
sum( 0 , 4) = 10
2 60 -
sum( 1 , 10) = 55
&
3
,D
&
3 D
&
&
s0
s0
ss+ i
ss+ i
if i < 0
continue
s s + i otherwise
sum( 4 , 4) =
sum( 4 , 4) = 20
&
=5 &
8
5&
&
#
&
2@6%
&
3
,D
&
3 D
,
,
otherwise
if i < 0
6
6
6
Mathcad Basics
&
&
30
'
)
6
6
?
?
38
&?
M ?
?
&
&
&
&
"
3
$
3 8
?
&
E
&
6
=
.
D
D
)
5
#
#
%
;
&
@L
>
&
!
&"
&
&
3
8
#
&
3 8
#
$
0 -
&
'
(%)
75
84
Grades := 23
class ( x) :=
sum 0
96
pass 0
43
fail 0
for i 1 .. length ( x)
pass pass + 1 if x 60
failures := result
sum sum + x
ave
passes := result
sum
length ( x)
average := result
fail
out
pass
ave
failures = 2
"
%
$=5 &
passes = 3
2 6 (
&
%
Mathcad Basics
average = 64.2
&
&
31
&
&# $
6 $
5D
# $+
&
& 4
&
0
P
x
Deflection =
P
(3Lx 2 x3 )
6 EI
Mathcad Basics
32
I := 600
E := 29000
P := 20
BeamDefl( L, NP , E, I , P) :=
L := 20
inc
NP := 10
L
( NP 1)
for i 1 .. NP
x 0 + ( i 1)inc
i
defl
i
P
6 E I
( i)2 (xi)3
3 L x
x
defl
results := BeamDefl( 20, 10, E, I , P)
results =
{10,1}
{10,1}
We've set up the output from the function to contain the two vectors:
x-coordinates and deflections at those coordinates.
They are placed as individual elements in a 2x1 vector.
Note that when we display the contents of 'results',
it tells us that each of the two elements are a 10x1 vector.
Thus 'results' is called a 'data structure'.
The difference is that each element in a data structure can be a vector or matrix,
not just a scalar.
These elements are indexed just like a vector (with a subscript).
In order to display and use the contents of the data structure,
we need to assign a name to each of the elements in the data structure.
xaxis := results
defl := results
defl 0.002
0.004
10
20
xaxis
Mathcad Basics
33
@
.
2
I := 600
E := 29000
P := 20
BeamDefl( L, NP , E, I , P) :=
L := 20
inc
NP := 10
L
( NP 1)
i1
for x 0 , inc .. L
xaxis x
i
defl
i
P
6 E I
3 L x x
ii+ 1
xaxis
defl
{10,1}
{10,1}
2 F
& F
Mathcad Basics
"
34
%
$
&
5
&
&
&
"
K
* K
&
! &
5
K
!
#K
!
&
,!
K K
%(
function ( v , t ) :=
j 1
j
B(
&&
'
( (
&&
)
function ( v , t ) :=
K
6
j1
while
j
) ,
K
% 0
&
K
K
K
#!
&&
!
function ( v , t) :=
j1
while v t
j
j j+ 1
j
Mathcad Basics
35
1
3
x :=
5
7
0 -
3
58
&
/
@W3
3
58
E
"
5#
@$7 3
#
8
function02( v , t) :=
F
j1
for i 1 .. length ( v )
j j + 1 if v t
i
break otherwise
j
function02( x, 4) = 3
FDD +
&
5
'
(%)
&
3 8
6
%
B
5
& 5
#
&
38 . #
&
6
Mathcad Basics
&
5
!
E
#
&&!
&
&
$
&
3
&
3
8
#
8
&
!
&
&
"
38
W
E
&
&
36
function03( v , t) :=
counter 0
j1
while v t
j
counter counter + 1
j j+ 1
counter
function03( x, 4) = 2
3
F
"
&
&
# !
!8 !F,
&
"
5#
O$7
, & 2M
function04( v , t ) :=
/7OW
3
A
counter 0
j 1
while v t
j
counter counter + 1
break if j
length ( v)
j j+ 1
counter
function04( x, 8) = 4
3
B
&
&
3
,D
3
G
8
&
&
'
(%)
&
&
+
K
&
>
!
'
&
&
&
!
&
!
"$ "
&
=5 &
&
"$
Mathcad Basics
&
37
O
&
9
Find_Negative ( vec ) :=
stop 1
location 1
while stop
if vec
list :=
1
location
12
stop 0
location location + 1
result = 5
out_location
6
&
&
,
/
#
E
!
/
&
-
&
5
#
&
/
/
"
B
>
#
&
&
/ X
&
"
5
&
#
D
!
&
-
7 $
#
2
"
5
&
&
! &
#
/
#
=5 &
90
3
<0
out_location location
&
5&
& 0 -
&
$
6,
#4 # #=
&0
M
>
!#
Mathcad Basics
& #
&
!
M
38
"
& 5& &$
M
,
!
&
&
5
"
9
(
! &
"
& 5& &
&#
&
&$
&
&
! Y
M #
&
.
5D 5
P
x
Deflection =
&
Mathcad Basics
P
(3Lx 2 x3 )
6 EI
39
kips := 1000lbf
ksi := 1
kips
2
in
E := 29000ksi
P := 20kips
I := 50in
L := 20in
NP := 10
BeamDefl(L, NP , P , E, I) :=
P L
maxdefl
3 E I
L L 1.05
3
maxdefl
P L
3 E I
i1
inc
L
( NP 1)
for x 0 , inc .. L
xaxis x
i
defl
i
P
6 E I
3 L x x
ii+ 1
xaxis
x_value
defl
0.1
0.002
deflection
deflection0.001
:= BeamDefl( L, NP , P , E, I)
deflection
in
0.2
0.4
x_value
0.6
0.8
0.05
10
20
30
x_value
in
Mathcad Basics
40