Ch E 310 - Fall 10 - Lecture 2

Ch E 310 - Fall 10 - Lecture 2 - Lecture 2 – Agenda •...

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lecture 2 – August 26, 2010 Agenda: • Introduction to MATLAB (continued) order of operations arrays (one and two-dimensional) function handles • In-class 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.03e-4 = 2.03 × 10-4 = 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 case-sensitive (you can have a and A ) • there are a few variables that have pre-defined values: pi (3.14159…), i ( ), j ( ) note that e is not pre-defined in MATLAB (use exp(1) ) these variables can be redefined by the user as needed be careful redefining built-in 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

{[ snackBarMessage ]}

Page1 / 29

Ch E 310 - Fall 10 - Lecture 2 - Lecture 2 – Agenda •...

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

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