Post on 10-Mar-2020
CS107, Prof. Steinberg, f10 1Lecture 01
CS107: Computing for MathCS107: Computing for Mathand Scienceand 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
CS107, Prof. Steinberg, f10 2Lecture 01
CS107: Computing for MathCS107: Computing for Mathand Scienceand Science
• Instructor: Prof. Apostolos Gerasoulis– office: Core 328– email: grasoul@cs.rutgers.edu– Office hours: by appointment
• TA:– Nader Boushehrinejadmoradi
naderb@cs.rutgers.edu
CS107, Prof. Steinberg, f10 3Lecture 01
CS107: Computing for MathCS107: Computing for Mathand Scienceand Science
• Course will use the computer forcommunication and instruction as muchas possible
CS107, Prof. Steinberg, f10 4Lecture 01
Class Web PagesClass Web Pages•• http://http://remusremus..rutgersrutgers..eduedu/CS107/CS107
– Policies– Syllabus– Assignments– Lecture notes– etc....
– You are assumed to know anythingposted.
CS107, Prof. Steinberg, f10 5Lecture 01
Class Web PagesClass Web Pages•• Sakai: Sakai: cscs 107, Fall 2010 107, Fall 2010
– Announcements– Posting grades– Chat room– Etc.
– You are assumed to know anythingposted.
CS107, Prof. Steinberg, f10 6Lecture 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 furthercourses in the CS Dept.
CS107, Prof. Steinberg, f10 7Lecture 01
PrerequisitePrerequisite• Calc I– 640:135 or 151 or 153 or 191– Grade of C or better
• No previous programming experience isassumed
• We will assume you do know how to use amouse, web browser, etc.
CS107, Prof. Steinberg, f10 8Lecture 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
CS107, Prof. Steinberg, f10 9Lecture 01
Grade based onGrade based on• Homework• Midterm exam• In-lecture quizzes• Final exam
CS107, Prof. Steinberg, f10 10Lecture 01
TextbooksTextbooksIntroduction to Scientific
Computation andProgrammingDaniel T KaplanBrooks/Cole
The Maple BookFrank GarmanChapman & Hall/CRC
CS107, Prof. Steinberg, f10 11Lecture 01
What is a computer?What is a computer?
CS107, Prof. Steinberg, f10 12Lecture 01
What is a computer?What is a computer?• A machine that follows instructions• Note the anthropomorphism here
CS107, Prof. Steinberg, f10 13Lecture 01
Anthropomorphism:Anthropomorphism:Use of a term normally applied to
people when speaking of something that isnot a person
• An analogy• Useful but dangerous
– What is the same– What is different
CS107, Prof. Steinberg, f10 14Lecture 01
How can a machine followHow can a machine followinstructions?instructions?
• Example: Washing machine controller– Controls hot water, cold water, drain, motor
CS107, Prof. Steinberg, f10 15Lecture 01
Hot Wash, Warm RinseHot Wash, Warm Rinse
C MDH Peg
No Peg
CS107, Prof. Steinberg, f10 16Lecture 01
Washing Machine InstructionsWashing Machine Instructions• A pattern of physical objects (pegs)– Physically causes the specified behavior
CS107, Prof. Steinberg, f10 17Lecture 01
ComputerComputer Instructions Instructions• A pattern of electrical voltages
– Physically causes the specified behavior
5 voltsRandom Access Memory
0 volts
CS107, Prof. Steinberg, f10 18Lecture 01
• People can read, write, think about thepattern without really having thepegs
• Patterns can be thought of as a languagefor expressing washing machineinstructions
Washing Machine LanguageWashing Machine Language
CS107, Prof. Steinberg, f10 19Lecture 01
Anthropomorphism AlertAnthropomorphism Alert• How is washing machine language like a
human (“natural”) language?• How is it different?
CS107, Prof. Steinberg, f10 20Lecture 01
• People can read, write, think about thepattern without really having thevoltages
• Patterns can be thought of as a languagefor expressing computerinstructions
ComputerComputer Machine Language Machine Language
CS107, Prof. Steinberg, f10 21Lecture 01
Washing Machine LanguagesWashing 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 inthis language
• So, we have a higher level language– Warm wash, cold rinse
CS107, Prof. Steinberg, f10 22Lecture 01
ComputerComputer Languages Languages• Each computer operation does a
very small amount of work• People would find it tedious and error
prone to instruct their computers inthis language
• So, we have a higher level language– Matlab– Java, Basic, Fortran, C, Lisp, ...
CS107, Prof. Steinberg, f10 23Lecture 01
Washing Machine LanguagesWashing 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 ofthe primitives available– Hot + Cold => Warm
CS107, Prof. Steinberg, f10 24Lecture 01
ComputerComputer Languages Languages• There is a fixed set of primitive operations
• And a way of combining operations
• We have to build behavior we want out ofthe primitives available
CS107, Prof. Steinberg, f10 25Lecture 01
Is a Washing Machine aIs a Washing Machine aComputer?Computer?
• A computer is a machine thatfollows instructionsand processes data
CS107, Prof. Steinberg, f10 26Lecture 01
DataData• Numbers, words, pictures, …• Data processing– What Kaplan text calls “computation”– Any process that transforms some data into
other data, e.g. addition
CS107, Prof. Steinberg, f10 27Lecture 01
RepresentationRepresentation• In a computer, data embodied as charge
or 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
CS107, Prof. Steinberg, f10 28Lecture 01
TranslationTranslation• Problem: pegs & switches understand
only machine language• How can we get instructions in higher
level language obeyed?• Translation:– “warm wash, cold rinse” dial selects a set of
pegs
CS107, Prof. Steinberg, f10 29Lecture 01
TranslationTranslation• 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
CS107, Prof. Steinberg, f10 30Lecture 01
GrammarGrammar• To make it easier to translate, a program
must have a structure that obeys agrammar– simple but rigid rules
CS107, Prof. Steinberg, f10 31Lecture 01
A ProgramA Programis more like a mechanism you buildthan a sentence you say.
CS107, Prof. Steinberg, f10 32Lecture 01
Kinds of KnowledgeKinds 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 33Lecture 01
E.G., AlgebraE.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 equation3*x - 5 + 5 = 10 + 53*x = 15
CS107, Prof. Steinberg, f10 34Lecture 01
To Construct a ProgramTo Construct a ProgramIs 5% “Know that” and95% “Know how”
CS107, Prof. Steinberg, f10 35Lecture 01
Learning Learning ““Knowing HowKnowing 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
CS107, Prof. Steinberg, f10 36Lecture 01
Extra HelpExtra 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.
CS107, Prof. Steinberg, f10 37Lecture 01
MatlabMatlab• 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 38Lecture 01
Matlab Matlab as a Calculatoras 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
CS107, Prof. Steinberg, f10 39Lecture 01
OperationsOperations• 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 40Lecture 01
VariablesVariables• 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 41Lecture 01
VariablesVariables• 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 42Lecture 01
Using VariablesUsing 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 = 72degreesC = (degreesF - 32) .* 5 ./ 9
CS107, Prof. Steinberg, f10 43Lecture 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)
CS107, Prof. Steinberg, f10 44Lecture 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 = 2root = 2>> root = (root + 5 ./ root) ./ 2root = 2.2500>> root = (root + 5 ./ root) ./ 2root = 2.2361>> root .* rootans = 5.0000
CS107, Prof. Steinberg, f10 45Lecture 01
Matlab Matlab ProgramsPrograms• A Matlab program is made up of
statements– One per line
• One kind of statement is:Assignment statement
CS107, Prof. Steinberg, f10 46Lecture 01
Assignment statementAssignment 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 47Lecture 01
Assignment statementAssignment statement• May end with ; to prevent printing the
value of the expressiondegreesF = 72;
CS107, Prof. Steinberg, f10 48Lecture 01
What does this do?What does this do? x = 4 + 5 y = x + 3 z = 6 .* 2 x = 1 x = x + 3
CS107, Prof. Steinberg, f10 49Lecture 01
What does this do?What does this do? total = 0; total = total + 5; total = total + 8; total = total + 7
CS107, Prof. Steinberg, f10 50Lecture 01
Getting helpGetting 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
CS107, Prof. Steinberg, f10 51Lecture 01
No Recitation this weekNo Recitation this week