0% found this document useful (0 votes)
20 views

Math Programming Examples1

Uploaded by

Yuen Mok
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Math Programming Examples1

Uploaded by

Yuen Mok
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Programming with Mathcad

Defining a function....

Thermostat ( T)  if ( T  23  1  if ( T  25  1  0) )

Using the function:


Thermostat ( 15)  1
Thermostat ( 30)  1

Writing a small program...

Thermo ( T)  RV  0
RV  1 if T  23
RV  1 if T  25

Testing the program:


Thermo ( 20)  1
Thermo ( 24)  0
Thermo ( 30)  1

Using worksheet variables in a program (NOT GOOD):

T  24

Thermos  RV  "unchanged"
RV  1 if T  23
RV  1 if T  25

Thermos  "unchanged" RV  Local variables can not be seen


outside the program
Problem 6.8 IF STATEMENT used to count parts that are outside of a range

 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

countw ( c  1.5  1.99)  3

 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 sk
s

addnumbers ( 5)  15

addnumbers ( 10)  55

addOdds ( n)  s 0
for k  0  n
continue if mod ( k  2)  0
s sk
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

DS ( f  xo)  tol  0.0001


error  1
while error  tol
x  f ( xo)
100
return "Solution not found" if x  10
error  x  xo
xo  x
x

2
x  28
F ( x) 
11

DS ( F  1)  4 DS ( F  0)  4

DS ( F  10)  "Solution not found"

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy