Keyword: ランダム直交行列
概要
本サンプルはランダム直交行列の生成を行うC#によるサンプルプログラムです。 本サンプルは 4x4 のランダム直交行列を生成し出力します。
※本サンプルはnAG Library for .NETに含まれる関数 g05px() のExampleコードです。本サンプル及び関数の詳細情報は g05px のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
出力結果
(本関数の詳細はg05px のマニュアルページを参照)| この出力例をダウンロード |
g05px Example Program Results
0.176 0.740 -0.307 -0.572
0.659 -0.578 -0.219 -0.428
0.668 0.317 0.608 0.290
-0.297 -0.132 0.699 -0.637
- 3〜6行目に生成されたランダム直交行列が出力されています。
ソースコード
(本関数の詳細はg05px のマニュアルページを参照)
※本サンプルソースコードは .NET環境用の科学技術・統計計算ライブラリである「nAG Library for .NET」の関数を呼び出します。
サンプルのコンパイル及び実行方法
| このソースコードをダウンロード |
// g05px Example Program Text
// C# version, nAG Copyright 2008
using System;
using NagLibrary;
using System.IO;
namespace NagDotNetExamples
{
public class G05PXE
{
static void Main(String[] args)
{
StartExample();
}
public static void StartExample()
{
try
{
const int n=4;
const int m=4;
const int mseed=1;
int genid, i, j, subid;
double[,] a = new double[m, n];
int[] seed = new int[mseed];
int ifail;
Console.WriteLine("g05px Example Program Results");
Console.WriteLine("");
// Initialise the seed
seed[0] = 1762543;
// genid and subid identify the base generator
genid = 1;
subid = 1;
// Initialise the generator to a repeatable sequence
G05.G05State g05State = new G05.G05State(genid, subid, seed, out ifail);
if (ifail != 0)
{
Console.WriteLine("** Generator initialisation failed with ifail = {0,5}", ifail);
goto L40;
}
// Generate the random orthogonal matrix
G05.g05px("Right", "Initialize", m, n, g05State, a, out ifail);
if (ifail != 0)
{
Console.WriteLine("** g05kp failed with ifail = {0,5}", ifail);
goto L40;
}
// Display the results
for (i = 1 ; i <= m ; i++)
{
for (j = 1 ; j <= n ; j++)
{
Console.Write(" {0,8:f3}", a[i - 1 , j - 1]);
}
Console.WriteLine("");
}
//
L40: ;
//
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine( "Exception Raised");
}
}
}
}
