Octave provides a number of functions for creating special matrix forms. In nearly all cases, it is best to use the built-in functions for this purpose than to try to use other tricks to achieve the same effect.
eye returns a square matrix with the dimension specified. If you
supply two scalar arguments, eye takes them to be the number of
rows and columns. If given a vector with two elements, eye uses
the values of the elements as the number of rows and columns,
respecively. For example,
eye (3)
=> 1 0 0
0 1 0
0 0 1
The following expressions all produce the same result:
eye (2) eye (2, 2) eye (size ([1, 2; 3, 4])
For compatibility with MATLAB, calling eye with no arguments
is equivalent to calling it with an argument of 1.
eye.
If you need to create a matrix whose values are all the same, you should use an expression like
val_matrix = val * ones (n, m)
eye.
"seed", x)
eye. In
addition, you can set the seed for the random number generator using the
form
randn ("seed", x)
where x is a scalar value. If called as
rand ("seed")
rand returns the current value of the seed.
"seed", x)
eye. In
addition, you can set the seed for the random number generator using the
form
randn ("seed", x)
where x is a scalar value. If called as
randn ("seed")
randn returns the current value of the seed.
The rand and randn functions use separate generators.
This ensures that
rand ("seed", 13);
randn ("seed", 13);
u = rand (100, 1);
n = randn (100, 1);
and
rand ("seed", 13);
randn ("seed", 13);
u = zeros (100, 1);
n = zeros (100, 1);
for i = 1:100
u(i) = rand ();
n(i) = randn ();
end
produce equivalent results.
Normally, rand and randn obtain their initial
seeds from the system clock, so that the sequence of random numbers is
not the same each time you run Octave. If you really do need for to
reproduce a sequence of numbers exactly, you can set the seed to a
specific value.
If it is invoked without arguments, rand and randn return a
single element of a random sequence.
The rand and randn functions use Fortran code from RANLIB,
a library of fortran routines for random number generation, compiled by
Barry W. Brown and James Lovato of the Department of Biomathematics at
The University of Texas, M.D. Anderson Cancer Center, Houston, TX 77030.
diag ([1, 2, 3], 1)
=> 0 1 0 0
0 0 2 0
0 0 0 3
0 0 0 0
The functions linspace and logspace make it very easy to
create vectors with evenly or logarithmically spaced elements.
See section Ranges.
The linspace function always returns a row vector, regardless of
the value of prefer_column_vectors.
linspace except that the values are logarithmically
spaced from
If limit is equal to the points are between not in order to be compatible with the corresponding MATLAB function.
The following functions return famous matrix forms.
A Hankel matrix formed from an m-vector c, and an n-vector r, has the elements
inverse (hilb (n)),
which suffers from the ill-conditioning of the Hilbert matrix, and the
finite precision of your computer's floating point arithmetic.
A square Toeplitz matrix has the form
A Vandermonde matrix has the form
Go to the first, previous, next, last section, table of contents.