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 Document
Unformatted text preview: Interactive Computing with MATLAB Chapter 2 of Numerical Methods with MATLAB, Gerald Recktenwald PGE 310: Formulation and Solution in Geosystems Engineering Dr. Balhoff Spring 2011 1 MATLAB Expressions • Matlab has an interactive mode – Many expressions are obvious (like addition, multiplication, etc.) – Some expressions (exponentials, natural logarithms, Bessel Functions, etc.) are not as obvious – The help , lookfor commands can be useful • Variables can be stored in Matlab – a = 5 – b = 2^3+6 – c = a+b • Some variables are built in. Be careful, you can change them – ans – pi – Inf – NaN 2 Matrices and Vectors • Arrays are a collection of values referred to by a single variable name • M a t r i c e s c a n b e d e f i n e d s e v e r a l d i f f e r e n t w a y s 1. Manual Entry 2. Expressions that evaluate a matrix 3. Builtin functions that return matrices 4. Userwritten functions that return matrices 5. Importing matrix data from files on disk “Roger, Roger. What’s our vector, Victor?” Airplane 3 • Vectors • Matrices Manual Entry >> A = [4 6 7; 5 3 2; 1 7 4] A = 4 6 7 5 3 2 1 7 4 >> u=[6 3 8] u = 6 3 8 >> v = [3.1; 4.2; 0.5; 9.0] v = 3.1000 4.2000 0.5000 9.0000 “The human mind has never invented a laborsaving machine equal to algebra.” Anonymous 4 Matrices and Vectors • Arrays are a collection of values referred to by a single variable name • M a t r i c e s c a n b e d e f i n e d s e v e r a l d i f f e r e n t w a y s 1. Manual Entry 2. Expressions that evaluate a matrix 3. Builtin functions that return matrices 4. Userwritten functions that return matrices 5. Importing matrix data from files on disk “Roger, Roger. What’s our vector, Victor?” Airplane 3 • Vectors • Matrices Manual Entry >> A = [4 6 7; 5 3 2; 1 7 4] A = 4 6 7 5 3 2 1 7 4 >> u=[6 3 8] u = 6 3 8 >> v = [3.1; 4.2; 0.5; 9.0] v = 3.1000 4.2000 0.5000 9.0000 “The human mind has never invented a laborsaving machine equal to algebra.” Anonymous 4 Expressions (e.g. Transpose) >> A = [4 6 7; 5 3 2; 1 7 4]; >> B=A' B = 4 5 1 6 3 7 7 2 4 5 Built in functions • d i a g , e y e , o n e s , r a n d , l e n g t h , linspace, logspace, zeros, size >> eye(4) % 4x4 Identity Matrix ans = 1 0 0 0 1 0 0 0 1 0 0 0 1 >> rand(3,4) % Matrix of random numbers between 0 and 1 ans = 0.8147 0.9134 0.2785 0.9649 0.9058 0.6324 0.5469 0.1576 0.1270 0.0975 0.9575 0.9706 6 More Built in Functions >> linspace(0,100,11) points ans = 0 10 20 30 40 50 60 70 80 90 100 >> x = logspace(1,5,3) x = 10 1000 100000 >> A = [1 3 5; 2 1 7; 4 3 2; 1 6 9]; 4 rows and 3 columns >> size(A) ans = 4 3 7 Subscript Notation >> A = [1 3 5; 2 1 7; 4 3 2; 1 6 9]; % A is 4x3 matrix >> A(2,3) % What is the value of A in the second row, 3 rd column?...
View
Full
Document
 Spring '06
 Klaus

Click to edit the document details