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.

Chapter 3<br />

Matrix Object<br />

Matrix computation is a complex task. <strong>Matvec</strong> provides a comprehensive set of functions and tools, which<br />

are powerful and easy to learn, to perform the massive matrix manipulation and sophisticated matrix computation.<br />

In particular, <strong>Matvec</strong> can be used to answer what-if questions raised by your research colleagues<br />

or by yourself.<br />

3.1 Creation<br />

There are several ways to create a matrix object. The three common matrix creation methods are listed<br />

below:<br />

• type in all elements row-by-row directly from keyboard with the special operator [ and ]. That is<br />

starting with [, separating each elements with comma (,), separating each row with semicolon (;), and<br />

ending with ]. For example,<br />

A = [1.0, 2.0, -2.0; 3.0, 2.0, sqrt(9.0)];<br />

• use object-creating friend functions such as Matrix(m,n), ones(m,n), zeros(m,n), and sample(m,n). For<br />

example,<br />

> A = Matrix(2,3) # Caution: its contents could be junk<br />

> B = ones(2,3)<br />

Col 1 Col 2 Col 3<br />

Row 1 3.24485e-308 2.26268e-76 1.28459e-153<br />

Row 2 3.24492e-308 5.82751e+252 3.94257e+180<br />

Col 1 Col 2 Col 3<br />

Row 1 1 1 1<br />

Row 2 1 1 1<br />

> C = zeros(2,3)<br />

Col 1 Col 2 Col 3<br />

Row 1 0 0 0<br />

Row 2 0 0 0<br />

> D = sample(2,3) // generated from Uniform(0.0,1.0)<br />

15

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

Saved successfully!

Ooh no, something went wrong!