Matlab_Formulas_List

# Matlab_Formulas_List - MATLAB FORMULA LIST Special...

This preview shows pages 1–4. Sign up to view the full content.

MATLAB FORMULA LIST Special Characters [ ] f o r m s m a t r i c e s ( ) forms subscripts , separates subscripts or matrix elements ; separates commands or matrix rows % indicates comments : generates matrices + scalar and array addition - scalar and array subtraction * scalar multiplication .* array multiplication / scalar division ./ array division ^ scalar exponentiation .^ array exponentiation transpose Some simple tricks Using the colon (“:”) character Make a series of numbers from a given beginning and ending number -Example: >> 0:5 returns 0 1 2 3 4 5 >> -7:5 returns -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 -End Example Using the semicolon (“;”) character The semicolon (“;”) can be used if you don’t want to see the output. -Example: Say for example you want make “x” to be the numbers between 1 and 100. Now you know what numbers “x” are going to be, and don’t want them to be outputted, then you can put a “;” at the end of the command and it won’t be. NOTE: written like this, it will return every value of “x” as shown below >> x=0:100 x = Columns 1 through 23 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Columns 24 through 46

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

View Full Document
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 Columns 47 through 69 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 Columns 70 through 92 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 Columns 93 through 101 92 93 94 95 96 97 98 99 100 NOTE: by putting a “;” at the end, you prevent it from returning every value of “x” >> x=0:100; >> -End Example How to set up a matrix -Example: NOTE: “,” separate columns and “;” separate rows >> [2] returns 2 >> [2,3] returns 2 3 >> [2;3] returns 2 3 >> [2,3,4] returns 2 3 4 >> [2,3,4;5,8,7] returns 2 3 4 5 8 7 -End Example Raise things to a power If you want to raise a scalar number by a power, then you use “^” If you want to raise an array (such as an matrix) by a power, then use “.^” -Example: >> 5^3 returns 125 >> [2,3].^2 returns 4 9 (raises every number in the matrix by a power of 2, 2 2 =4 and 3 2 =9) -End Example How to transpose a matrix ‘ represents transpose -Example:
1 2 3 4 5 6 7 8 9 >> [1,2,3;4,5,6;7,8,9]' returns 1 4 7 2 5 8 3 6 9 -End Example Definitions abs computes absolute value or magnitude -Examples >> abs(5) returns 5 >> abs(-5) returns 5 >> abs([1,2;6,-5]) returns 1 2 6 5 -End Example acos computes arccosine -Example: NOTE: the “pi” represents π >> cos(pi/4) returns 0.7071 >> acos(0.7071) returns 0.7854 (which is ( π /4) written as a decimal) -End Example all determines if all values are true ans stores expression value -Example: “ans” stores the answer to the last operation you did. >> 27*9

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

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

## This note was uploaded on 01/20/2010 for the course ASE 311 taught by Professor Kraczek during the Spring '08 term at University of Texas.

### Page1 / 20

Matlab_Formulas_List - MATLAB FORMULA LIST Special...

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

View Full Document
Ask a homework question - tutors are online