Chapter 2 Getting Started with Matlab

Download Report

Transcript Chapter 2 Getting Started with Matlab

Problem Solving:
Practice & Approaches
1. Practice solving more challenging problems
2. Strategies for solving problems
3. More Practice
1
General Idea of This Lesson
• Programming is like learning a language
– You need to learn the vocabulary (keywords), grammar (syntax), and how
to use punctuation (symbols)
• Problem solving is like learning to cook
– A novice chef has a recipe
– A master chef can create their own recipe
Both tasks require practice!
2
Review: Scientific Problem-Solving Method
1.
2.
3.
4.
5.
6.
7.
List the givens needed & list what to find
Diagram
Theory (Basic Equations) – DO NOT SOLVE HERE
Assumptions – Allows us to move from step3 to step5!
Solution – Choose numbers – SOLVE HERE
Verify Accuracy – CHECK YOUR ANSWER SOMEHOW!
Computerize the solution
a.
b.
c.
Deduce the algorithm from step 5
Translate the algorithm to lines of code
Verify Results – Test code thoroughly
3
Example #1: Balancing a fulcrum
Two children of known mass sit on the extreme opposite of a 5.00-m long teetertotter. Where should the fulcrum be placed so the two children balance?
Step1
Givens
Step5
Step2
Step3
Step4
Find
Step6
Step7a
4
Reminders: Algorithms
• Reminder: Algorithms are a finite-list of instructions to follow
to complete a task. NO FULL SENTENCES. NO SPECIFICS.
Recipes
Pre-flight checklist
Post-flight checklist
Surgery procedure
5
What happens…
if the problem gets
6
Problem Solving Strategies
• The trouble with Step 5: “Solution Steps”
There can be many approaches
to solving the same problem
• CREATIVITY is an important component on how we view,
approach, and SOLVE problems.
7
Creativity
• Connect the following 9 dots with four continuous lines without
lifting your pencil
Sometimes you will need to think outside the box
8
Problem Solving Strategies
(Polya, 1945)
1. Utilize analogies
– Flow through a piping system can be modeled with electronics
Fluid friction <–>
Holdup tanks <–>
Pumps <–>
Resistors
Capacitors
Batteries
2. Work Auxiliary Problems
– Remove some constraints
9
Problem Solving Strategies
(Polya, 1945)
3. Decompose & Recombine problems
– Break the problem into individual components
Calculate Area
Prove the following equation
𝑝2 + 1 𝑞 2 + 1 𝑟 2 + 1 𝑠 2 + 1
≥ 16
𝑝𝑞𝑟𝑠
2 x 2 x 2 x 2 = 16
10
Problem Solving Strategies
4.
(Polya, 1945)
Work backwards from the solution
Ex: Measure exactly 7 oz. of liquid from an infinitely
large container using only a 5 oz. container and an 8 oz. container
8
7?
5
Solution:
1. Fill _____ container and empty into _____
2. Fill _____ container again, then pour to top-off _____ container
(_____ remaining in _____ )
3. Empty _____ and fill with the remaining _____ from _____ container
4. Fill _____ container and add it to the _____ container
11
Example#2: Kite Design
Step1
Givens known
width of a kite (cm)
height of a kite (cm)
upper-to-lower ratio
number of kites
Find
width of sheet (m)
height of sheet (m)
waste at ends (m2)
waste top and bottom (m2)
percentage waste overall (%)
Step2
Wsheet ?
Height
Wasteend ?
Width
𝑈𝑝𝑝𝑒𝑟
𝑅𝑎𝑡𝑖𝑜 =
𝐿𝑜𝑤𝑒𝑟
Hsheet ?
WasteTop Bottom ?
worksheet
12
Example #3: Fuel tank design
A fuel tank is to be constructed that will hold 50 Liters. The shape is cylindrical with a hemisphere
top and a cylindrical midsection. Costs to construct the cylindrical portion will be $300/m2 of
surface area and $400/m2 of surface area of the hemispheres. What is the tank dimension that
will result in the lowest dollar cost? What cost is that?
Step1. Givens Needed/Find?
(Use highlighter/circle/list)
Step2. diagram
Step3. Theory (Equations)
13
Example #3: Fuel tank design
Step4. Assumptions
No dead air space
Construction cost independent of size
Other costs do not change with tank dimensions
Thickness of walls is negligible
14
Example #3: Fuel tank design (Step5) Solution: Basic Algebra!
Where to start???
Write the equations you CAN put
together based on the givens, then
proceed!
Simplify, Rearrange, Get rid of "duplicate
data"… etc…
The total volume of the tank is dependent on radius and
height of cylinder.
2
𝑉𝑜𝑙𝑢𝑚𝑒 = 𝜋𝑅3 + 𝜋𝑅2 𝐻
3
Trying to solve for radius, eliminate height in final
function by inserting the volume instead (known), and
simplify:
𝑉
𝐶𝑜𝑠𝑡 𝑅 = 700𝜋𝑅2 + 600 ∗
𝑅
Write the function that links the two values you need to
find. Cost is dependent on radius, hence Cost is a
function of radius!
(mathematical notation: 𝐶𝑜𝑠𝑡 𝑅 , just like 𝑓(𝑥))
Name one possible
reason why I haven't
replaced V yet.
𝐶𝑜𝑠𝑡 𝑅 = 400 ∗ 2𝜋𝑅2 + 300 ∗ (2𝜋𝑅𝐻 + 𝜋𝑅2 )
This is NOT multiplication. Review your math notations!!
Cost is the dependent variable. R is the independent
variable.
15
Example #3: Fuel tank design
Guess & Check (Trial & Error)
Repetitive solution
Try R = 10 cm
Try R = 5 cm
Try R = 7.5 cm
Try R = 6 cm
Try R = 6.5 cm
Various methods
Graphical Solution
cost = ?
cost = ?
cost = ?
cost = ?
cost = ?
Analytical Solution (MA241)
Use the derivative:
𝑑𝐶𝑜𝑠𝑡 𝑅
=0
𝑑𝑅
Solve for R directly!
Estimate the radius that yields the minimum cost:
________ cm
16
Example #3: Fuel tank design
Finish Step5!!
• Knowing the radius, calculate height, then cost!
• Verify!!!
Example #3: Fuel tank design
Algorithms
Option 1 – Trial & Error
Option 2 - Derivatives
Option 3 - Plotting
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
define cost hemisphere/tank
define total volume
set range of radius (0-100m)
calculate cost for each radius
determine minimum of all cost
calculate height cylinder
show best dimensions
calculate/show cost
define cost hemisphere/tank
define total volume
solve for radius using derivative
solve/show for cost
calculate height cylinder
show best dimensions
define cost hemisphere/tank
define total volume
set range of radius (0-100m)
calculate cost for each radius
plot cost vs. radius
read off graph lower cost
calculate height cylinder
show best dimensions
calculate/show cost
18
Wrapping Up
•
Before you begin, know the overall solution! IMAGINATION!
•
•
•
•
•
•
•
Apply the 7 step process before you begin programming
Be clear about your approach
Think creatively
Caution on special cases! (1 kite?!)
Use a couple of strategies when understanding a problem
Practice for the next 4/5 years!
Use MATLAB to make your life easier repeating the problem with different
values.
19