{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture03 (1)

# lecture03 (1) - CS107 Computing for Math CS107 and Science...

This preview shows pages 1–13. Sign up to view the full content.

CS107, Prof. Steinberg, S10 Lecture 03 CS107: Computing for Math CS107: Computing for Math and Science and Science Lecture 03: Functions

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS107, Prof. Steinberg, S10 Lecture 03 Matlab Matlab Matlab is: A programming language A library of programs An Interactive Development Environment (IDE)
CS107, Prof. Steinberg, S10 Lecture 03 Matlab as a Calculator Matlab as a Calculator You type an expression Matlab Reads what you typed Evaluates the expression and Prints the result

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS107, Prof. Steinberg, S10 Lecture 03 Expressions Expressions Expressions contain Numbers 3 -24.15 6.022e23 Operators Infix, eg .* ./ + - 1+4 Prefix, eg mod sqrt sqrt( 4 ) Variables
CS107, Prof. Steinberg, S10 Lecture 03 Variables Variables A variable is a place in the computer to store a piece of data Has a name, e.g. age, year, area, … Has a value, which can be changed When a variable appears in an expression, it means the current value large 98 17 + large means 17 + 98

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS107, Prof. Steinberg, S10 Lecture 03 Why use a variable? Why use a variable? To save and reuse a value instead of recomputing it totTaxRate .* salary1 totTaxRate .* salary2
CS107, Prof. Steinberg, S10 Lecture 03 Why use a variable? Why use a variable? To keep track of current state in a sequential calculation Eg cube root of 5 x =5 x = x - (x.^3-5)/(2.*x.^2); x = x - (x.^3-5)/(2.*x.^2); x = x - (x.^3-5)/(2.*x.^2);

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS107, Prof. Steinberg, S10 Lecture 03 Matlab Programs Matlab Programs A Matlab program is made up of statements One per line One kind of statement is the Assignment statement
CS107, Prof. Steinberg, S10 Lecture 03 Assignment statement Assignment statement Purpose: store a piece of data in a variable Form: variableName = expression Meaning: evaluate expression , store resulting value in variable with name variableName , print the value With ; at end do not print

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS107, Prof. Steinberg, S10 1 Lecture 03 Beware the Mathomorphism Beware the Mathomorphism An assignment statement is not an equation An assignment statement says: Compute the value of this expression Store that value in this variable Nothing more, nothing less
CS107, Prof. Steinberg, S10 1 Lecture 03 Grammatical Structure Grammatical Structure An assignment statement has parts cost = nonTaxable + taxable .* 1.065 Variable name Expression

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS107, Prof. Steinberg, S10 1
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern