{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
CS107, Prof. Steinberg, S10 Lecture 03 CS107: Computing for Math CS107: Computing for Math and Science and Science Lecture 03: Functions
Image of page 1

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

View Full Document Right Arrow Icon
CS107, Prof. Steinberg, S10 Lecture 03 Matlab Matlab Matlab is: A programming language A library of programs An Interactive Development Environment (IDE)
Image of page 2
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
Image of page 3

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

View Full Document Right Arrow Icon
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
Image of page 4
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
Image of page 5

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

View Full Document Right Arrow Icon
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
Image of page 6
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);
Image of page 7

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

View Full Document Right Arrow Icon
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
Image of page 8
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
Image of page 9

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

View Full Document Right Arrow Icon
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
Image of page 10
CS107, Prof. Steinberg, S10 1 Lecture 03 Grammatical Structure Grammatical Structure An assignment statement has parts cost = nonTaxable + taxable .* 1.065 Variable name Expression
Image of page 11

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

View Full Document Right Arrow Icon
CS107, Prof. Steinberg, S10 1
Image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern