lecture 2 1.computing 101 2.developing a solution 3.problem solving

43
Lecture 2 1. Computing 101 2. Developing a Solution 3. Problem Solving

Upload: leon-richard

Post on 29-Dec-2015

216 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

Lecture 2

1. Computing 1012. Developing a Solution3. Problem Solving

Page 2: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

2

Recommendation on taking notes in EGR115

• Notebook– slide number in margin. comments on the right.– write down vocabulary words– write down overall ideas– write down things that we repeat 4 or 5 times!– write down possible errors

• Printout of Slides*– print 2 or 3 slides per page– draw arrows, add your comments– Highlight

*We will do our best to have the slides posted by the night before, but no guarantees.

Page 3: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

Computer Hardware• 1946 – ENIAC (Electronic Numerical Integrator And

Computer) – First general purpose electronic computer.• The Von Neumann computer architecture is mostly what

we use today. The architecture separates a computer in 3 major parts:– The Central Processing Unit (CPU)– The computer memory– The Input/Output (I/O) devices

3

CPU + memoryScreen=output

Speakers=output Mouse=input

Keyboard=input

?

?

Page 4: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

The important pieces

• Computing (as a whole) can be broken into 4 main categories:– Hardware

• What people generally think of as the computer. You can touch it. (Normally limited to electronic components)

– Software• Applications, games, programs you run.

– Data• The stuff applications use and produce – Word documents, saved game

files, Excel Spreadsheets, etc.– Media

• Where things get stored. Hard disks, USB thumb drives, CD/DVD disks, 3.5” floppy disks, magnetic tape.

Page 5: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

Programming?

• You will generally be using hardware to write software that uses data and is saved on media.

• Programming is the act of writing logical instructions that the computer will execute when the software is used.

• Writing a program can be as difficult as learning to speak a foreign language, since the programmer is constrained to the vocabulary (specific terminology or keywords), grammar (exact syntax), and punctuation (symbols) of programming.

5

Page 6: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

6

Categories of software

• Software contains the instructions the CPU uses to run programs.

• There are several categories, including:– Operating systems (OS) – manager of the computer system as a whole– Software applications – commercial programs that have been written

to solve specific problems– Language compilers - to ‘translate’ programs written by people into

something understandable by the machine (sometimes not needed)

Page 7: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

Generations of Languages used to write software

1) Machine language – also called binary language. Sequence of 0’s and 1’s.

(rarely written by hand)

2) Assembly language – each line of code produces a single machine instruction (add, subtract…)(Used by specialty professionals)

3) High-level language – slightly closer to spoken languages.(How most programmersprogram)

7

add b,cadd a,b

a = a + b + c;

This line does the same as the two above.

Page 8: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

Finally… MATLAB

• Is both a software application and a language interpreter.

• Is an interpreted language – does not require compilation, but it does have a conversion step hidden from the user.

• Has an interactive environment –– “In the MATLAB environment, you can develop and execute programs

that contain MATLAB commands. You can execute a MATLAB command, observe the results, and then execute another MATLAB command that interacts with the information in memory, observe its results and so on.”

8

Page 9: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

Generating a Solution

• Computers make very fast, very accurate mistakes.

• They do exactly what you tell them to, not what you mean for them to do.

• You are looking to design a technique for solving a problem. If the inputs change, then the technique should still work.

• If the goal is to solve a problem, you have to know how to solve the problem before you can tell the computer how to solve it.

• The set and order of steps you (and the computer) take to solve a problem is called an algorithm.

Page 10: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

General Idea of This Lesson

• Provide you with a method (i.e. a recipe) for solving problems

Example problems:• “Find the optimum nozzle dimensions for …”• “Solve for the optimum path for the robot …”• “Find the range of temperatures adequate for …”

• In EGR115, most tasks will be:“Develop a program that ……”

Page 11: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

General Terms

• Keep in mind there are 2 sides to software– The person who writes software: the programmer– The person who uses software: the user (i.e. client)

11

Page 12: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

General Terms

• Keep in mind there are 2 sides to software– The person who writes software: the programmer– The person who uses software: the user (i.e. client)

• As you (the student) develop software, you will constantly jump back and forth between the two roles.

• Your goal:“The programmer should make the user’s life easy.”- Clear directions- Clear units- Examples of answers- Clean presentation

12

Page 13: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

13

Where do I even start?

ME408 Clean Thermal

Power Systems

Page 14: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

14

Scientific Problem-Solving Method

1. Problem Statementa. Diagramb. Assumptions

2. Solution Steps (manual solution)a. Theory / limitationsb. Itemize specific steps (in order) as you solve the problemc. Identify results & verify accuracy

3. Computerize the solutiona. Express the algorithm as steps general to any instance of the problemb. Translate the algorithm to lines of codec. Test and verify result

Page 15: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

15

Scientific Problem-Solving Method

1. Problem Statementa. Diagramb. Assumptions

2. Solution Stepsa. Theory / limitationsb. Itemize specific steps (in order) as you solve the problemc. Identify results & verify accuracy

3. Computerize the solutiona. Express the algorithm as steps general to any instance of the problemb. Translate the algorithm to lines of codec. Test and verify results

• Create a program to “solve” many instances => Create a program to re-use the solution for other sets of givens.

• Coding is very late in the process.

Page 16: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

16

Scientific Problem-Solving Method

1. Problem Statement– Summarize the given information– Must contain all essential information, units included!

• GET RID OF useless information!– State what is to be determined

Page 17: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

17

Example – Aerospace Engineering

• Problem:– Givens

• Temperature (Kelvin)• Volume (meters cubed)• n : chemical amount of gas (moles)• R : gas constant R = 8.3144 Joules/(moles*Kelvin)

– Solve for• The pressure (Pascals)

http://www.epa.gov/eogapti1/bces/module2/idealgas/idealgas.htm

NOTE: There is no full sentence here!!!

Do not rewrite the problem. Separate the GIVENS from the SOLVE FOR.

(Might use the Ideal Gas Law)

Page 18: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

18

Example – Mechanical Engineering

• Problem: Stress on a beam

– Givens• Load 1: R1 = 10lb• Load 2: R2 = 60lb• Load 3: R3 = 20lb• Load 4: R4 = 50lb• Distances from start of beam to load2: 5ft• Distance between load2 and 3: 15ft• Distance between load3 and end of beam: 7ft

– Solve for• shear diagram• moment diagram

square beam

R1 = 10lb

R2 = 60lb R3 = 20lb

R4 = 50lb

5ft 15ft 7ft

NOTE: There is no full sentence here!!!

Do not rewrite the problem. Separate the GIVENS from the SOLVE FOR.

Page 19: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

19

Example – Civil Engineering

• Problem: Elongation of rod

– Givens• diameter of rod: 0.5in• length of rod: 6ft• weight of load: 2000lbs• material: steel

– Solve for• normal stress in rod (psi)• strain (elongation for 1 unit) in the rod (inches/in)• elongation of rod (inches)

2000 lbs

6ft

AGAIN…No full sentences

Page 20: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

Scientific Problem-Solving Method

• Sometimes it is helpful to think about the problem this way:– What am I trying to get to (e.g., the output)?– What are the constants given in the problem?– What are the things the user will provide (either from the keyboard or

a file)– What are the constants I think I will need but that aren’t given (e.g.,

gravity, pi, etc.)– What things can I calculate with that information? Note, this may be

something where you know how to calculate (e.g., area or circumference) or that you know a formula exists for and you just need to find that formula. (e.g., solving for unknown parts of a triangle)

Page 21: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

21

Scientific Problem-Solving Method

1. Problem Statementa. Diagramb. Assumptions

2. Solution Steps (manual solution)a. Theory / limitationsb. Itemize specific steps (in order) as you solve the problemc. Identify results & verify accuracy

3. Computerize the solutiona. Express the algorithm as steps general to any instance of the problemb. Translate the algorithm to lines of codec. Test and verify results

Page 22: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

22

Example – Aerospace Engineering

http://txchnologist.com/post/31532018204/txchnical-improvements-combining-rockets-and-jets-for

http://www.universetoday.com/29317/how-to-keep-asteroids-away-tie-them-up/

http://hsc.csu.edu.au/engineering_studies/focus/aero/3057/Graphics.html

Page 23: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

23

Example – Civil Engineering

http://map.ua.edu/resources/

Page 24: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

24

Example – Electrical Engineering

Page 25: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

25

Scientific Problem-Solving Method

1. Problem Statementa. Diagramb. Assumptions

2. Solution Steps (manual solution)a. Theory / limitationsb. Itemize specific steps (in order) as you solve the problemc. Identify results & verify accuracy

3. Computerize the solutiona. Express the algorithm as steps general to any instance of the problemb. Translate the algorithm to lines of codec. Test and verify results

Page 26: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

26

For example…

• Assume no friction• Assume wall thickness is negligible• Assume initial speed is zero• Assume mass of object is negligible

• Aerodynamics: Assume laminar flow (i.e. no turbulence)

• Thermodynamics: Assume geometry of a turkey is that of an American football

• Solids: assume system is in equilibrium

Page 27: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

Assumptions

• ASSUMPTIONS ARE NOT FACTS!

• Assume “Area of a Circle” = π * radius2

• That isn’t an assumption – it’s a fact. Assumptions are things that MIGHT not be true (or that you know AREN’T true).

• Assuming π = 3.14 is an assumption because you know it isn’t true.

• They may be necessary to solve the problem, or they may just make the problem easier to solve.

Page 28: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

28

Scientific Problem-Solving Method

1. Problem Statementa. Diagramb. Assumptions

2. Solution Steps (manual solution)a. Theory / limitationsb. Itemize specific steps (in order) as you solve the problemc. Identify results & verify accuracy

3. Computerize the solutiona. Express the algorithm as steps general to any instance of the problemb. Translate the algorithm to lines of codec. Test and verify results

Page 29: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

29

Example – General Equations

• Volume of a sphereV = 4/3*∏*R^3

• Volume of a cubeV = L^3

• Newton’s second law of motionF = m*a

• Equation of a liney = m*x + b

• Slopem = Δy/Δx = (y2-y1)/(x2-x1)

• WeightW = mass * g

Page 30: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

30

Example – ME/AE Engineering

• If the system is in equilibrium,ΣF = 0 (“sum of all forces equals zero”)

• Bernoulli’s Principle (fluid dynamic)

Page 31: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

31

Example – Electrical/Civil Engineering

• Ohm’s lawV = R*I (V=voltage (V), R=resistance (Ω), I=current (A))

• Electrical Power (i.e. Work)P = V * I (P = power, in Watts)

• Potential EnergyPenergy = w * h (W=weight (Newtons), h=height (m), P (Joules))

• Kinetic EnergyKenergy = ½*m * v2

Page 32: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

32

Scientific Problem-Solving Method

1. Problem Statementa. Diagramb. Assumptions

2. Solution Steps (manual solution)a. Theory / limitationsb. Itemize specific steps (in order) as you solve the problemc. Identify results & verify accuracy

3. Computerize the solutiona. Express the algorithm as steps general to any instance of the problemb. Translate the algorithm to lines of codec. Test and verify results

Page 33: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

33

Examples

• Number the equations

© FrigginPhysics.com

Page 34: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

34

Scientific Problem-Solving Method

1. Problem Statementa. Diagramb. Assumptions

2. Solution Steps (manual solution)a. Theory / limitationsb. Itemize specific steps (in order) as you solve the problemc. Identify results & verify accuracy

3. Computerize the solutiona. Express the algorithm as steps general to any instance of the problemb. Translate the algorithm to lines of codec. Test and verify results

Page 35: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

35

Identify Results

• Make sure the solutions are clearly identified– example: boxed, circled, colored, underlined, centered…

© FrigginPhysics.com

Page 36: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

36

Verify

• Do the values match/verify the diagram?

• Common sense– Time cannot be negative– (Scalar) distance cannot be negative

• Visually– If you drew a scaled diagram, verify that the results are close to the drawing?

• Is it realistic? Drive Time = 394,242,305,932 seconds?Vrunner = 217.5 miles/hr

When turning in homework, always work on fixing errors, but if you fail, at least indicate “something wrong, this is unrealistic”… before turning it in..

http://www.hardenedshelters.com/underground.asp

Page 37: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

37

Last but not least!!! Presenting the data

• Paper, or machine

• Either way:– Clearly present the

information– Words and sentences

must explain what’s going on each step

– Skip lines, space things out!• not everything has to fit

on the top left corner!!!!

Page 38: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

38

Bad Presentations

• inadequate paper size, incomplete (missing data, and units), change of orientation, no breathing room…where are the results?!

http://www.math.mcgill.ca/rags/JAC/ddb121.htmlSemester 2012 Fall

Page 39: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

39

HORRIBLE HANDWRITING!

• You can feel it in your guts…

How you can feel “OK” turning this in????- See this as a draft, & start over!!

Page 40: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

What is this?

• Lower case b?• Lower case c?• Lower case e?• Capitol G?

• If we can’t clearly identify it, it is wrong.

Page 41: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

Scientific Problem-Solving Method

1. Problem Statementa. Diagramb. Assumptions

2. Solution Steps (manual solution)a. Theory / limitationsb. Itemize specific steps (in order) as you solve the problemc. Identify results & verify accuracy

3. Computerize the solutiona. Express the algorithm as steps general to any instance of the problemb. Translate the algorithm to lines of codec. Test and verify results

41

b. and c. is what will be learned all this semester!

Page 42: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

42

3a. Deduce the algorithm

• In mathematics and computer science, an algorithm is a step-by-step procedure for calculation. (Wikipedia)

• More precisely, an algorithm is an effective method expressed as a finite list of well-defined instructions for calculating a function. (Wikipedia)

• Algorithms – must not be complex!– should be detailed/organized– must be general enough for different values of inputs

– Simple problem = simple algorithm– Complex problem = detailed algorithm

Page 43: Lecture 2 1.Computing 101 2.Developing a Solution 3.Problem Solving

43

Example

The problem The algorithmDefine base and heightCalculate areaDisplay result

OR

Define side1 and 2’s lengthDefine angle between the two

sidesCalculate areaDisplay result

height=6m

base=3m

side 1=25m

side 2 = 45m

angle = 26.5deg

“detailed yet general”

NOTE: There is neither full sentence here, nor detailed equations!!!