CS1371 Introduction to Computing for Engineers

advertisement
CMPS 1371
Introduction to Computing
for Engineers
PRINCIPLES OF PROBLEM SOLVING
Problem Solving
 Define the Problem
 Identify given information.
 Identify other available information.
 Design and implement your solution to the
problem.
 Verify your solution.
 Reflect on your solution.
Example
 Suppose you work for a company that produces
packaging. You are told that a new material is
available to protect the package if dropped,
provided the package hits the ground at less than
25 ft/sec. The average package weight is 20
pounds with rectangular dimensions of 12 by 12
by 8 inches.
 You must determine whether the
packaging material provides
enough protection when carried by
a delivery person.
Problem Solving
 Define the Problem
 What problem are you trying to solve?
 "What would success look like?"
 What should the program output? Computed
values? A plot or series of plots?
The implication is that the package is to be
protected from an accidental drop while
being carried (not falling off the delivery
truck)
Problem Solving
 Identify given information.


What constants or data are supplied?
What theory, principles, models and equations
have you been given?
The known information is the package’s
weight, dimensions, and the maximum
allowed impact speed.
Problem Solving
 Identify other available information.
 What theory, principles, models and
equations can you find in other sources
(text books, lecture notes, etc.)?
Although not explicitly stated, you need to
know the maximum height from which the
package can be dropped without damage.
You need to find a relationship between the
speed of impact and the height of the
dropped package
Problem Solving
 Basic assumptions





The package is dropped from rest with no
vertical or horizontal velocity
The package does not tumble
The effect of air drag is negligible
Assume maximum height of 6 feet (ignore
those 8ft delivery men)
The acceleration, g, due to gravity is constant
since only a 6 ft drop
Problem Solving
 Design and implement your solution to the
problem.






How can you break the larger problem into smaller
problems?
Can you sketch the problem?
Look at the problem from the top down or bottom up?
What programming techniques might you use to
convert input to output?
What variables do you need? Vectors? Arrays?
What principles and equations apply to convert input to
output?
Problem Solving
 Since the problem involves
mass in motion, we can apply
Newton’s Laws:



Height vs time to impact
2
 h = ½ g t
Impact speed vs time to impact
 v = g t
Conservation of mechanical
energy
2
 m g h = ½ m v
m
g
v
h
ground
Problem Solving
 We could solve for any three of the
equations, but notice the 3rd equation does
not involve the impact time:



m g h = ½ m v2
h = ½ v2 / g
Notice the mass cancelled out; hence, weight
of the package does not affect the relation
between the impact speed and the height
dropped
Problem Solving
Solution:
h = ½ v2 / g
v = 25 ft/sec,
g = 32.2 ft/sec2
h = ½ (25)2 / 32.2 = 9.7 ft
>>v = 25;
>>g = 32.2;
>>h = v.^2./(2.*g)
h=
9.7050
Problem Solving
 Verify your solution.

How do you know your solution is correct?
 If the computed height was negative, we would know we
did something wrong.
 If the height was very large, we might be suspicious
 Computed height of 9.7 ft seems reasonable
 To be conservative, we would report that the protective
packaging works for heights less than 9 ft when dropped.
Problem Solving
 Reflect on your solution.

What worked?

What didn't?
Fundamental Operations
 List of possible operations we may expect to
perform on collections







Build / Insert
Traverse
Map
Filter
Fold
Search
Sort
- Create a collection of elements
- Create a new collection by operating
on an existing collection
- Transform a collection with same length
- Remove items with specified criteria
- Collection is summarized
- Locate specified element
- Re-ordering of elements
Download