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

cs107 computing for math cs107 computing for math and
SMART_READER_LITE
LIVE PREVIEW

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 acohen @


slide-1
SLIDE 1

CS107, Prof. Steinberg, f10

1

Lecture 01

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 acohen @ cs.rutgers.edu – Xiaoye xiaoye @ cs.rutgers.edu

slide-2
SLIDE 2

CS107, Prof. Steinberg, f10

2

Lecture 01

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 naderb@cs.rutgers.edu

slide-3
SLIDE 3

CS107, Prof. Steinberg, f10

3

Lecture 01

CS107: Computing for Math CS107: Computing for Math and Science and Science

  • Course will use the computer for

communication and instruction as much as possible

slide-4
SLIDE 4

CS107, Prof. Steinberg, f10

4

Lecture 01

Class Web Pages Class Web Pages

  • http://

http://remus remus. .rutgers rutgers. .edu edu/CS107 /CS107

– Policies – Syllabus – Assignments – Lecture notes – etc....

– You are assumed to know anything

posted.

slide-5
SLIDE 5

CS107, Prof. Steinberg, f10

5

Lecture 01

Class Web Pages Class Web Pages

  • Sakai:

Sakai: cs cs 107, Fall 2010 107, Fall 2010

– Announcements – Posting grades – Chat room – Etc.

– You are assumed to know anything

posted.

slide-6
SLIDE 6

CS107, Prof. Steinberg, f10

6

Lecture 01

What is CS107? What is CS107?

  • A course about using computers
  • Aimed at majors in Math and Science
  • After this class you should know
  • Methods for using the computer that will be useful

for mathematicians & scientists

  • Some key ideas in computer science
  • CS 107 does not prepare you to take further

courses in the CS Dept.

slide-7
SLIDE 7

CS107, Prof. Steinberg, f10

7

Lecture 01

Prerequisite Prerequisite

  • Calc I

– 640:135 or 151 or 153 or 191 – Grade of C or better

  • No previous programming experience is

assumed

  • We will assume you do know how to use a

mouse, web browser, etc.

slide-8
SLIDE 8

CS107, Prof. Steinberg, f10

8

Lecture 01

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

slide-9
SLIDE 9

CS107, Prof. Steinberg, f10

9

Lecture 01

Grade based on Grade based on

  • Homework
  • Midterm exam
  • In-lecture quizzes
  • Final exam
slide-10
SLIDE 10

CS107, Prof. Steinberg, f10

10

Lecture 01

Textbooks Textbooks

Introduction to Scientific Computation and Programming

Daniel T Kaplan Brooks/Cole

The Maple Book

Frank Garman Chapman & Hall/CRC

slide-11
SLIDE 11

CS107, Prof. Steinberg, f10

11

Lecture 01

What is a computer? What is a computer?

slide-12
SLIDE 12

CS107, Prof. Steinberg, f10

12

Lecture 01

What is a computer? What is a computer?

  • A machine that follows instructions
  • Note the anthropomorphism here
slide-13
SLIDE 13

CS107, Prof. Steinberg, f10

13

Lecture 01

Anthropomorphism: Anthropomorphism:

Use of a term normally applied to people when speaking of something that is not a person

  • An analogy
  • Useful but dangerous

– What is the same – What is different

slide-14
SLIDE 14

CS107, Prof. Steinberg, f10

14

Lecture 01

How can a machine follow How can a machine follow instructions? instructions?

  • Example: Washing machine controller

– Controls hot water, cold water, drain, motor

slide-15
SLIDE 15

CS107, Prof. Steinberg, f10

15

Lecture 01

Hot Wash, Warm Rinse Hot Wash, Warm Rinse

C M D H

Peg No Peg

slide-16
SLIDE 16

CS107, Prof. Steinberg, f10

16

Lecture 01

Washing Machine Instructions Washing Machine Instructions

  • A pattern of physical objects (pegs)

– Physically causes the specified behavior

slide-17
SLIDE 17

CS107, Prof. Steinberg, f10

17

Lecture 01

Computer Computer Instructions Instructions

  • A pattern of electrical voltages

– Physically causes the specified behavior

5 volts

Random Access Memory

0 volts

slide-18
SLIDE 18

CS107, Prof. Steinberg, f10

18

Lecture 01

  • People can read, write, think about the

pattern without really having the pegs

  • Patterns can be thought of as a language

for expressing washing machine instructions

Washing Machine Language Washing Machine Language

slide-19
SLIDE 19

CS107, Prof. Steinberg, f10

19

Lecture 01

Anthropomorphism Alert Anthropomorphism Alert

  • How is washing machine language like a

human (“natural”) language?

  • How is it different?
slide-20
SLIDE 20

CS107, Prof. Steinberg, f10

20

Lecture 01

  • People can read, write, think about the

pattern without really having the voltages

  • Patterns can be thought of as a language

for expressing computer instructions

Computer Computer Machine Language Machine Language

slide-21
SLIDE 21

CS107, Prof. Steinberg, f10

21

Lecture 01

Washing Machine Languages Washing Machine Languages

  • Each washing machine operation does a

very small amount of work

  • People would find it tedious and error

prone to instruct their washers in this language

  • So, we have a higher level language

– Warm wash, cold rinse

slide-22
SLIDE 22

CS107, Prof. Steinberg, f10

22

Lecture 01

Computer Computer Languages Languages

  • Each computer operation does a

very small amount of work

  • People would find it tedious and error

prone to instruct their computers in this language

  • So, we have a higher level language

– Matlab – Java, Basic, Fortran, C, Lisp, ...

slide-23
SLIDE 23

CS107, Prof. Steinberg, f10

23

Lecture 01

Washing Machine Languages Washing Machine Languages

  • There is a fixed set of primitive operations

– Hot, Cold, Drain, Motor

  • And a way of combining operations

– Rows obeyed in sequence

  • We have to build behavior we want out of

the primitives available

– Hot + Cold => Warm

slide-24
SLIDE 24

CS107, Prof. Steinberg, f10

24

Lecture 01

Computer Computer Languages Languages

  • There is a fixed set of primitive operations
  • And a way of combining operations
  • We have to build behavior we want out of

the primitives available

slide-25
SLIDE 25

CS107, Prof. Steinberg, f10

25

Lecture 01

Is a Washing Machine a Is a Washing Machine a Computer? Computer?

  • A computer is a machine that

follows instructions and processes data

slide-26
SLIDE 26

CS107, Prof. Steinberg, f10

26

Lecture 01

Data Data

  • Numbers, words, pictures, …
  • Data processing

– What Kaplan text calls “computation” – Any process that transforms some data into

  • ther data, e.g. addition
slide-27
SLIDE 27

CS107, Prof. Steinberg, f10

27

Lecture 01

Representation Representation

  • In a computer, data embodied as charge
  • r voltage

– E.g.: 0 volts means 0, 5 volts means 1 – A “bit”: a 2-way choice, e.g. 0 volts vs 5 volts

  • Data is represented by groups of bits

– E.g.: 3 bits gives 8 patterns: 000 001 010 011 100 101 110 111

slide-28
SLIDE 28

CS107, Prof. Steinberg, f10

28

Lecture 01

Translation Translation

  • Problem: pegs & switches understand
  • nly machine language
  • How can we get instructions in higher

level language obeyed?

  • Translation:

– “warm wash, cold rinse” dial selects a set of pegs

slide-29
SLIDE 29

CS107, Prof. Steinberg, f10

29

Lecture 01

Translation Translation

  • Problem: transistors understand only

machine language

  • How can we get instructions in higher

level language obeyed?

  • Translation:

– Instructions are also data – A program does the translation

slide-30
SLIDE 30

CS107, Prof. Steinberg, f10

30

Lecture 01

Grammar Grammar

  • To make it easier to translate, a program

must have a structure that obeys a grammar

– simple but rigid rules

slide-31
SLIDE 31

CS107, Prof. Steinberg, f10

31

Lecture 01

A Program A Program

is more like a mechanism you build than a sentence you say.

slide-32
SLIDE 32

CS107, Prof. Steinberg, f10

32

Lecture 01

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

slide-33
SLIDE 33

CS107, Prof. Steinberg, f10

33

Lecture 01

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

slide-34
SLIDE 34

CS107, Prof. Steinberg, f10

34

Lecture 01

To Construct a Program To Construct a Program

Is 5% “Know that” and 95% “Know how”

slide-35
SLIDE 35

CS107, Prof. Steinberg, f10

35

Lecture 01

Learning Learning “ “Knowing How Knowing How” ”

  • 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

slide-36
SLIDE 36

CS107, Prof. Steinberg, f10

36

Lecture 01

Extra Help Extra Help

  • For some people writing a program is very

hard.

– Even some people who do very well in other courses

  • Extra help will be available

– See Prof. Steinberg or a TA – Do so as soon as possible if you find the homework extremely hard

  • Everyone should be able to pass this class, with

hard work.

slide-37
SLIDE 37

CS107, Prof. Steinberg, f10

37

Lecture 01

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

slide-38
SLIDE 38

CS107, Prof. Steinberg, f10

38

Lecture 01

Matlab Matlab as a Calculator as a Calculator

  • 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
slide-39
SLIDE 39

CS107, Prof. Steinberg, f10

39

Lecture 01

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.
slide-40
SLIDE 40

CS107, Prof. Steinberg, f10

40

Lecture 01

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

slide-41
SLIDE 41

CS107, Prof. Steinberg, f10

41

Lecture 01

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

slide-42
SLIDE 42

CS107, Prof. Steinberg, f10

42

Lecture 01

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

slide-43
SLIDE 43

CS107, Prof. Steinberg, f10

43

Lecture 01

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)

slide-44
SLIDE 44

CS107, Prof. Steinberg, f10

44

Lecture 01

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

slide-45
SLIDE 45

CS107, Prof. Steinberg, f10

45

Lecture 01

Matlab Matlab Programs Programs

  • A Matlab program is made up of

statements

– One per line

  • One kind of statement is:

Assignment statement

slide-46
SLIDE 46

CS107, Prof. Steinberg, f10

46

Lecture 01

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

slide-47
SLIDE 47

CS107, Prof. Steinberg, f10

47

Lecture 01

Assignment statement Assignment statement

  • May end with ; to prevent printing the

value of the expression

degreesF = 72;

slide-48
SLIDE 48

CS107, Prof. Steinberg, f10

48

Lecture 01

What does this do? What does this do?

x = 4 + 5 y = x + 3 z = 6 .* 2 x = 1 x = x + 3

slide-49
SLIDE 49

CS107, Prof. Steinberg, f10

49

Lecture 01

What does this do? What does this do?

total = 0; total = total + 5; total = total + 8; total = total + 7

slide-50
SLIDE 50

CS107, Prof. Steinberg, f10

50

Lecture 01

Getting help Getting help

  • The help command gets help, e.g. -

> help + gets help on the + operator

  • Also, under the Help menu, select

Product Help, type sum in “search for” box

slide-51
SLIDE 51

CS107, Prof. Steinberg, f10

51

Lecture 01

No Recitation this week No Recitation this week