MatlabTutorial_9_20

MatlabTutorial_9_20 - CME 100 Vector Calculus for Engineers...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CME 100 Vector Calculus for Engineers Prof. Eric Darve TA: Mavis Li Matlab Tutorial Handout 1 Help For help on a particular function, type ‘help <function name>’. For documentation on the function, type ‘doc <function name>’ Basic Arithmetic We can use Matlab for simple arithmetic. examples >> 5+7 ans = 12 >> 1432-55 ans = 1377 >> 3*127 ans = 381 >> 4^5 ans = 1024 >> 72/55 ans = 1.3091 >> exp(1) ans = 2.7183 Variables Variables keep track of the values we use in programs. We will discuss a simple example using variables. Example Let the variable wallet represent the amount of money in your wallet. Let pen , notebook , and paycheck be the corresponding values for each. Suppose we first buy two pens, then buy a notebook and then receive a paycheck. (In Matlab, a semicolon after your expression suppresses the output.) >> wallet=20; >> pen=1; >> notebook=3; >> paycheck=30; >> wallet=wallet-2*pen wallet = 18 >> wallet=wallet-notebook wallet = 15 >> wallet=wallet+paycheck
Background image of page 1

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

View Full DocumentRight Arrow Icon
wallet = 45 The “=” sign here is different than in mathematics. Here, it represents a new assignment to the variable wallet . Matlab first evaluates the expression on the right hand side, then assigns the resulting value to the variable on the left hand side. Note that wallet is used twice in these expressions. The wallet on the right hand side takes on the current value of wallet . The wallet on the left hand side takes on the newly assigned value. For this example, we start off with
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

MatlabTutorial_9_20 - CME 100 Vector Calculus for Engineers...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online