本文整理汇总了C#中System.Complex.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# Complex.GetLength方法的具体用法?C# Complex.GetLength怎么用?C# Complex.GetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Complex
的用法示例。
在下文中一共展示了Complex.GetLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ComplexMatrix
public ComplexMatrix(Complex[,] values)
: this(values.GetLength(0), values.GetLength(1))
{
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
SetEntryInternal(i, j, values[i, j]);
}
}
}
示例2: matrix_ConjugateTranspose
// [X] = ([A]*)t
public static Complex[,] matrix_ConjugateTranspose(Complex[,] matA)
{
Complex[,] matX = new Complex[matA.GetLength(1), matA.GetLength(0)];
for (int i = 0; i < matX.GetLength(0); i++)
{
for (int j = 0; j < matX.GetLength(1); j++)
{
matX[i, j] = new Complex(matA[j, i].Real, -matA[j, i].Imag);
}
}
return matX;
}
示例3: MyComplexMatrix
/// <summary>
/// 2�����z��V�����s���쐬����D
/// </summary>
/// <param name="arr">�s��̗v�f��i�[����2�����z��</param>
public MyComplexMatrix(Complex[,] arr)
{
int rsize = arr.GetLength(0);
int csize = arr.GetLength(1);
Resize(rsize, csize);
for (int r = 0; r < rsize; ++r)
{
for (int c = 0; c < csize; ++c)
{
this[r, c] = arr[r, c];
}
}
}
示例4: product
public static Complex[,] product(Complex[,] matA, Complex[,] matB)
{
System.Diagnostics.Debug.Assert(matA.GetLength(1) == matB.GetLength(0));
Complex[,] matX = new Complex[matA.GetLength(0), matB.GetLength(1)];
for (int i = 0; i < matX.GetLength(0); i++)
{
for (int j = 0; j < matX.GetLength(1); j++)
{
matX[i, j] = 0.0;
for (int k = 0; k < matA.GetLength(1); k++)
{
matX[i, j] += matA[i, k] * matB[k, j];
}
}
}
return matX;
}
示例5: printMatrix
public static void printMatrix(string tag, Complex[,] mat)
{
for (int i = 0; i < mat.GetLength(0); i++)
{
for (int j = 0; j < mat.GetLength(1); j++)
{
Complex val = mat[i, j];
System.Diagnostics.Debug.WriteLine(tag + "(" + i + ", " + j + ")" + " = "
+ "(" + val.Real + "," + val.Imag + ") " + Complex.Norm(val));
}
}
}
示例6: plus
// [X] = [A] + [B]
public static Complex[,] plus(Complex[,] matA, Complex[,] matB)
{
System.Diagnostics.Debug.Assert(matA.GetLength(0) == matB.GetLength(0));
System.Diagnostics.Debug.Assert(matA.GetLength(1) == matB.GetLength(1));
Complex[,] matX = new Complex[matA.GetLength(0), matA.GetLength(1)];
for (int i = 0; i < matA.GetLength(0); i++)
{
for (int j = 0; j < matA.GetLength(1); j++)
{
matX[i, j] = matA[i, j] + matB[i, j];
}
}
return matX;
}
示例7: Matrix
/// <summary>
/// Constructs a matrix from the array.
/// </summary>
/// <param name="table"> The array the matrix gets constructed from. </param>
public Matrix(Complex[,] table)
: this((uint) table.GetLength(0), (uint) table.GetLength(1))
{
Initialize(table);
}
示例8: matrix_setRowVec
public static void matrix_setRowVec(Complex[,] matA, int row, Complex[] rowVec)
{
System.Diagnostics.Debug.Assert(matA.GetLength(1) == rowVec.Length);
for (int j = 0; j < matA.GetLength(1); j++)
{
matA[row, j] = rowVec[j];
}
}
示例9: SolvePortWaveguideEigen
//.........这里部分代码省略.........
System.Diagnostics.Debug.WriteLine("betamToSolveList.Length {0}", betamToSolveList.Length);
//////////////////////////////////////////////////////////////////////////////////////
// モード数の修正
int maxMode = maxModeSpecified;
if (maxMode > betamToSolveList.Length)
{
maxMode = betamToSolveList.Length;
}
//////////////////////////////////////////////////////////////////////////////////////
// 表示用に周期構造領域の固有モード分布を格納する
eigenVecsPeriodic = new KrdLab.clapack.Complex[maxMode][];
for (int imode = betamToSolveList.Length - 1, tagtModeIndex = 0; imode >= 0 && tagtModeIndex < maxMode; imode--, tagtModeIndex++)
{
KrdLab.clapack.Complex[] resVec = resVecList[imode];
System.Diagnostics.Debug.Assert(resVec.Length == nodePeriodic.Count);
eigenVecsPeriodic[tagtModeIndex] = new KrdLab.clapack.Complex[nodePeriodic.Count];
resVec.CopyTo(eigenVecsPeriodic[tagtModeIndex], 0);
}
//////////////////////////////////////////////////////////////////////////////////////
// 固有値、固有ベクトル
// 格納
int nodeCntB1 = nodePeriodicB1.Count;
eigenValues = new Complex[maxMode];
//eigenVecsB1 = new Complex[maxMode, nodeCntB1];
//eigen_dFdXsB1 = new Complex[maxMode, nodeCntB1];
eigenVecsB1 = new Complex[maxMode, nodesBoundary.Length]; // 強制境界を除く
eigen_dFdXsB1 = new Complex[maxMode, nodesBoundary.Length]; // 強制境界を除く
for (int imode = 0; imode < maxMode; imode++)
{
eigenValues[imode] = new Complex(0, 0);
for (int ino = 0; ino < eigenVecsB1.GetLength(1); ino++)
{
eigenVecsB1[imode, ino] = new Complex(0, 0);
eigen_dFdXsB1[imode, ino] = new Complex(0, 0);
}
}
for (int imode = betamToSolveList.Length - 1, tagtModeIndex = 0; imode >= 0 && tagtModeIndex < maxMode; imode--, tagtModeIndex++)
{
//System.Diagnostics.Debug.WriteLine("imode = {0}", imode);
KrdLab.clapack.Complex workBetam = betamToSolveList[imode];
KrdLab.clapack.Complex[] resVec = resVecList[imode];
KrdLab.clapack.Complex[] resDFDXVec = resDFDXVecList[imode];
Complex betam = new Complex(workBetam.Real, workBetam.Imaginary);
bool isComplexConjugateMode = false;
// 減衰定数は符号がマイナス(β = -jα)
if (betam.Imaginary > 0.0 && Math.Abs(betam.Real) <= 1.0e-12)
{
betam = new Complex(betam.Real, -betam.Imaginary);
isComplexConjugateMode = true;
}
//Complex[] evec = new Complex[nodeCntB1];
//Complex[] evec_dFdX = new Complex[nodeCntB1];
Complex[] evec = new Complex[nodesBoundary.Length]; // 強制境界を除く
Complex[] evec_dFdX = new Complex[nodesBoundary.Length]; // 強制境界を除く
for (int ino = 0; ino < nodeCntB1; ino++)
{
int nodeNumberPortBc1 = nodePeriodicB1[ino];
//System.Diagnostics.Debug.WriteLine("ino = {0} nodeNumberPortBc1 = {1}", ino, nodeNumberPortBc1);
int ino_InLoop_PortBc1 = toNodePeriodic[nodeNumberPortBc1];
Complex cvalue = new Complex(resVec[ino_InLoop_PortBc1].Real, resVec[ino_InLoop_PortBc1].Imaginary);
Complex dFdXValue = new Complex(resDFDXVec[ino_InLoop_PortBc1].Real, resDFDXVec[ino_InLoop_PortBc1].Imaginary);
示例10: int_Det
private static Complex int_Det(Complex[,] matrix)
{
var frow = new List<Complex>();
var size = matrix.GetLength(0);
if (size == 2) return matrix[0, 0] * matrix[1, 1] - matrix[1, 0] * matrix[0, 1];
var mat = new Complex[size - 1, size];
for (int row = 0; row < size; row++)
{
frow.Add(matrix[0, row]);
for (int col = 0; col < size - 1; col++)
{
mat[col, row] = matrix[col + 1, row];
}
}
Complex result = 0;
for (int i = 0; i < size; i++)
{
var fac = frow[i];
var mtt = new List<Complex>();
for (int row = 0; row < size; row++)
{
if (row != i)
{
for (int col = 0; col < size - 1; col++)
{
mtt.Add(mat[col, row]);
}
}
}
var det = fac * Determinant(mtt.ToArray());
if (i % 2 != 0) result -= det;
else result += det;
}
return result;
}
示例11: GetIncidentAmplitude
/// <summary>
/// 入射振幅を取得する
/// </summary>
/// <param name="world"></param>
/// <param name="fieldPortBcId"></param>
/// <param name="eigen_values"></param>
/// <param name="eigen_vecs"></param>
/// <returns></returns>
public static Complex[] GetIncidentAmplitude(
CFieldWorld world,
uint fieldPortBcId,
IList<IList<uint>> PCWaveguidePorts,
Complex[] eigen_values,
Complex[,] eigen_vecs)
{
// 2チャンネルのポート?
if (PCWaveguidePorts.Count != 2)
{
return null;
}
//境界節点番号→全体節点番号変換テーブル(no_c_all)
uint[] no_c_all = null;
// 全体節点番号→境界節点番号変換テーブル(to_no_boundary
Dictionary<uint, uint> to_no_boundary = null;
// 境界節点の座標
double[][] coord_c_all = null;
// 境界上のすべての節点番号を取り出す
//bool res = WgUtil.GetBoundaryNodeList(world, fieldPortBcId, out no_c_all, out to_no_boundary);
bool res = WgUtil.GetBoundaryCoordList(world, fieldPortBcId, out no_c_all, out to_no_boundary, out coord_c_all);
if (!res)
{
return null;
}
uint max_mode = (uint)eigen_values.Length;
uint node_cnt = (uint)eigen_vecs.GetLength(1);
System.Diagnostics.Debug.Assert(max_mode >= 2);
System.Diagnostics.Debug.Assert(node_cnt == no_c_all.Length);
// check
//for (int ino = 0; ino < node_cnt; ino++)
//{
// double[] coord = coord_c_all[ino];
// System.Diagnostics.Debug.WriteLine("coord[1]: {0}", coord[1]);
//}
double[] coord_c_first = coord_c_all[0];
double[] coord_c_last = coord_c_all[node_cnt - 1];
// 振幅を合わせる基準点節点
int no_base = -1;
// 入射モードの電力
//double inputPower = 1.0 / max_mode;
////////////////////////////////
/*
// チャンネル2のみ入力
// ポート1のチャンネル1(上側)の節点を基準点にする モード減算
bool isMinus = true; // 減算
int channelIndex = 0; // チャンネル1
// ポート1のチャンネル2(下側)の節点を基準点にする モード加算
//bool isMinus = false; // 加算
//int channelIndex = 1; // チャンネル2
*/
// チャンネル1のみ入力
// ポート1のチャンネル1(上側)の節点を基準点にする モード減算
//bool isMinus = false; // 加算
//int channelIndex = 0; // チャンネル1
// ポート1のチャンネル2(下側)の節点を基準点にする モード加算
bool isMinus = true; // 減算
int channelIndex = 1; // チャンネル2
IList<uint> channelNodes = PCWaveguidePorts[channelIndex];
double waveguideWidth = Math.Abs(coord_c_last[1] - coord_c_first[1]);
int rodCntHalf = g_rodCntHalf;
int rodCntMiddle = g_rodCntMiddle;
int defectRodCnt = g_defectRodCnt;
int rodCntY = rodCntHalf * 2 + defectRodCnt * 2 + rodCntMiddle;
double rodDistanceY = waveguideWidth / rodCntY;
double yy_min = 0.0;
double yy_max = 0.0;
//double margin = 0.05;
double margin = 0.10;
double yy_0 = 0;
if (channelIndex == 0)
{
yy_0 = (rodCntHalf + defectRodCnt + rodCntMiddle) * rodDistanceY + 0.5 * rodDistanceY;
}
else
{
yy_0 = rodCntHalf * rodDistanceY + 0.5 * rodDistanceY;
}
yy_min = yy_0 - margin * rodDistanceY;
yy_max = yy_0 + margin * rodDistanceY;
foreach (uint no in channelNodes)
{
// 境界上の節点以外は処理しない(チャンネル節点は内部領域の節点も格納されている)
if (!to_no_boundary.ContainsKey(no)) continue;
// noは全体節点番号
// 境界節点番号へ変換
//.........这里部分代码省略.........
示例12: solveProblem
//.........这里部分代码省略.........
DrawerAry.InitTrans(Camera);
return true;
}
*/
// 格納する
ryy_1d_port_list.Add(ryy_1d_port1);
eigen_values_port_list.Add(eigen_values_port1);
eigen_vecs_port_list.Add(eigen_vecs_port1);
eigen_dFdXs_port_list.Add(eigen_dFdXs_port1);
// 入射モードチェック
if (retAddPort)
{
if ((workWgPortInfo.IncidentModeIndex >= eigen_values_port_list[portIndex].Length)
|| (Math.Abs(eigen_values_port_list[portIndex][workWgPortInfo.IncidentModeIndex].Real) < MyUtilLib.Matrix.Constants.PrecisionLowerLimit) // 入射モードが伝搬モードでない
)
{
retAddPort = false;
}
}
}
else if (IsInoutWgSame && portIndex != 0)
{
double[,] ryy_1d_port2 = null;
Complex[] eigen_values_port2 = null;
Complex[,] eigen_vecs_port2 = null;
Complex[,] eigen_dFdXs_port2 = null;
// 出力側は入力側と同じ導波路とする
double[,] ryy_1d_port1 = ryy_1d_port_list[0];
Complex[] eigen_values_port1 = eigen_values_port_list[0];
Complex[,] eigen_vecs_port1 = eigen_vecs_port_list[0];
Complex[,] eigen_dFdXs_port1 = eigen_dFdXs_port_list[0];
ryy_1d_port2 = new double[ryy_1d_port1.GetLength(0), ryy_1d_port1.GetLength(1)];
for (int i = 0; i < ryy_1d_port2.GetLength(0); i++)
{
// 位置を反転
for (int j = 0; j < ryy_1d_port2.GetLength(1); j++)
{
double value = ryy_1d_port1[ryy_1d_port2.GetLength(0) - 1 - i, ryy_1d_port2.GetLength(1) - 1 - j];
ryy_1d_port2[i, j] = value;
}
}
eigen_values_port2 = new Complex[eigen_values_port1.Length];
eigen_vecs_port2 = new Complex[eigen_vecs_port1.GetLength(0), eigen_vecs_port1.GetLength(1)];
eigen_dFdXs_port2 = new Complex[eigen_dFdXs_port1.GetLength(0), eigen_dFdXs_port1.GetLength(1)];
for (int i = 0; i < eigen_vecs_port2.GetLength(0); i++)
{
Complex betam = eigen_values_port1[i];
eigen_values_port2[i] = betam;
// 位置を反転
for (int j = 0; j < eigen_vecs_port2.GetLength(1); j++)
{
eigen_vecs_port2[i, j] = eigen_vecs_port1[i, eigen_vecs_port2.GetLength(1) - 1 - j];
eigen_dFdXs_port2[i, j] = eigen_dFdXs_port1[i, eigen_dFdXs_port2.GetLength(1) - 1 - j];
}
}
// 格納する
ryy_1d_port_list.Add(ryy_1d_port2);
eigen_values_port_list.Add(eigen_values_port2);
eigen_vecs_port_list.Add(eigen_vecs_port2);
eigen_dFdXs_port_list.Add(eigen_dFdXs_port2);
}
else
{
示例13: Initialize
/// <summary>
/// </summary>
/// <param name="table"> </param>
public void Initialize(Complex[,] table)
{
for (var i = 0; i < 2; ++i) if (_matrix.GetLength(i) != table.GetLength(i)) throw new ArgumentException("Dimensions doesnot matches (+,-).");
//M = table; // Logical Error (reference type)
var rows = Rows;
var cols = Cols;
for (var i = 0; i < rows; ++i) for (var j = 0; j < cols; ++j) _matrix[i, j] = table[i, j];
}
示例14: matrix_FromBuffer
public static Complex[,] matrix_FromBuffer(KrdLab.clapack.Complex[] mat_, int nRow, int nCol)
{
Complex[,] mat = new Complex[nRow, nCol];
// rowから先に埋めていく
for (int j = 0; j < mat.GetLength(1); j++) // col
{
for (int i = 0; i < mat.GetLength(0); i++) // row
{
KrdLab.clapack.Complex cval = mat_[j * mat.GetLength(0) + i];
mat[i, j] = new Complex(cval.Real, cval.Imaginary);
}
}
return mat;
}
示例15: matrix_Inverse
public static Complex[,] matrix_Inverse(Complex[,] matA)
{
System.Diagnostics.Debug.Assert(matA.GetLength(0) == matA.GetLength(1));
int n = matA.GetLength(0);
KrdLab.clapack.Complex[] matA_ = matrix_ToBuffer(matA);
KrdLab.clapack.Complex[] matB_ = new KrdLab.clapack.Complex[n * n];
// 単位行列
for (int i = 0; i < matB_.Length; i++)
{
matB_[i] = (KrdLab.clapack.Complex)0.0;
}
for (int i = 0; i < n; i++)
{
matB_[i * n + i] = (KrdLab.clapack.Complex)1.0;
}
// [A][X] = [B]
// [B]の内容が書き換えられるので、matXを新たに生成せず、matBを出力に指定している
int x_row = 0;
int x_col = 0;
KrdLab.clapack.FunctionExt.zgesv(ref matB_, ref x_row, ref x_col, matA_, n, n, matB_, n, n);
Complex[,] matX = matrix_FromBuffer(matB_, x_row, x_col);
return matX;
}