Matlab Slides I
Matlab Slides I
https://au.mathworks.com/academia/tah-portal/
macquarie-university-916052.html
• pi: 3.141592...
• ans: The output of the last calculation
• eps: The smallest number Matlab can distinguish
• inf: Infinity
• NaN: Not a number (eg. 0/0)
• i, 1i, 7i: Imaginary numbers (get in the habit of using 1i
instead of i, to save frustration later)
There are others, but you won’t need them this semester.
Creating variables
Matlab can assign variables using the = sign, and call them later.
Creating variables
You don’t always want the output printed on the screen, especially
if you’re defining variables. If you end a line with a semi-colon (;),
it suppresses the output.
Saving variables
Matlab has a lot of in-built functions which we can make use of:
• Trigonometric: sin, cos, tan, asin, acos, atan
• Exponentials and logarithms: exp, log, log10
• Hyperbolic: cosh, sinh, tanh, acosh, asinh, atanh
• Rounding: round, floor, ceil
• Complex numbers: real, imag, abs, angle, conj
• Sign: sgn
• Square root: sqrt
Matrices and vectors
• Row vector: [1 1 2 3 5 8]
• Column vector: [3; 1; 4; 1; 5; 9]
• Matrix: [1 0 0; 0 1 0; 0 0 1]
• M(3,2) = 8
• M(2,:) = [4 5 6]
• M(1,[2 3]) = [2 3]
• M([1 2],[1 3]) = [1 3; 4 6]
• M(:,[1,2]) = [1 2; 4 5; 7 8]
• M(1,end) = 3
It’s alright that you don’t know what eigenvalues and eigenvectors
are yet. You don’t have to know for this subject.
We can compare the time required to compute the inverse with the
time required to use the backslash operator:
This doesn’t seem like much, but numerical linear algebra often
involves performing these operations millions of times. It adds up.
List Operations
Once you start programming next week, it will also tell you on
what line of code the error occurred:
Go and Practice