Title: EGR 106 Project Intro While Loop
1EGR 106 Project Intro / While Loop
- Project description
- Project schedule
- Background information / terminology
- A simple example
- Examples of similar programs
- While loop
2Project Description
- Working in teams of approx. four students, each
team is to develop a Matlab program that can be
used to design a lightweight truss structure - The code shall allow the designer to evaluate
alternative designs quickly and easily - The actual truss analysis will be performed by
the Matlab function truss_analysis.m to be
provided by the instructor.
3Project Description (cont.)
- The program developed by each team shall provide
a user-friendly interface for both data input and
interpretation of results - Each teams code will be used in a design
competition in which each team will be given 1
hour to develop a truss design for a particular
load scenario - The team will then construct their design from
balsa wood (required construction materials will
be provided)
4Project Schedule (tentative)
3/27 (T) Project Introduction 3/29 (R) Quiz
2 make up / Team assignment 1 4/3 (T) Lecture
Analysis of Trusses / Graphical Interface 4/5
(R) Project work / Team assignment 2 4/10
(T) Lecture Analysis of Trusses / Graphical
Interface 4/12 (R) Quiz 3 / Project work 4/17
(T) Project work 4/19 (R) In-class design
competition 4/24 (T) Quiz 4 / Model
testing 4/26 (R) Project Presentations /
Demonstrations 5/1 (T) Written reports due
5Background Truss Structures
- Definition A planar truss is a structure
composed of slender members joined together at
their end points (called joints).
Photo Engineering Mechanics Statics, by R. C.
Hibbeler
6Terminology Truss Structures
7Terminology (cont.)
- Trusses are supported at certain joints at which
motion is constrained either in the x- direction,
y-direction or both the x- and y-directions.
These supports are also called boundary
conditions.
X Y displacement0 X - displacement0
Y -displacement0 (bctype1)
(bctype2)
(bctype3)
8Truss Analysis A simple example
9A simple example input data(details to be
discussed next class)
joint_def0, 0, 1, 0, 0 50,
50, 0, 0, 0 150, 150, 0, 100,
-50 250, 50, 0, 0, 0
300, 0, 3, 0, 0 200, 0, 0,
0, 0 100, 0, 0, 0, 0
member_def1, 2, 10, 10 2, 3, 10,
10 3, 4, 10, 10 4, 5,
10, 10 5, 6, 10, 10 6,
7, 10, 10 7, 1, 10, 10
2, 7, 10, 10 7, 3, 10, 10
3, 6, 10, 10 6, 4, 10, 10
10A simple example - results
Matlab command (call to function
analyze_truss) disp,stressanalyze_truss(join
t_def,member_def)
- Joint Displacments
- disp
- 0.0000
- 0.0000
- 0.2457
- -0.1750
- 0.6493
- -0.4371
- 0.2043
- -0.4578
- 0.4500
- -0.0000
- 0.3000
- -0.5536
- 0.1500
- -0.2707
Member Stresses stress 0.3536 0.3536
-1.0607 -1.0607 0.7500 0.7500
0.7500 -0.0000 0.0000 0.0000 -0.0000
11Examples of truss design programs
- Johns Hopkins University
- http//www.jhu.edu/virtlab/bridge/truss.htm
- West Point Bridge Design Contest
- http//bridgecontest.usma.edu/
12Notes on academic integrity
Truss design and analysis programs are
common. Students are welcome to look at other
programs for features to incorporate. Direct
copying of code, however, is not permitted. Do
not share code with other teams. Be sure not to
leave your codes on public computers.
13Longer Running Loops
- for loops repeat a fixed number of times
- for variable array of length n
- commands
- end
- and break can be used to stop earlier.
- Question How about repeating until done? Run
as long as is needed.
14Answer MATLABs while loop
- while expression
- commands to be repeated as long
- as expression is true
- end
15Prior example compounded interest until the
amount doubles
for loop
- value 1000
- for year 11000
- value value 1.08
- disp(num2str(year),' years ',num2str(value)
) - if value gt 2000
- break
- end
- end
terminated with break
16Expected output
17while version
- format bank
- value 1000
- while value lt 2000
- value value 1.08
- disp(value)
- end
18Example Collecting and storing data until a
zero is entered
empty array
- x
- new 1
- while new 0
- new input('enter value ')
- x x, new
- end
- x x(1end1)
initialize
to drop the zero
19Example Getting valid keyboard input
- E.g. forcing the users input to be between 0
and 10 - x 3
- while ( x lt 0 ) ( x gt 10 )
- x input( 'type a value ' )
- end
20- or
- x input('enter value ')
- while (xlt0)(xgt10)
- disp('invalid choice')
- x input('enter value ')
- end
- disp('finally!')
21Example computing pi
22Example infinite Hi-Lo
- numb round (10rand(1))
- done 0
- while done
- guess input('guess')
- if guess numb
- disp( 'You got it !!!' ) done 1
- elseif guess gt numb
- disp('too high')
- else
- disp('too low')
- end
- end
initialization
single guess
loop control
23Nesting of while loops
- while expression1
- outer loop commands
- while expression2
- inner loop commands
- end
- more outer loop commands
- end
these can also be more than 2 levels deep