This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Lecture 2 – August 26, 2010 Agenda: • Introduction to MATLAB (continued) order of operations arrays (one and twodimensional) function handles • Inclass exercise 2 (submit to WebCT) MATLAB: Basic Formatting format compact single spaces all text output clear clears all stored variables in the workspace clear x y z clears only variables x , y , and z clear a* clears only variables starting with a home returns command prompt to the top of the screen clc clears the command window prior to home ; suppresses output/multiple entries per line , multiple entries per line % blah comment ( green text following isn’t evaluated) 3.1e6 = 3.1 × 10 6 = 3,100,000 (large number entry) 2.03e4 = 2.03 × 104 = 0.000203 (small number entry) MATLAB: Order of Operations 1. ( ) contents within parentheses, including functions 2. ^ exponentiation 3. *,/,\ multiplication and (left, right) division 4. +, addition and subtraction Note : this order is true of equivalent matrix operations as well as we’ll discuss Example : >> 2*cos(2*pi/3 + 0.5)^2 + 1 1. 2*cos(2.5944)^2 + 1 argument of the cosine first 2. 2*(0.8540)^2 + 1 function second 3. 2*0.7293 + 1 exponent third 4. 1.4586 + 1 multiplication fourth 5. 2.4586 addition last and final result MATLAB: Assignment Assignment: assigning values to variable names • variable names are casesensitive (you can have a and A ) • there are a few variables that have predefined values: pi (3.14159…), i ( ), j ( ) note that e is not predefined in MATLAB (use exp(1) ) these variables can be redefined by the user as needed be careful redefining builtin functions (e.g., sqrt , sin , etc.) • a “scalar” is a variable with only one piece of data >> a = 3; b = 4; >> A = 50; • variables can be cleared and redefined (even without clearing) >> clear a b A ; a = 2; A = 10; 1 1 MATLAB: Number Formatting Type Description Example short fixed point, 5 digits 3.1416 long fixed point, 15 digits 3.14159265358979 short e floating point, 5 digits 3.1416e+000 long e floating point, 15 digits (double) 3.141592653589793+000 short g best of fixed/floating, 5 digits 3.1416 long g best of fixed/floating, 15 digits 3.14159265358979 short eng eng format, exp mult of 3 3.1416e+000 long eng 16 sig figs, exp mult of 3 3.14159265358979e+000 bank dollars and cents 3.14 >> format short e ; pi ans = 3.1416e+000 MATLAB: Creating Arrays Array: collection of values represented by one variable • bracket method of constructing a row array >> a = [1 2 3 4] a = 1 2 3 4 >> a = [1; 2; 3; 4] a = 1 2 3 4 • bracket method of constructing a column array • spaces between values keep them in the same row • semicolons start a new row >> a=[1 2 3...
View
Full
Document
This note was uploaded on 09/21/2011 for the course CH E 310 taught by Professor Staff during the Spring '08 term at Iowa State.
 Spring '08
 Staff

Click to edit the document details