03.03.2014 Views

Numerical Methods Course Notes Version 0.1 (UCSD Math 174, Fall ...

Numerical Methods Course Notes Version 0.1 (UCSD Math 174, Fall ...

Numerical Methods Course Notes Version 0.1 (UCSD Math 174, Fall ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2.2. USEFUL COMMANDS 15<br />

octave:22> z = 5:(-2):1<br />

z =<br />

5 3 1<br />

octave:23> z = 2:3:11<br />

z =<br />

2 5 8 11<br />

octave:24> z = 2:3:10<br />

z =<br />

2 5 8<br />

2.2 Useful Commands<br />

Here’s a none too complete listing of useful commands in octave:<br />

• help is the most useful command.<br />

• floor(X) returns the largest integer not greater than X. If X is a vector or matrix, it computes<br />

the floor element-wise. This behavior is common in octave: many functions which we normally<br />

think of as applicable to scalars can be applied to matrices, with the result computed elementwise.<br />

• ceil(X) returns the smallest integer not less than X, computed element-wise.<br />

• sin(X), cos(X), tan(X), atan(X), sqrt(X), returns the sine, cosine, tangent, arctangent,<br />

square root of X, computed elementwise.<br />

• exp(X) returns e X , elementwise.<br />

• abs(X) returns |X| , elementwise.<br />

• norm(X) returns the norm of X; if X is a vector, this is the L 2 norm:<br />

‖X‖ 2<br />

=<br />

( ∑<br />

i<br />

X 2 i<br />

) 1/2<br />

,<br />

if X is a matrix, it is the matrix norm subordinate to the L 2 norm.<br />

You can compute other norms with norm(X,p) where p is a number, to get the L p norm, or<br />

with p one of Inf, -Inf, etc.<br />

• zeros(m,n) returns an m × n matrix of all zeros.<br />

• eye(m) returns the m × m identity matrix.<br />

• [m,n] = size(A) returns the number of rows, columns of A.<br />

• length(v) returns the length of vector v, or the larger dimension if v is a matrix.<br />

• diag(v) returns the diagonal matrix with vector v as diagonal. diag(M) returns as a vector,<br />

the diagonal of matrix v. Thus diag(diag(v)) is v for vector v, but diag(diag(M)) is the<br />

diagonal part of matrix M.<br />

• toeplitz(v) returns the Toeplitz matrix associated with vector v. That is<br />

⎡<br />

toeplitz(v) =<br />

⎢<br />

⎣<br />

v(1) v(2) v(3) · · · v(n)<br />

v(2) v(1) v(2) · · · v(n − 1)<br />

v(3) v(2) v(1) · · · v(n − 2)<br />

. . .<br />

. .. .<br />

v(n) v(n − 1) v(n − 2) · · · v(1)<br />

⎤<br />

⎥<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!