関数random_columnvector マニュアル

(The documentation of function random_columnvector)

Last Update: 2021/12/6


◆機能・用途(Purpose)

各成分の値を乱数で与えた列ベクトルを作成する。
Create a column vector whose values of components are given by random values.


◆形式(Format)

#include <matrix/initialize.h>
inline struct columnvector random_columnvector(const int size)


◆引数(Arguments)

size 作成する行ベクトルの次元。
The dimension of the row vector to create.


◆戻り値(Return value)

各成分の値を乱数で与えたsize次元の列ベクトルを表す構造体。 戻り値の各メンバの値は以下のようになる。
A structure which represents a column vector of size dimension, whose components are given by random values. The values of members of the return value are as follows.

戻り値のメンバ
Member of the return value
値
Value
size 引数sizeの値。
The value of argument size.
main size次元の配列。 各配列要素の値は乱数で与える。詳しくは下記「詳細」参照。
An array of size dimension. The values of array components are given by random values; see “Detail” below.
allocated ’y’


◆使用例(Example)

struct columnvector v=random_columnvector(3);


◆詳細(Detail)

この関数では乱数値を以下の方法で生成する。
In this function, random values are generated by the procedure below.
  1. 関数randを用いて0-RAND_MAXの間の整数値乱数を取得する。 0が得られた場合はノンゼロの乱数値が得られるまで繰り返す。
    An integer random value in a range 0-RAND_MAX is obtained by function rand. If the result was 0, then the same procedure is repeated until a non-zero random value is obtained.
  2. 上で取得した整数値乱数の逆数を計算する。
    The inverse of the integer random value obtained above is calculated.
  3. ステップ1で取得した整数値が奇数ならば ステップ2の計算結果に\(-1\)を掛ける。
    A factor \(-1\) is multiplied with the value obtained by the step 2 if the integer obtained by the step 1 was an odd number.
このステップ3で得られた値が行列要素の値として採用される。 したがって全ての値が整数値の逆数であり、値の範囲は\([-1,1]\)である。 0に近い値ほど高確率となる。 また、正の数と負の数を取る確率はほぼ同じである。
The value obtained by the step 3 is adopted as the value of each matrix component. Thus all the values are an inverse of an integer and varies in the range \([-1,1]\). The closer the value is to 0, the higher the probability. Positive and negative values appear at almost same probability.