14.09.2015 Views

Matvec Users’ Guide

Matvec Users' Guide

Matvec Users' Guide

SHOW MORE
SHOW LESS
  • No tags were found...

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

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

3.4. COMPUTATION 19<br />

3.3.3 Selecting elements<br />

Sometimes, you may want to select elements which satisfy certain condition. Here is an example:<br />

> A = [1,2,3;4,5,6]<br />

Col 1 Col 2 Col 3<br />

Row 1 1 2 3<br />

Row 2 4 5 6<br />

> A.select(A>2)<br />

i = 1 i = 2 i = 3 i = 4<br />

3 4 5 6<br />

3.4 Computation<br />

3.4.1 Friend function<br />

There are several standard math functions available. The details about the ranges and error conditions can<br />

be found in your math library reference manuals. They are implemented as friend functions of class Matrix.<br />

abs(A) acos(A) asin(A) atan(A) atan2(A,B)<br />

ceil(A) cos(A) cosh(A) erf(A) erfc(A)<br />

exp(A) floor(A) gammainc(A) gammaln(A,B) int(A)<br />

log(A) log10(A) max(A) max(A,B) min(A)<br />

min(A,B) mod(A,B) pow(A) round(A) sin(A)<br />

sinh(A) sqrt(A) tan(A) tanh(A)<br />

The above friend functions are performed element-by-element, and the relevant objects A and B remain<br />

intact.<br />

3.4.2 Member function<br />

For a convenience, the standard math functions are also implemented as member functions.<br />

A.abs() A.acos() A.asin() A.atan() A.atan2(B)<br />

A.ceil() A.cos() A.cosh() A.erf() A.erfc()<br />

A.exp() A.floor() A.gammainc() A.gammaln(B) A.int()<br />

A.log() A.log10() A.max() A.max(B) A.min()<br />

A.min(B) A.mod(B) A.pow() A.round() A.sin()<br />

A.sinh() A.sqrt() A.tan() A.tanh()<br />

A.gammaln() returns the log of the gamma function value of A. The gamma function is defined as<br />

Γ(x) =<br />

∫ ∞<br />

0<br />

t (x−1) e −t dt<br />

with Γ(1) = 1, Γ(1/2) = √ (π), and Γ(x + 1) = xΓ(x).<br />

A.gammainc() returns the incomplete gamma function value of A. The incomplete gamma function is<br />

defined as<br />

∫ x<br />

0<br />

gammainc(x, a) =<br />

t(a−1) e −t dt<br />

(a > 0)<br />

Γ(a)<br />

all<br />

A.all() operates over the columns of A, returning a vector of 1’s and 0’s. If A is a one-row or one-column<br />

matrix, then the returned value would be a scalar. For example,

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

Saved successfully!

Ooh no, something went wrong!