本文整理汇总了C#中Matrix.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.Clone方法的具体用法?C# Matrix.Clone怎么用?C# Matrix.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix.Clone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QRD
public QRD(Matrix A)
{
_QR = A.Clone();
_diag = new Matrix(ColumnCount);
double val = 0;
double norm = 0;
for (int k = 0; k < ColumnCount; k++)
{
for (int i = k; i < RowCount; i++)
{
norm = 0;
val = _QR[i, k];
if (Math.Abs(norm) > Math.Abs(val))
{
double r = val / norm;
norm = Math.Abs(norm) * Math.Sqrt(1 + r * r);
}
else if (Math.Abs(val) > 0.00000001)
{
double r = norm / val;
norm = Math.Abs(val) * Math.Sqrt(1 + r * r);
}
}
if (norm != 0.0)
{
if (_QR[k,k] < 0)
{
norm = -norm;
}
for (int i = k; i < RowCount; i++)
{
_QR[i,k] /= norm;
}
_QR[k,k] += 1.0;
for (int j = k + 1; j < ColumnCount; j++)
{
double s = 0.0;
for (int i = k; i < RowCount; i++)
{
s += _QR[i,k] * _QR[i,j];
}
s = (-s) / _QR[k,k];
for (int i = k; i < RowCount; i++)
{
_QR[i,j] += s * _QR[i,k];
}
}
}
_diag[k] = -norm;
}
_isFullRank = CheckIsDiagFullRank();
}
示例2: QpProblem
public QpProblem(Matrix<double> Q, Vector<double> g, Matrix<double> A, Vector<double> b)
{
this._Q = Q.Clone();
this._c = g.Clone();
this._A = A.Clone();
this._b = b.Clone();
}
示例3: SurfaceBackgroundChangeMemento
public SurfaceBackgroundChangeMemento(Surface surface, Matrix matrix) {
_surface = surface;
_image = surface.Image;
_matrix = matrix.Clone();
// Make sure the reverse is applied
_matrix.Invert();
}
示例4: QrDecomposition
/// <summary>Construct a QR decomposition.</summary>
public QrDecomposition(Matrix value)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
this.QR = (Matrix) value.Clone();
double[][] qr = this.QR.Array;
int m = value.Rows;
int n = value.Columns;
this.Rdiag = new double[n];
for (int k = 0; k < n; k++)
{
// Compute 2-norm of k-th column without under/overflow.
double nrm = 0;
for (int i = k; i < m; i++)
{
nrm = Hypotenuse(nrm,qr[i][k]);
}
if (nrm != 0.0)
{
// Form k-th Householder vector.
if (qr[k][k] < 0)
{
nrm = -nrm;
}
for (int i = k; i < m; i++)
{
qr[i][k] /= nrm;
}
qr[k][k] += 1.0;
// Apply transformation to remaining columns.
for (int j = k+1; j < n; j++)
{
double s = 0.0;
for (int i = k; i < m; i++)
{
s += qr[i][k]*qr[i][j];
}
s = -s/qr[k][k];
for (int i = k; i < m; i++)
{
qr[i][j] += s*qr[i][k];
}
}
}
this.Rdiag[k] = -nrm;
}
}
示例5: TransformBenchmark
public TransformBenchmark(string name, Surface dst, MaskedSurface src, Matrix transform, bool highQuality)
: base(name)
{
this.dst = dst;
this.src = src;
this.transform = transform.Clone();
this.highQuality = highQuality;
}
示例6: CalcTransform
private void CalcTransform()
{
Matrix m = new Matrix();
m.Translate(Width / 2, Height / 2);
m.Scale((float)zoom, (float)zoom);
m.Translate(offset.X, offset.Y);
transform = m;
itransform = m.Clone();
itransform.Invert();
}
示例7: SquareMatrixInverse
private Matrix SquareMatrixInverse(Matrix argument)
{
int size = argument.Rows;
Matrix original = argument.Clone();
Matrix inverse = new SimpleMatrix(size, size);
for (int i = 0; i < size; i++)
{
inverse[i, i] = 1;
}
for (int i = 0; i < size; i++)
{
double reciprocal = 1 / original[i, i];
for (int k = 0; k < size; k++)
{
original[i, k] *= reciprocal;
inverse[i, k] *= reciprocal;
}
for (int j = 0; j < size; j++)
{
if (i == j)
{
continue;
}
double quotient = original[j, i] / original[i, i];
for (int k = 0; k < size; k++)
{
original[j, k] = original[j, k] - quotient * original[i, k];
inverse[j, k] = inverse[j, k] - quotient * inverse[i, k];
}
}
}
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
if ((i == j && original[i, j] != 1) ||
(i != j && original[i, j] != 0))
{
// no inverse found report error
throw new Error.Domain(DomainErrorText);
}
}
}
return inverse;
}
示例8: Solve
/// <summary>
/// Computes the solution to a real system of linear equations A * X = B, where A is a general matrix.
/// </summary>
/// <param name="A">The square matrix.</param>
/// <param name="B">The vector containing the right-hand side of the linear system.</param>
/// <returns>A vector containing the solution to the linear system of equations.</returns>
public Vector Solve(Matrix A, Vector B)
{
this.CheckDimensions(A, B);
Matrix Solution = B.Clone();
Matrix AClon = A.Clone();
this.SolveInplace(AClon, Solution);
return Solution.GetColumnVector(0);
}
示例9: calc2DCoords
public void calc2DCoords()
{
// From http://en.wikipedia.org/wiki/3D_projection#Perspective_projection :
//
// Point(X|Y|X) a{x,y,z} The point in 3D space that is to be projected.
// Cube.Camera(X|Y|X) c{x,y,z} The location of the camera.
// Cube.Theta(X|Y|X) 0{x,y,z} The rotation of the camera. When c{x,y,z}=<0,0,0>, and 0{x,y,z}=<0,0,0>, the 3D vector <1,2,0> is projected to the 2D vector <1,2>.
// Cube.Viewer(X|Y|X) e{x,y,z} The viewer's position relative to the display surface.
// Bsub(X|Y) b{x,y} The 2D projection of a.
//
double BsubX, BsubY;
Matrix convMat1, convMat2, convMat3, convMat4, convMat41, convMat42, DsubXYZ;
double CosThetaX = Math.Cos(Cube.ThetaX); double SinThetaX = Math.Sin(Cube.ThetaX);
double CosThetaY = Math.Cos(Cube.ThetaY); double SinThetaY = Math.Sin(Cube.ThetaY);
double CosThetaZ = Math.Cos(Cube.ThetaZ); double SinThetaZ = Math.Sin(Cube.ThetaZ);
convMat1 = new Matrix(new double[][] {
new double[] { 1, 0, 0 },
new double[] { 0, CosThetaX, ((-1)*(SinThetaX)) },
new double[] { 0, SinThetaX, CosThetaX }
});
convMat2 = new Matrix(new double[][] {
new double[] { CosThetaY, 0, SinThetaY },
new double[] { 0, 1, 0 },
new double[] { ((-1)*(SinThetaY)), 0, CosThetaY }
});
convMat3 = new Matrix(new double[][] {
new double[] { CosThetaZ, ((-1)*(SinThetaZ)), 0 },
new double[] { SinThetaZ, CosThetaZ, 0 },
new double[] { 0, 0, 1 }
});
convMat41 = new Matrix(new double[][] {
new double[] { X3 },
new double[] { Y3 },
new double[] { Z3 }
});
convMat42 = new Matrix(new double[][] {
new double[] { Cube.CameraX },
new double[] { Cube.CameraY },
new double[] { Cube.CameraZ }
});
convMat4 = convMat41.Clone();
convMat4.Subtract(convMat42);
DsubXYZ = ((convMat1.Multiply(convMat2)).Multiply(convMat3)).Multiply(convMat4);
BsubX = (DsubXYZ[0, 0] - Cube.ViewerX) / (Cube.ViewerZ / DsubXYZ[2, 0]);
BsubY = (DsubXYZ[1, 0] - Cube.ViewerY) / (Cube.ViewerZ / DsubXYZ[2, 0]);
X2 = (int)((BsubX * 50) + 250);
Y2 = (int)((BsubY * 50) + 250);
// Can include Math.Sqrt() here if needed. Math.Sqrt() is slow so its omitted. Doesn't change anything.
distanceFromViewer = Math.Pow((X3 - Cube.ViewerX), 2) + Math.Pow((Y3 - Cube.ViewerY), 2) + Math.Pow((Z3 - Cube.ViewerZ), 2);
}
示例10: NoiseOld
public static Matrix NoiseOld(Matrix pic, int ammount)
{
Matrix noised = pic.Clone();
int limit = pic.RowCount;
for (int i = 0; i < ammount; ++i)
{
if (!RandomGenerator.Match(ammount)) continue;
int x = RandomGenerator.Next(limit);
int y = RandomGenerator.Next(limit);
noised[y, x] = noised[y, x] > 0 ? -1 : +1;
}
return noised;
}
示例11: CloneExample
public void CloneExample()
{
var matrix = new Matrix(2, 2);
matrix[0, 0] = 1;
matrix[0, 1] = 2;
matrix[1, 0] = 3;
matrix[1, 1] = 4;
var clone = matrix.Clone();
Assert.AreEqual(matrix.Rows, clone.Rows);
Assert.AreEqual(matrix.Columns, clone.Columns);
Assert.IsTrue(matrix.Equals(clone));
}
示例12: Noise
public static Matrix Noise(Matrix pic, int ammount)
{
Matrix noised = pic.Clone();
for (int r = 0; r < pic.RowCount; ++r)
{
for (int c = 0; c < pic.ColumnCount; ++c)
{
if (RandomGenerator.Match(ammount))
{
noised[r, c] = noised[r, c] > 0 ? -1 : +1;
}
}
}
return noised;
}
示例13: QRDecomposition
/// <summary>QR Decomposition, computed by Householder reflections.</summary>
/// <remarks>Provides access to R, the Householder vectors and computes Q.</remarks>
/// <param name="A">Rectangular matrix</param>
public QRDecomposition(Matrix A)
{
// Initialize.
QR = (Matrix) A.Clone();
Rdiag = new double[n];
// Main loop.
for (int k = 0; k < n; k++)
{
// Compute 2-norm of k-th column without under/overflow.
double nrm = 0;
for (int i = k; i < m; i++)
{
nrm = Fn.Hypot(nrm, QR[i, k]);
}
if (nrm != 0.0)
{
// Form k-th Householder vector.
if (QR[k, k] < 0)
{
nrm = - nrm;
}
for (int i = k; i < m; i++)
{
QR[i, k] /= nrm;
}
QR[k, k] += 1.0;
// Apply transformation to remaining columns.
for (int j = k + 1; j < n; j++)
{
double s = 0.0;
for (int i = k; i < m; i++)
{
s += QR[i, k] * QR[i, j];
}
s = (- s) / QR[k, k];
for (int i = k; i < m; i++)
{
QR[i, j] += s * QR[i, k];
}
}
}
Rdiag[k] = - nrm;
}
}
示例14: Solve
public IVector Solve(Matrix a, Matrix b)
{
int i, j;
var n = a.RowsCount;
var A = a.Clone();
var B = b.Clone();
n--;
for (i = 0; i < n - 1; i++)
{
for (j = i + 1; j < n; j++)
{
A[j, i] = -A[j, i] / A[i, i];
for (var k = i + 1; k < n; k++)
{
A[j, k] = A[j, k] + A[j, i] * A[i, k];
B[j, 0] = B[j, 0] + A[j, i] * B[i, 0];
}
}
}
var x = new double[n];
x[n] = B[n, 0] / A[n, n];
for (i = n - 1; i >= 0; i--)
{
var h = B[i, 0];
for (j = i + 1; j < n; j++)
{
h = h - x[j] * A[i, j];
}
x[i] = h / A[i, i];
}
return new Vector(x);
}
示例15: SetupTransform
private void SetupTransform()
{
//world points
float x1 = 0, y1 = 0, x2 = 100, y2 = 100;
//device points
Rectangle crect = this.ClientRectangle;
float x1d = (float)5 * crect.Width / 14;//up left corner
float y1d = 0.1f * crect.Height;//up left corner
float x2d = (float)13 * crect.Width / 14;//bottom rigth corner
float y2d = 0.9f * crect.Height;//bottom right corner
//calcutae the scalling
s1 = (x1d - x2d) / (x1 - x2);
s2 = (y1d - y2d) / (y1 - y2);
t1 = (x1 * x2d - x2 * x1d) / (x1 - x2);
t2 = (y1 * y2d - y2 * y1d) / (y1 - y2);
m = new Matrix();
m.Translate(t1, t2);//transalation
m.Scale(s1, s2);//scaling
//get the inverse
m.Invert();
minv = m.Clone();
m.Invert();
}