cs107 computing for math cs107 computing for math and
play

CS107: Computing for Math CS107: Computing for Math and Science - PowerPoint PPT Presentation

CS107: Computing for Math CS107: Computing for Math and Science and Science Instructor: Prof. Louis Steinberg office: Hill 401 email: lou@cs.rutgers.edu Office hours: by appointment TAs: Andre Cohen office: CBIM


  1. CS107: Computing for Math CS107: Computing for Math and Science and Science • Instructor: Prof. Louis Steinberg – office: Hill 401 – email: lou@cs.rutgers.edu – Office hours: by appointment • TAs: – Andre Cohen office: CBIM acohen@ cs.rutgers.edu – Xiaoye Han office: Hill 405 xiaoye @ cs.rutgers.edu CS107, Prof. Steinberg, f10 Lecture 02 1

  2. CS107: Computing for Math CS107: Computing for Math and Science and Science • Instructor: Prof. Apostolos Gerasoulis – office: Core 328 – email: grasoul@cs.rutgers.edu – Office hours: by appointment • TA: – Nader Boushehrinejadmoradi Office: Hill 353 naderb@cs.rutgers.edu CS107, Prof. Steinberg, f10 Lecture 02 2

  3. Items posted on web site Items posted on web site • Assignment 1 on Sakai ??? • Practice problems 1 on Remus CS107, Prof. Steinberg, f10 Lecture 02 3

  4. Web Sites Web Sites • http:// http://remus remus.rutgers.edu/cs107 .rutgers.edu/cs107 • – Policies – Syllabus – Lecture notes – etc.... – You are assumed to know anything posted. – Also Sakai site CS107, Prof. Steinberg, f10 Lecture 02 4

  5. Should you take CS107? Should you take CS107? • Math or science major, had calc I: YES • Exceptions: – Computer Science major or minor: NO – Except: unsure about CS: MAYBE – Option B: The Computer-Oriented Mathematics Major: NO CS107, Prof. Steinberg, f10 Lecture 02 5

  6. Kinds of Knowledge Kinds of Knowledge • Knowing that – Knowing a fact, e.g. rules of Chess • Knowing how – Knowing how to use facts to achieve a goal, e.g. how to win at chess CS107, Prof. Steinberg, f10 Lecture 02 6

  7. E.G., Algebra E.G., Algebra • Knowing that If X = Y then X + a = Y + a • Knowing how – To solve 3*x - 5 = 10, start by adding 5 to both sides of the equation 3*x - 5 + 5 = 10 + 5 3*x = 15 CS107, Prof. Steinberg, f10 Lecture 02 7

  8. Learning “ “Knowing How Knowing How” ” Learning • The only way to learn “How” is practice • Only way to learn most of the course material is to do homework • Purpose of lecture and textbook is to prepare you to do this work CS107, Prof. Steinberg, f10 Lecture 02 8

  9. Review Review • What is a computer • Anthropomorphisms – Follow instructions – Process data – Language CS107, Prof. Steinberg, f10 Lecture 02 9

  10. What is a computer? What is a computer? • A machine that follows instructions and processes data CS107, Prof. Steinberg, f10 Lecture 02 10

  11. How can a machine follow How can a machine follow instructions? instructions? • Example: Washing machine controller – Controls hot water, cold water, drain, motor CS107, Prof. Steinberg, f10 Lecture 02 11

  12. Hot Wash, Warm Rinse Hot Wash, Warm Rinse Peg H C D M No Peg CS107, Prof. Steinberg, f10 Lecture 02 12

  13. Machine Instructions Machine Instructions • A pattern of physical objects • Pegs, electrons, etc • Physically causes the specified behavior • Can be thought of as a language • Expresses commands • Made of pieces combined according to rules • Extremely detailed, so need “higher level” language CS107, Prof. Steinberg, f10 Lecture 02 13

  14. Higher Level Language Higher Level Language • Compromise – Easier for humans to deal with – Write, check, understand, … – Still not too hard to make a machine obey CS107, Prof. Steinberg, f10 Lecture 02 14

  15. Data processing Data processing • What Kaplan text calls “computation” • Any process that transforms some data into other data, e.g. addition CS107, Prof. Steinberg, f10 Lecture 02 15

  16. Representation Representation • For a machine to process data, the data must be represented by some physical quantity – Length, voltage, … CS107, Prof. Steinberg, f10 Lecture 02 16

  17. Matlab Matlab • Matlab is: – A programming language – A library of programs and pieces – An Interactive Development Environment (IDE) – A program that helps you build and test programs CS107, Prof. Steinberg, f10 Lecture 02 17

  18. Matlab as a Calculator as a Calculator Matlab • E.g., convert 75 degrees Fahrenheit to Celsius • E.g. convert $100 to Euros ($1 = .79 Eur.) • E.g. wall area of a room 10’ x 12’ x 8’ • Note: precedence • Note: infix vs prefix form • Note: lack of units CS107, Prof. Steinberg, f10 Lecture 02 18

  19. Operations Operations • Plus + 4 + 5 • Minus - 4 - 5 • Times .* 4 .* 5 • Divide ./ 4 ./ 5 • Power .^ 4 .^ 5 • Square root sqrt sqrt(4) • Sin sin sin(4) • … etc. CS107, Prof. Steinberg, f10 Lecture 02 19

  20. Variables Variables • Typically, calculators have a memory; matlab has many memory cells • Memory cell in matlab is called a “variable” • A variable has – a name, e.g. age, year, area, … – a value CS107, Prof. Steinberg, f10 Lecture 02 20

  21. Variables Variables • The first time you type a variable’s name, Matlab: – Reserves a space in the computer’s memory – Associates that space with the name you typed • After that, when you type the name, Matlab uses the associated memory space CS107, Prof. Steinberg, f10 Lecture 02 21

  22. Using Variables Using Variables • To refer to a variable just type its name • Most of the time name means “the value stored there” (degreesF - 32) .* 5 ./ 9 • To say “store this value here”, use = degreesF = 72 degreesC = (degreesF - 32) .* 5 ./ 9 CS107, Prof. Steinberg, f10 Lecture 02 22

  23. Why use a variable? Why use a variable? • One use: to store an intermediate result for reuse discriminant = b.^2-4.*a.*c b + sqrt(discriminant)/(2.*a) b - sqrt(discriminant)/(2.*a) CS107, Prof. Steinberg, f10 Lecture 02 23

  24. Why use a variable? Why use a variable? • Another use: in a repetitive computation – E.g. compute square root of 5. Use a variable named, say, root >> root = 2 root = 2 >> root = (root + 5 ./ root) ./ 2 root = 2.2500 >> root = (root + 5 ./ root) ./ 2 root = 2.2361 >> root .* root ans = 5.0000 CS107, Prof. Steinberg, f10 Lecture 02 24

  25. Matlab Programs Programs Matlab • A Matlab program is made up of statements – One per line • One kind of statement is: Assignment statement CS107, Prof. Steinberg, f10 Lecture 02 25

  26. Assignment statement Assignment statement • Purpose: store a piece of data in a variable • Form: variableName = expression • Meaning: – Evaluate expression – Store the result in the variable with name variableName – Print the result CS107, Prof. Steinberg, f10 Lecture 02 26

  27. Assignment statement Assignment statement • May end with ; to prevent printing the value of the expression degreesF = 72; CS107, Prof. Steinberg, f10 Lecture 02 27

  28. Grammatical Structure Grammatical Structure • An assignment statement has parts cost = nonTaxable + taxable .* 1.065 Variable Expression name CS107, Prof. Steinberg, f10 Lecture 02 28

  29. Grammatical Structure Grammatical Structure • Parts can have parts nonTaxable + taxable .* 1.065 Expression expression operator expression CS107, Prof. Steinberg, f10 Lecture 02 29

  30. Grammatical Structure Grammatical Structure • Parts can have parts that have parts nonTaxable + taxable .* 1.065 Expression expression operator expression expression operator expression CS107, Prof. Steinberg, f10 Lecture 02 30

  31. Grammatical Structure Grammatical Structure totalCal = mms .* calPerMm position = startPos + time .* speed pay = hours .* rate + overtime * otrate CS107, Prof. Steinberg, f10 Lecture 02 31

  32. Grammatical Structure Grammatical Structure totalCal = mms .* calPerMm position = startPos + time .* speed pay = hours .* rate + overtime * otrate CS107, Prof. Steinberg, f10 Lecture 02 32

  33. Grammatical Structure Grammatical Structure totalCal = mms .* calPerMm position = startPos + time .* speed pay = hours .* rate + overtime * otrate CS107, Prof. Steinberg, f10 Lecture 02 33

  34. Grammatical Structure Grammatical Structure totalCal = mms .* calPerMm position = startPos + time .* speed pay = hours .* rate + overtime * otrate CS107, Prof. Steinberg, f10 Lecture 02 34

  35. Programs Programs • So far, we have used Matlab as a calculator – Type a line, Matlab does it • How do we type instructions once, use many times? CS107, Prof. Steinberg, f10 Lecture 02 35

  36. Functions Functions • Suppose you want to calculate length of hypotenuse? hypotenuse = ? height = 4 base = 5 • In command window, type sqrt(5.^2 + 4.^2) CS107, Prof. Steinberg, f10 Lecture 02 36

  37. Functions Functions • Suppose you want to calculate length of hypotenuse many times? CS107, Prof. Steinberg, f10 Lecture 02 37

  38. Functions Functions • Suppose you want to calculate length of hypotenuse many times? sqrt( 4 .^2 + 5.^2) sqrt( 7 .^2 + 11.^2) sqrt( 20 .^2 + 21.^2) … • This is a pain - can’t we just do hyp(4, 5) hyp(7, 11) hyp(20, 21) CS107, Prof. Steinberg, f10 Lecture 02 38

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend