General Problem Solving Methodology

advertisement
EGR 106 – Project Intro / While Loop






Project description
Project schedule
Background information / terminology
A simple example
Examples of similar programs
While loop
Project 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.
Project Description (cont.)



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 Schedule (tentative)
3/27 – (T)
3/29 – (R)
4/3 – (T)
4/5 – (R)
4/10 – (T)
4/12 – (R)
4/17 – (T)
4/19 – (R)
4/24 – (T)
4/26 – (R)
5/1 – (T)
Project Introduction
Quiz 2 make up / Team assignment #1
Lecture: Analysis of Trusses / Graphical Interface
Project work / Team assignment #2
Lecture: Analysis of Trusses / Graphical Interface
Quiz 3 / Project work
Project work
In-class design competition
Quiz 4 / Model testing
Project Presentations / Demonstrations
Written reports due
Background – 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
Terminology – Truss Structures
Forces
Member
Joint
Supports
Terminology (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 –displacement=0
(bctype=1)
X - displacement=0
(bctype=2)
Y -displacement=0
(bctype=3)
Truss Analysis – A simple example
Cy = -50
Cx = 100
150 mm
300 mm
A simple example – input data
(details to be discussed next class)
Cy = -50
Cx = 100
150
mm
300
mm
joint_def=[0,
0,
50, 50,
150, 150,
250, 50,
300,
0,
200,
0,
100,
0,
member_def=[1,
2,
3,
4,
5,
6,
7,
2,
7,
3,
6,
2,
3,
4,
5,
6,
7,
1,
7,
3,
6,
4,
1,
0,
0;
0,
0,
0;
0, 100, -50;
0,
0,
0;
3,
0,
0;
0,
0,
0;
0,
0,
0];
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10;
10;
10;
10;
10;
10;
10;
10;
10;
10;
10];
A simple example - results
Matlab command (call to function ‘analyze_truss’):
[disp,stress]=analyze_truss(joint_def,member_def)
Joint Displacments
Cy = -50
Cx =
100
150
mm
300
mm
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
Examples of truss design programs
Johns Hopkins University:
http://www.jhu.edu/~virtlab/bridge/truss.htm
West Point Bridge Design Contest
http://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 until
the amount doubles:
for loop
value = 1000;
for year = 1:1000
value = value * 1.08;
disp([num2str(year),' years: $ ',num2str(value) ])
if value > 2000
break
end
terminated
end
with break
Expected output:
while version
format bank
value = 1000;
while value < 2000
value = value * 1.08;
disp(value)
end
Example – Collecting and storing data until a
zero is entered:
empty array
x = [ ];
initialize
new = 1;
while new ~= 0
new = input('enter value ');
x = [ x, new ];
end
x = x(1:end–1)
to drop the zero
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 – computing pi:
4 4 4 4 4 4
  4       ...
3 5 7 9 11 13
Example – “infinite” Hi-Lo:
loop
control
numb = round (10*rand(1));
initialization
done = 0;
while ~done
guess = input('guess');
if guess = = numb
disp( 'You got it !!!' ); done = 1;
elseif guess > numb
single
disp('too high')
guess
else
disp('too low')
end
end
Nesting 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
Download