5p. Intro to Matlab _printable_

5p. Intro to Matlab _printable_ - Introduction to Matlab...

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

View Full Document Right Arrow Icon
1 ©2009 by L. Lagerstrom Introduction to Matlab • Numbers • Operators • The Command Window • Chaining operations • Syntax errors • Precedence of operations • Variables and assignment statements • Mathematical functions • Punctuation: semi-colons, commas, and ellipses ©2009 by L. Lagerstrom Numbers in Matlab Numbers in Matlab may be entered in either fixed point or floating point format. Fixed point examples: 2.639, -827, 0.000023. Floating point examples: 4.39e5, 4.39E5, 245.8e-2. Note that "e" or "E" here stands for power-of-10 exponent and does NOT refer to the exponential function e x . In other words, 4.39e5 in Matlab means (4.39)(10 5 ) in regular math notation. Remember also that we call the 4.39 part the "mantissa." (We'll learn how to use the exponential function a little later.) ©2009 by L. Lagerstrom Math Operators Matlab has the usual math operators: • Addition: 5 + 8 • Subtraction: 9 - 4 • Multiplication: 5*7 (i.e., an asterisk) • Division: 56/8 (i.e., a slash) • Exponentiation: 7^2 (i.e., a caret symbol; note that 7^2 is 7 squared) In addition to the regular / operator for division, there is also a \ (backslash) operator, called the "left division" operator. (And the regular / operator is the "right division" operator.) When we write 8\56 it means "8 divided into 56." That is, 8\56 is the same as 56/8. (The reason for the left division operator will become clear when we cover solving systems of linear equations.) ©2009 by L. Lagerstrom The Matlab Command Window When you start Matlab, the first window you will usually see is the "Command Window" with a ">>" prompt. You may enter math expressions at the prompt and then press the Enter key to have Matlab execute them. The results will be displayed as shown below. (The "ans" stands for "answer.") Examples: >>5 + 8 ans = 13 >>3*7 ans = 21
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 ©2009 by L. Lagerstrom Interpreting Our Examples It's very important to understand what's going on in an example like that below, so that you don't get confused with our later examples. The ">>5 + 8" line means that we have typed "5 + 8" at the >> prompt in the Matlab Command window. (Sometimes we just call it the "command prompt".) We then press the Enter key to enter that expression, causing Matlab to execute it. After it executes it, Matlab displays the result (the "ans = 13" part). >>5 + 8 ans = 13 ©2009 by L. Lagerstrom A Note re. Decimal Places Later we will cover in detail how Matlab displays numbers regarding number of decimal places, etc. For now, just understand that if the result is an exact integer, then it is displayed as such with no decimal part. If it's not an exact integer, then the decimal part is displayed up to four decimal places, rounded appropriately. (This is known as "format short.")
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.

This note was uploaded on 02/23/2010 for the course ENG 42325 taught by Professor Lagerstrom during the Spring '10 term at UC Davis.

Page1 / 9

5p. Intro to Matlab _printable_ - Introduction to Matlab...

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