本文整理汇总了C#中VectorD.Set方法的典型用法代码示例。如果您正苦于以下问题:C# VectorD.Set方法的具体用法?C# VectorD.Set怎么用?C# VectorD.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VectorD
的用法示例。
在下文中一共展示了VectorD.Set方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EigenvalueDecompositionD
//--------------------------------------------------------------
/// <summary>
/// Creates the eigenvalue decomposition of the given matrix.
/// </summary>
/// <param name="matrixA">The square matrix A.</param>
/// <exception cref="ArgumentNullException">
/// <paramref name="matrixA"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// <paramref name="matrixA"/> is non-square (rectangular).
/// </exception>
public EigenvalueDecompositionD(MatrixD matrixA)
{
if (matrixA == null)
throw new ArgumentNullException("matrixA");
if (matrixA.IsSquare == false)
throw new ArgumentException("The matrix A must be square.", "matrixA");
_n = matrixA.NumberOfColumns;
_d = new VectorD(_n);
_e = new VectorD(_n);
_isSymmetric = matrixA.IsSymmetric;
if (_isSymmetric)
{
_v = matrixA.Clone();
// Tridiagonalize.
ReduceToTridiagonal();
// Diagonalize.
TridiagonalToQL();
}
else
{
_v = new MatrixD(_n, _n);
// Abort if A contains NaN values.
// If we continue with NaN values, we run into an infinite loop.
for (int i = 0; i < _n; i++)
{
for (int j = 0; j < _n; j++)
{
if (Numeric.IsNaN(matrixA[i, j]))
{
_e.Set(double.NaN);
_v.Set(double.NaN);
_d.Set(double.NaN);
return;
}
}
}
// Storage of nonsymmetric Hessenberg form.
MatrixD matrixH = matrixA.Clone();
// Working storage for nonsymmetric algorithm.
double[] ort = new double[_n];
// Reduce to Hessenberg form.
ReduceToHessenberg(matrixH, ort);
// Reduce Hessenberg to real Schur form.
HessenbergToRealSchur(matrixH);
}
}
示例2: SingularValueDecompositionD
public SingularValueDecompositionD(MatrixD matrixA)
{
if (matrixA == null)
throw new ArgumentNullException("matrixA");
// Derived from LINPACK code.
// Initialize.
_m = matrixA.NumberOfRows;
_n = matrixA.NumberOfColumns;
MatrixD matrixAClone = matrixA.Clone();
if (_m < _n)
throw new ArgumentException("The number of rows must be greater than or equal to the number of columns.", "matrixA");
int nu = Math.Min(_m, _n);
_s = new VectorD(Math.Min(_m + 1, _n));
_u = new MatrixD(_m, nu); //Jama getU() returns new Matrix(U,_m,Math.min(_m+1,_n)) ?!
_v = new MatrixD(_n, _n);
double[] e = new double[_n];
double[] work = new double[_m];
// Abort if A contains NaN values.
// If we continue with NaN values, we run into an infinite loop.
for (int i = 0; i < _m; i++)
{
for (int j = 0; j < _n; j++)
{
if (Numeric.IsNaN(matrixA[i, j]))
{
_u.Set(double.NaN);
_v.Set(double.NaN);
_s.Set(double.NaN);
return;
}
}
}
// By default, we calculate U and V. To calculate only U or V we can set one of the following
// two constants to false. (This optimization is not yet tested.)
const bool wantu = true;
const bool wantv = true;
// Reduce A to bidiagonal form, storing the diagonal elements
// in s and the super-diagonal elements in e.
int nct = Math.Min(_m - 1, _n);
int nrt = Math.Max(0, Math.Min(_n - 2, _m));
for (int k = 0; k < Math.Max(nct, nrt); k++)
{
if (k < nct)
{
// Compute the transformation for the k-th column and
// place the k-th diagonal in s[k].
// Compute 2-norm of k-th column without under/overflow.
_s[k] = 0;
for (int i = k; i < _m; i++)
_s[k] = MathHelper.Hypotenuse(_s[k], matrixAClone[i, k]);
if (_s[k] != 0)
{
if (matrixAClone[k, k] < 0)
_s[k] = -_s[k];
for (int i = k; i < _m; i++)
matrixAClone[i, k] /= _s[k];
matrixAClone[k, k] += 1;
}
_s[k] = -_s[k];
}
for (int j = k + 1; j < _n; j++)
{
if ((k < nct) && (_s[k] != 0))
{
// Apply the transformation.
double t = 0;
for (int i = k; i < _m; i++)
t += matrixAClone[i, k] * matrixAClone[i, j];
t = -t / matrixAClone[k, k];
for (int i = k; i < _m; i++)
matrixAClone[i, j] += t * matrixAClone[i, k];
}
// Place the k-th row of A into e for the
// subsequent calculation of the row transformation.
e[j] = matrixAClone[k, j];
}
if (wantu & (k < nct))
{
// Place the transformation in U for subsequent back
// multiplication.
for (int i = k; i < _m; i++)
_u[i, k] = matrixAClone[i, k];
}
if (k < nrt)
//.........这里部分代码省略.........
示例3: SetWithIListShouldThrowArgumentNullException
public void SetWithIListShouldThrowArgumentNullException()
{
var v = new VectorD(1);
v.Set((IList<double>)null);
}
示例4: SetWithArrayShouldThrowArgumentNullException
public void SetWithArrayShouldThrowArgumentNullException()
{
VectorD v = new VectorD(1);
v.Set((double[])null);
}
示例5: Set
public void Set()
{
VectorD v = new VectorD(5);
v.Set(0.123);
Assert.AreEqual(5, v.NumberOfElements);
for (int i = 0; i < 5; i++)
Assert.AreEqual(0.123, v[i]);
v.Set(new VectorD(new double[] { 1, 2, 3, 4, 5 }));
Assert.AreEqual(5, v.NumberOfElements);
Assert.AreEqual(1, v[0]);
Assert.AreEqual(2, v[1]);
Assert.AreEqual(3, v[2]);
Assert.AreEqual(4, v[3]);
Assert.AreEqual(5, v[4]);
v.Set(new double[] { 1, 2, 3, 4, 5 });
Assert.AreEqual(5, v.NumberOfElements);
Assert.AreEqual(1, v[0]);
Assert.AreEqual(2, v[1]);
Assert.AreEqual(3, v[2]);
Assert.AreEqual(4, v[3]);
Assert.AreEqual(5, v[4]);
v.Set(new List<double>(new double[] { 1, 2, 3, 4, 5 }));
Assert.AreEqual(5, v.NumberOfElements);
Assert.AreEqual(1, v[0]);
Assert.AreEqual(2, v[1]);
Assert.AreEqual(3, v[2]);
Assert.AreEqual(4, v[3]);
Assert.AreEqual(5, v[4]);
}
示例6: ProjectTo2
public void ProjectTo2()
{
VectorD unitX = new VectorD(new double[] { 1, 0, 0, 0 });
VectorD unitY = new VectorD(new double[] { 0, 1, 0, 0 });
VectorD unitZ = new VectorD(new double[] { 0, 0, 1, 0 });
VectorD one = new VectorD(new double[] { 1, 1, 1, 1 });
// Project (1, 1, 1) to axes
VectorD projection = new VectorD(new double[] { 1, 1, 1, 0 });
projection.ProjectTo(unitX);
Assert.AreEqual(unitX, projection);
projection.Set(one);
projection.ProjectTo(unitY);
Assert.AreEqual(unitY, projection);
projection.Set(one);
projection.ProjectTo(unitZ);
Assert.AreEqual(unitZ, projection);
// Project axes to (1, 1, 1)
VectorD expected = new VectorD(new double[] { 1, 1, 1, 0 }) / 3.0;
projection.Set(unitX);
projection.ProjectTo(new VectorD(new double[] { 1, 1, 1, 0 }));
Assert.AreEqual(expected, projection);
projection.Set(unitY);
projection.ProjectTo(new VectorD(new double[] { 1, 1, 1, 0 }));
Assert.AreEqual(expected, projection);
projection.Set(unitZ);
projection.ProjectTo(new VectorD(new double[] { 1, 1, 1, 0 }));
Assert.AreEqual(expected, projection);
}