1 / 39

Computer Science 121

Scientific Computing Winter 2012 Chapter 1: What is Computation?. Computer Science 121. 1.1 Computation as Transformation. A computation is a transformation from on or more inputs to an output. Input = time ; Output = reactant (grams). 1.1 Computation as Transformation.

lynette
Download Presentation

Computer Science 121

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Scientific Computing Winter 2012 Chapter 1: What is Computation? Computer Science 121

  2. 1.1 Computation as Transformation • A computation is a transformation from on or more inputs to an output. • Input = time; Output = reactant (grams)

  3. 1.1 Computation as Transformation • Input = age (years); Output = recall (items)

  4. http://www.macalester.edu/~kaplan/scientificprogramming/figures.ppthttp://www.macalester.edu/~kaplan/scientificprogramming/figures.ppt 1.1 Computation as Transformation Input = x; Output =√x

  5. http://www.macalester.edu/~kaplan/scientificprogramming/figures.ppthttp://www.macalester.edu/~kaplan/scientificprogramming/figures.ppt 1.1 Computation as Transformation Input = financial info; Output = tax owed / refunded

  6. http://www.macalester.edu/~kaplan/scientificprogramming/figures.ppthttp://www.macalester.edu/~kaplan/scientificprogramming/figures.ppt 1.1 Computation as Transformation Input = image file; Output = “This is the Mona Lisa!”

  7. 1.1 Computation as Transformation Input = .wav file; Output = “This is the vowel /i/”

  8. 1.2 Computation as Reaction to Events • Inputs often come from measurements • Measurements are typically performed using transducers (convert input signal into numbers) • microphone • speedometer • thermometer • seismograph • radar • (What sort of data doesn't require transducers?)

  9. 1.2 Computation as Reaction to Events • Sundial (and compass): Analog transducers http://research.utk.edu/ora/explore/sundial.jpg

  10. 1.2 Computation as Reaction to Events • Because measurements (signals) typically change over time, we get the concept of state: the set of values describing a system at a given time • E.g. • Health: <blood pressure, temperature, heart rate> • Airplane: <heading, altitude, fuel> • Subatomic particle: <position, momentum> • So... • A computation isa transition from an old state to a new state.

  11. 1.2 Computation as Reaction to Events • A computation isa transition from an old state to a new state • What does this mean? • If we can build a computational model of how a system changes state (reacts to events), we can make predictions about how the system will behave • Health: influence of drugs • Airplane: response to turbulence • Particle: Heisenberg's Uncertainty Principle (!!!)

  12. 1.3 Algorithms Muhammad ibn Mūsā al-Khwārizmī (c. 780 – 850) Al-Kitāb al-mukhtaṣar fī hisāb al-jabr wa-l-muqābala

  13. Matlab Programs Matlab Interpreter Operating System Hardware 1.3 Algorithms • “Don't Reinvent the Wheel” Principle: We should build new computations out of ones that already exist • Principle applies across the board in computer science: • How computer runs programs:

  14. my_program.m read_data.m save_data.m plot_data.m 1.3 Algorithms • Principle applies across the board • How programs are written:

  15. 1.3 Algorithms • Build new computations out of ones that already exist • An algorithmis a set of directions for carrying out a computation in terms of other, simpler computations. • Difficulty in writing algorithms comes from differences between the ways that people do things and the way that computers do them • People: Slow, parallel, good generalization

  16. “Cat!” “Cat!” “Cat!” 1.3 Algorithms • People: Slow, parallel, good generalization

  17. 6068 x 4859 29484412 1.3 Algorithms • Computers: Fast, serial, poor generalization

  18. Expressing Algorithms • Example: Compare two Arabic numerals (e.g., 23 and 97) to determine which is larger • Count the digits in each numeral. If one has more digits than another, the one with more is the larger. • Otherwise, compare the leftmost digits in the two numerals. If one digit is larger than the other, the numeral with the larger leftmost digit is the larger numeral. • Otherwise, chop off the first numeral and go to step 2. Q.: What haven't we considered?

  19. Expressing Algorithms • Example: Find smallest number in list • Assume smallest is first item in list. • If there are no more items in list, we're done. Report smallest number. • Otherwise, look at next item. If it's smaller than current assumed “smallest” value, make current answer equal to value of this item. • Go to step 2.

  20. Expressing Algorithms • Example: Find smallest LIST: 5 2 9 1 3

  21. Expressing Algorithms • Example: Find smallest LIST: 5 2 9 1 3 SMALLEST: 5

  22. Expressing Algorithms • Example: Find smallest LIST: 5 2 9 1 3 SMALLEST: 2

  23. Expressing Algorithms • Example: Find smallest LIST: 5 2 9 1 3 SMALLEST: 2

  24. Expressing Algorithms • Example: Find smallest LIST: 5 2 9 1 3 SMALLEST: 1

  25. Expressing Algorithms • Example: Find smallest LIST: 5 2 9 1 3 SMALLEST: 1

  26. Expressing Algorithms • Example: Find smallest LIST: 5 2 9 1 3 SMALLEST: 1

  27. Expressing Algorithms • Example: Sort a list of numbers • Create a new, empty list • Find the smallest item in the old list. • Remove this item from the old list and add it to the beginning of the new list. • If the old list is empty, we're done. Output the new list. • Otherwise, go to step 2.

  28. Expressing Algorithms • Example: Sort a list of numbers OLD: 5 2 9 1 3 NEW:

  29. Expressing Algorithms • Example: Sort a list of numbers OLD: 5 2 9 1 3 NEW:

  30. Expressing Algorithms • Example: Sort a list of numbers OLD: 5 2 9 3 NEW: 1

  31. Expressing Algorithms • Example: Sort a list of numbers OLD: 5 2 9 3 NEW: 1

  32. Expressing Algorithms • Example: Sort a list of numbers OLD: 5 9 3 NEW: 1 2

  33. Expressing Algorithms • Example: Sort a list of numbers OLD: 5 9 3 NEW: 1 2

  34. Expressing Algorithms • Example: Sort a list of numbers OLD: 5 9 NEW: 1 2 3

  35. Expressing Algorithms • Example: Sort a list of numbers OLD: 5 9 NEW: 1 2 3

  36. Expressing Algorithms • Example: Sort a list of numbers OLD: 9 NEW: 1 2 3 5

  37. Expressing Algorithms • Example: Sort a list of numbers OLD: 9 NEW: 1 2 3 5

  38. Expressing Algorithms • Example: Sort a list of numbers OLD: NEW: 1 2 3 5 9

  39. Important Points • We re-used our smallest-number algorithm in our sorting algorithm: instead of re-writing it, we referred to it! • We needed a strange notion of “smallest” - smallest item in a one-item list is the item itself. • Contrast this with ordinary language terminology • No “smallest” (or largest) item in a one-item list. • We (are supposed to) say “smaller” (not “smallest”) if there are only two items • These sorts of differences contribute to our difficulty in learning to program. • But as algorithms get more complicated, we will find it more difficult to use ordinary language (“the current smallest”) to express them – need variables

More Related