introduction to computing ui m lbusing · pdf fileintroduction to computing ui m lbusing...

35
Introduction to Computing U i M lb Using Matlab CS 1112 Fall 2012 (CS1142) (CS1142) Dr. K.-Y. Daisy Fan http://www.cs.cornell.edu/courses/cs1112/

Upload: buinhu

Post on 05-Feb-2018

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

Introduction to ComputingU i M l bUsing Matlab

CS 1112 Fall 2012(CS1142)(CS1142)

Dr. K.-Y. Daisy Fan

http://www.cs.cornell.edu/courses/cs1112/

Page 2: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

Today’s lecture

An illuminating problem CS1112 philosophies & syllabus CS1112 philosophies & syllabus What is computer programming? Choosing between CS1112 & CS1110 Course logistics/policies (highlights)g p ( g g )

How about CS1115? Introduction to How about CS1115? Introduction to Computational Science and Engineering Using Matlab Graphical User Interfaces

Lecture 1 4

Matlab Graphical User Interfaces

Page 3: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

An illuminating problem: computing square roots

Suppose A > 0

Observation: If A is the area of a square, then I can just measure the side length—that is Ag

Idea: Make a square with area AIdea: Make a square with area A

Real task: Make a sequence of increasingly square Real task: Make a sequence of increasingly square rectangles, each with area A

Lecture 1 5

Page 4: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

How to make a rectangle “more square”?

If a square and a rectangle both have area A …

then is between the length and width of the rectangle

Arectangle

Lecture 1 6

Page 5: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

An improvement strategy

A/LCurrent:

L

Recipe: Lnew = (L + A/L) / 2The average of the length andwidth.

A/LNext: A/Lnew

Lnew

Page 6: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

A Matlab program to make “increasingly square” rectangles

% The first rectangle...L1 = A;W1 = 1;% The second rectangle...gL2 = (L1+W1)/2;W2 = A/L2;/ ;% The third rectangle...L3 = (L2+W2)/2;L3 (L2+W2)/2;W3 = A/L3;% and so on

Lecture 1 8

% and so on...

Page 7: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

The progression of rectangles with area 10The progression of rectangles with area 10

Length WidthLength Width9.000000000000000 1.0000000000000005.000000000000000 1.8000000000000003.400000000000000 2.6470588235294123.023529411764706 2.9766536964980553.000091554131380 2.9999084486625883.000000001396984 2.999999998603016

Page 8: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

Some conclusions from square root finding problem

It paid to have a geometric sense A complicated computation was reduced to a A complicated computation was reduced to a

sequence of elementary calculationsA i lik f l ( f A program is like a formula (or sequence of formulas)

Lecture 1 10

Page 9: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

Course Goals

Develop your “computational senses ” senses that Develop your computational senses, senses that you need in computer problem-solving

Develop a facility with the Matlab programming environment

Lecture 1 11

Page 10: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

A sense of geometry

Lecture 1 12

Page 11: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

A sense of complexityWhat is the best What is the best

itinerary to visit Boston, Miami, LA, Dallas?3! = 6 possibilities

Add Seattle, NYC Austin, Denver7! = 5040

If a computer can process 1 billion itineraries a second, how long does it take to solve a 100-city problem?

Lecture 1 13

g y p

Page 12: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

A sense of complexityWhat is the best What is the best

itinerary to visit Boston, Miami, LA, Dallas?3! = 6 possibilities

Add Seattle, NYC Austin, Denver7! = 5040

If a computer can process 1 billion itineraries a second, how long does it take to solve a 100-city problem?g y p

About a century…

Page 13: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

A sense of approximation & error

1/3 = 333331/3 = .33333…

Lecture 1 15

Page 14: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

A sense of randomness and probability

Random walkRandom walkBrownian motion in water

Lecture 1 16

Page 15: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

Course Goals

Develop your “computational senses ” senses that Develop your computational senses, senses that you need in computer problem-solving

Develop a facility with the Matlab programming environment

Lecture 1 17

Page 16: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

Computer problem-solving

Key: Algorithmic thinking

Algorithm:A step by step procedure that takes you from a A step-by-step procedure that takes you from a prescribed set of inputs to a prescribed set of outputsoutputs

Program:Program:The algorithm expressed in a specific language, e.g., Matlab

Lecture 1 18

Matlab

Page 17: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

Computer problem-solving — Programming

Developing instructions for the computer to execute (in order to solve some problem)execute (in order to solve some problem)

The steps must be logicalU i l l d f ll h l f h Use a particular language and follow the rules of the language (grammar/syntax)

Lecture 1 19

Page 18: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

Example: Adding songs from the internet to your music library

Find a website with MP3 or other audio files Register with the music site if required for music Register with the music site, if required for music

downloading. (Don’t steal music.)Cli k h i fil d l d i Click on the music file to download it onto your computer

Drag the file to your library

Reference: iTunes

Lecture 1 20

Page 19: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

Example: Adding songs from the internet to your music library

Drag the file to your library Click on a music file to download it onto your Click on a music file to download it onto your

computerFi d b i i h MP3 h di fil Find a website with MP3 or other audio files

Register with the music site, if required for music downloading. (Don’t steal music.)

Lecture 1 21

Page 20: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

Example: Adding songs from the internet to your music library

Find a website with MP3 or other audio files Register with the music site if required for music Register with the music site, if required for music

downloading. (Don’t steal music.)Cli k h i fil d l d i Click on the music file to download it onto your computer

Drag the file to your library

Reference: iTunes

Lecture 1 22

Page 21: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

Example: Adding songs from the internet to your music library

Find a website with MP3 or other audio files Register with the music site if required for music Register with the music site, if required for music

downloading. (Don’t steal music.)Cli k h i fil d Nl d i Click on the music file to dowNload it onto your computer

file Drag your librAry to

Lecture 1 23

Page 22: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

Computer programming is …

a tool used by computer scientists, engineers, and other professionalsother professionals

not all of computer science

Think about astronomy: Telescope is a tool used by astronomers; astronomy is not about telescopes…

Lecture 1 24

Page 23: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

Matlab is the vehicle we use

With the Matlab environment, you can easily Develop programs Develop programs Display results & ideas graphically Interact with large data sets (process text,

image, and other files)

Matlab has extensive libraries of mathematical, statistical simulation and other tools It is heavily statistical, simulation, and other tools. It is heavily used in engineering & sciences, both in industry and academia

Lecture 1 27

academia.

Page 24: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

Engineering students take one of these courses:

CS1112 – this course, Matlab CS1115 Matlab + GUI CS1115 – Matlab + GUI CS1110 – PythonEach course satisfies the Engineering Computing Requirement. You will learn procedural programming in depth and be introduced to object-oriented programming.Each course can serve as the prerequisite for CS/ENGRD 2110 Object-Oriented Programming &

Lecture 1 28

j g gData Structure

Page 25: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

CS1112 has a focus on computational science & engineering

Approximation, randomness, model building, sensitivity of modelsmodel building, sensitivity of models

L t l d h k ill t t b Lecture examples and homework illustrate above themes

Ed d iEdge detectionRanking web pages Congressional apportionment

Lecture 1 29

Page 26: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

Some past programming assignments

Find the US population center from census data

Draw the random Mondrian

Organize protein data using structure arrays

Pyramid of Khufu Egypt Scale is 5 54 feet per unit length on axes

Draw the “Betsy Ross Flag”

Mozart’s musical dice gamePyramid of Khufu, Egypt Scale is 5.54 feet per unit length on axes

Select a path using multiple mouse clicks. Click outside the map to stop.Total distance: 8379.3 feet

100

200

300

400

500

600

700

Path distance tool(like that in Google Earth)

Lecture 1 30100 200 300 400 500 600 700 800 900 1000

800

900

Root finding tool

Page 27: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

CS1110 – Now in Python

Switched from Java to Python because Python is a friendlier and more modern object-oriented friendlier and more modern object oriented language.

Python is more relevant to non computer Python is more relevant to non-computer scientists than Java—numerical libraries are availableavailable

Matlab and Python are just different vehicles we Conducive to discussion of design

y juse to travel the “computational landscape.”Different scenery along the way

Lecture 1 31

y g yBoth vehicles get you there

Page 28: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

CS1112 CS1110

No prior programming

No prior programming programming

experience One semester of

programming experience

No CalculusCalculus

Focus on Focus on software computational science & engineering

development

Matlab Java

Lecture 1 33

Page 29: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

CS1115 Intro to Computational Science & Engineering Using Matlab Graphical User Interfacesg p

A faster-paced course that teaches programming c nce ts thr h the de el ment f Gra hical concepts through the development of Graphical User Interfaces (GUIs)

f CS 2 G Think of it as CS1112 + GUIs Not an honors course, but the introduction of

GUIs is possible because students come with some programming experience

Pre-req: a Calculus course and some programming q p g gexperience in any programming language

Lecture 1 34

Page 30: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

CS1112 requirements

Attend lecture Attend discussion—get individual attention/help on Attend discussion get individual attention/help on

weekly exercises! Monitor course announcements on website Do homework: best 5 of 6 programming projects Take 2 prelims and a final exam at their scheduled timesTake 2 prelims and a final exam at their scheduled times Answer in-class quizzes (use your clicker) Adhere to the Code of Academic Integrity Adhere to the Code of Academic Integrity

Lecture 1 38

Page 31: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

Grading

Best five of six projects (25%)Di i i (4%) Discussion exercises (4%)

In-class quizzes (1%) Prelim 1 (20%) Prelim 2 (20%)Prelim 2 (20%) Final exam (30%)

Lecture 1 39

Page 32: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

Course Materials

Insight Through ComputingA Matlab introduction to Computationals Science A Matlab introduction to Computationals Science and Engineering

An iClicker clicker An iClicker clicker

MATLAB Student Version (2008 or later) optional because you can use

Lecture 1 40

later) optional because you can use it in the public labs

Page 33: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

Consulting & Computing

Consulting in ACCEL Green Room (Engineering Library, Carpenter Hall). Check course website Library, Carpenter Hall). Check course website for hours.

Some public labs that have Matlab: Upson B-7 ACCEL

(Carpenter Hall, former Engrg Lib)

North campus: RPCC

Lecture 1 41

Page 34: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

What to do now?

Pick a courseTake CS1112 CS1110 or CS1115Take CS1112, CS1110, or CS1115(add/drop: lecture and discussion and AEW)

Ch k b i Check course website Start reading (see listing on course website) Attend discussion in the lab (Upson B7) on

Tues/Wed You must attend the discussion in which you are

enrolled!

Lecture 1 42

enrolled!

Page 35: Introduction to Computing Ui M lbUsing · PDF fileIntroduction to Computing Ui M lbUsing Matlab CS 1112 Fall 2012 ... then I can just ... 205 W 10:10-11:00a UPS B7 Right & HLS 401

CS1112 Discussion Sections

Sec # Time Room201 T 12:20-1:10p UPS B7 Right & HLS 314

202 T 1 25 2 15 UPS B7 Ri ht & HLS 314202 T 1:25-2:15p UPS B7 Right & HLS 314

203 T 2:30-3:20p UPS B7 Right & HLS 401

204 T 3:35-4:25p UPS B7 Right & HLS 401

205 W 10:10-11:00a UPS B7 Right & HLS 401

206 W 11:15a-12:05p UPS B7 Right & HLS 401

207 W 12 20 1 10 UPS B7 Ri h & HLS 401207 W 12:20-1:10p UPS B7 Right & HLS 401

208 W 1:25:2:15p UPS B7 Right & HLS 401

209 W 2:30-3:20p UPS B7 Right & HLS 314p g

210 W 3:35-4:25p UPS B7 Right & HLS 314

211 W 7:30-8:20p UPS B7 Right & HLS 401

Lecture 1 45

Discussions are held in UPS B7 the first two weeks