EGR 106 – Project Intro / While Loop
Project description Project schedule Background information / terminology A simple example Examples of similar programs While loop
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.
Project Description
The program developed by each team shall provide a user-friendly interface for both data input and interpretation of results
Each team’s 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)
Project Description (cont.)
3/27 – (T) Project Introduction3/29 – (R) Quiz 2 make up / Team assignment #14/3 – (T) Lecture: Analysis of Trusses / Graphical Interface4/5 – (R) Project work / Team assignment #24/10 – (T) Lecture: Analysis of Trusses / Graphical Interface4/12 – (R) Quiz 3 / Project work4/17 – (T) Project work4/19 – (R) In-class design competition4/24 – (T) Quiz 4 / Model testing4/26 – (R) Project Presentations / Demonstrations5/1 – (T) Written reports due
Project Schedule (tentative)
Definition: A planar truss is a structure composed of slender members joined together at their end points (called joints).
Background – Truss Structures
Photo: Engineering Mechanics: Statics, by R. C. Hibbeler
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.
Terminology (cont.)
X & Y –displacement=0 X - displacement=0 Y -displacement=0 (bctype=1) (bctype=2) (bctype=3)
A simple example – input data(details to be discussed next class)
Cx = 100
Cy = -50
300 mm
150 mm
joint_def=[0, 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_def=[1, 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];
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
Cx = 100
Cy = -50
300 mm
150 mm
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
A simple example - resultsMatlab command (call to function ‘analyze_truss’):
[disp,stress]=analyze_truss(joint_def,member_def)
Examples of truss design programs
Johns Hopkins University:http://www.jhu.edu/~virtlab/bridge/truss.htm
West Point Bridge Design Contesthttp://bridgecontest.usma.edu/
Notes 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.
Longer 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.
Answer: MATLAB’s “while” loop:
while expression
{commands to be repeated as long
as expression is true}
end
Prior example – compounded interest untilthe amount doubles:
value = 1000;
for year = 1:1000
value = value * 1.08;
disp([num2str(year),' years: $ ',num2str(value) ])
if value > 2000
break
end
end
for loop
terminated with break
Example – Collecting and storing data until a zero is entered:
x = [ ];
new = 1;
while new ~= 0
new = input('enter value ');
x = [ x, new ];
end
x = x(1:end–1)
empty array
to drop the zero
initialize
Example – Getting valid keyboard input:
E.g. forcing the user’s input to be between 0 and 10:
x = –3;
while ( x < 0 ) | ( x > 10 )
x = input( 'type a value ' );
end
or:
x = input('enter value ');
while (x<0)|(x>10)
disp('invalid choice');
x = input('enter value ');
end
disp('finally!');
Example – “infinite” Hi-Lo:
numb = round (10*rand(1)); done = 0;while ~done
guess = input('guess');if guess = = numb disp( 'You got it !!!' ); done = 1;elseif guess > numb disp('too high')else disp('too low')end
end
initialization
single guess
loopcontrol
Top Related