English  Español  Português  Français  Italiano  Deutsch  Nederlands  Svenska  Dansk  Suomi  Norsk  Русский  Polski  Română  Български  Hrvatski  Česky  中国  中國  日本語  한국어  Ελληνική  हिन्दी  العربية 
线性代数
Colin Fahey

1. 软件

LinearAlgebra.zip
线性代数的源代码(C#)
19910 字节
MD5: 11d8c8035cac30ba543e5e0b72ee9767

2. 导言

本文介绍了向量和矩阵在(d)三维空间。

3. (d)三维空间:属性

3.1 阵列

“数组” :收集了变数,例如,每个变量有其独特的名称,这样的名字可以被指派的命令。
整数的价值可以被用来作为名字的变量在一个数组。
例如,如果一个数组包含(d)的变数,那么整数价值观{ 0, 1, 2, ..., (d-1) }可以的名称分配给变量在数组中。

3.2 (d)维向量

(d)维向量” :一阵列(d)变数。
“载体的组成部分” :一个变量在一个载体。

3.3 (d)三维向量空间

“一维空间” :一套完整的价值观,可存储由一变。
(d)三维空间” :一套完整的组合的价值,可以储存阵列(d)变数。
正式的定义, “向量空间” :
(T)的一个基本类型(例如:实数,整数,复杂的号码,理性的号码等) 。
任何一个变量的基本类型命名为一个“标” 。
1 “(T)(d)三维向量空间” ,是一套(S)(d)三维向量有两个行动,矢量此外(+) ,和标量乘法(*) ,满足以下条件:
( 1 )如果(v)(w)是任何两个向量在(S) ,然后(v + w)也是一个载体,在(S) ;
( 2 )如果(u)(v)(w)任何三个载体,在(S) ,然后(u + v) + w = u + (v + w) ;
[添加剂交换]
( 3 )如果(v)(w)是任何两个向量在(S) ,然后(v + w) = (w + v) ;
[添加剂结合]
( 4 )有一个“零矢量” , (0) ,在(S) ,例如,对于任何向量(v)(S)(v + (0)) = v ;
[添加剂的身份]
( 5 )如果(c)是任何标量类型(T)(v)是任何载体在(S) ,那么产品(c * v)是一个载体,在(S) ;
( 6 )如果(a)(b)(c)是任何标量类型(T)(v)(w)任何载体的(S) ,然后(a + b) * v = a*v + b*vc*(v + w) = c*v + c*w ;
[乘法distributivity ]
( 7 )如果(a)(b)是任何标量类型(T)(v)是任何载体在(S) ,然后(a*b)*v = a*(b*v) ;
( 8 )如果“1”是一个标量型(T)这种(1*1)=1(v)是任何载体在(S) ,然后(1*v) = v ;
( 9 )为每个矢量(v)(S) ,矢量(-1)*v = -v满足v + (-v) = (0) ;
[加法逆]

3.4 (d)维向量代码

下面的代码显示了如何(d)维向量,与64位浮点型元件,可以实施。
一个数组是足以代表一个向量。
下面的代码有一个阵列中所载的一类,只为方便。
该守则是不打算效率。
一个结构(例如: “struct” ,价值型)代表载体固定数量的尺寸(例如: 34 )很可能是更为有效比一般(d)维向量阶层在这里显示。
虽然下面的代码定义了向量与浮点型元件,这份文件还使用了向量整数组成部分。
下面的代码可以很容易被修改,以落实向量整数组成部分。
using System;
using System.Collections.Generic;
using System.Text;

// Multidimensional vector with 64-bit floating-point components:

public class VectorF64
{
    private double[] components;




    public int Dimensions()
    {
        if (null == this.components)
        {
            return (0);
        }

        return (this.components.Length);
    }




    public VectorF64()
    {
        this.components = null;
    }




    public VectorF64params double[] paramValues )
    {
        this.components = null;

        if (null == paramValues)
        {
            return;
        }

        int dimensions = paramValues.Length;

        this.components = new double[dimensions];

        for (int i = 0; i < dimensions; i++)
        {
            this.components[i] = paramValues[i];
        }
    }




    public VectorF64VectorF64 other )
    {
        this.components = null;

        if (null == other)
        {
            return;
        }

        if (null == other.components)
        {
            return;
        }

        int dimensions = other.Dimensions();

        this.components = new double[dimensions];

        for (int i = 0; i < dimensions; i++)
        {
            this.components[i] = other.components[i];
        }
    }




    public double this[int index]
    {
        get
        {
            if (null == this.components)
            {
                return (0.0);
            }

            if
            (
                   (index >= 0)
                && (index < this.components.Length)
            )
            {
                return (this.components[index]);
            }

            return (0.0);
        }

        set
        {
            if (null == this.components)
            {
                return;
            }

            if
            (
                   (index >= 0)
                && (index < this.components.Length)
            )
            {
                this.components[index] = value;
            }
        }
    }




    public void Write( int precision )
    {
        if (null == this.components)
        {
            Log.Write( String.Empty + '(' + ' ' + ')' );
            return;
        }

        int dimensions = this.Dimensions();
        if (0 == dimensions)
        {
            Log.Write( String.Empty + '(' + ' ' + ')' );
            return;
        }

        // Determine the largest component width in characters
        // so that we can make all components an equal width.
        int largestComponentWidth = 1;
        for (int i = 0; i < dimensions; i++)
        {
            // { index [,minwidth] [:typeCode[precision]] }
            //      (minwidth<0) means left-justify
            String text = String.Format( String.Empty + '{' + '0' + ':'
                + 'g' + precision + '}', this[i] );
            if (text.Length > largestComponentWidth)
            {
                largestComponentWidth = text.Length;
            }
        }

        Log.Write( '(' );
        for (int i = 0; i < dimensions; i++)
        {
            Log.Write( ' ' );
            String text =
                String.Format( String.Empty + '{' + '0' + ','
                + largestComponentWidth + ':' + 'g' + precision + '}',
                this[i] );
            Log.Write( text );
            if ((i + 1) < dimensions)
            {
                Log.Write( ',' );
            }
            else
            {
                Log.Write( ' ' );
            }
        }
        Log.Write( ')' );
    }




    public void WriteLine( int precision )
    {
        this.Write( precision );
        Log.WriteLine();
    }




    public void WriteLine()
    {
        const int defaultPrecision = 8;
        this.Write( defaultPrecision );
        Log.WriteLine();
    }




    // . . .




    public static void Test()
    {
        // A 3-dimensional vector with 64-bit floating-point components:
        VectorF64 v3 = new VectorF640.01.02.0 );
        v3.WriteLine(); // ( 0, 1, 2 )

        // A 4-dimensional vector with 64-bit floating-point components:
        VectorF64 v4 = new VectorF640.01.02.03.0 );
        v4.WriteLine(); // ( 0, 1, 2, 3 )

        // . . .
    }
}
(d)三维零向量” :向量与所有(d)组件等于零。
public class VectorF64
{
    // . . .




    public static VectorF64 Zero( int dimensions )
    {
        VectorF64 zero = new VectorF64();

        zero.components = new double[dimensions];

        for (int i = 0; i < dimensions; i++)
        {
            zero[i] = 0.0;
        }

        return (zero);
    }




    // . . .




    public static void Test()
    {
        // . . .


        // An 8-dimensional vector with all 8 64-bit floating-point
        // components set to zero:
        VectorF64 z = VectorF64.Zero( 8 );
        z.WriteLine(); // ( 0, 0, 0, 0, 0, 0, 0, 0 )


        // . . .
    }
}

3.5 (d)三维空间:点

(d)三维空间点” :一阵列(d)变数与特定值( “坐标值” ) 。
(d)三维空间资料来源” : 1阵列(d)变数与所有的价值等于零。

3.6 (d)三维矢量:非相对的和相对

1 (d)维向量即“非相对”是一个(d)维向量,直接代表了一个状态或配置。
1 (d)维向量认为是“相对的”是一个(d)维向量代表更改了一套组件。
相对矢量可以代表之间的差异,两个非相对载体。
鉴于一个相对的载体,确定一个非相对的地位,或配置使用相对矢量需要相结合,相对向量与非相对载体。
非相对的载体和相对载体,都是载体。
是否有特别的矢量是不相对多数或相对必须指定时,向量的定义。
如果(d)维向量被解释为不相对的,那么(d)维向量可以代表这一点在(d)三维空间。

3.7 (d)维向量此外,减法,结垢

矢量此外,减法,结垢:
public class VectorF64
{
    // . . .




    public static VectorF64 operator +( VectorF64 a, VectorF64 b )
    {
        if ((null == a) ¦¦ (null == b))
        {
            return (new VectorF64()); // Vector not specified.
        }

        if ((null == a.components) ¦¦ (null == b.components))
        {
            return (new VectorF64()); // Vector is empty.
        }

        if (a.Dimensions() != b.Dimensions())
        {
            return (new VectorF64()); // Vectors not the same size.
        }

        int dimensions = a.Dimensions();

        VectorF64 result = VectorF64.Zero( dimensions );

        for (int i = 0; i < dimensions; i++)
        {
            result[i] = a[i] + b[i];
        }

        return (result);
    }




    public static VectorF64 operator -( VectorF64 a, VectorF64 b )
    {
        if ((null == a) ¦¦ (null == b))
        {
            return (new VectorF64()); // Vector not specified.
        }

        if ((null == a.components) ¦¦ (null == b.components))
        {
            return (new VectorF64()); // Vector is empty.
        }

        if (a.Dimensions() != b.Dimensions())
        {
            return (new VectorF64()); // Vectors not the same size.
        }

        int dimensions = a.Dimensions();

        VectorF64 result = VectorF64.Zero( dimensions );

        for (int i = 0; i < dimensions; i++)
        {
            result[i] = a[i] - b[i];
        }

        return (result);
    }




    public static VectorF64 operator -( VectorF64 a )
    {
        if (null == a)
        {
            return (new VectorF64()); // Vector not specified.
        }

        if (null == a.components)
        {
            return (new VectorF64()); // Vector is empty.
        }

        int dimensions = a.Dimensions();

        VectorF64 result = VectorF64.Zero( dimensions );

        for (int i = 0; i < dimensions; i++)
        {
            result[i] = (-( a[i] ));
        }

        return (result);
    }




    public static VectorF64 operator *( double scale, VectorF64 a )
    {
        if (null == a)
        {
            return (new VectorF64()); // Vector not specified.
        }

        if (null == a.components)
        {
            return (new VectorF64()); // Vector is empty.
        }

        int dimensions = a.Dimensions();

        VectorF64 result = VectorF64.Zero( dimensions );

        for (int i = 0; i < dimensions; i++)
        {
            result[i] = scale * a[i];
        }

        return (result);
    }




    public static VectorF64 operator *( VectorF64 a, double scale )
    {
        if (null == a)
        {
            return (new VectorF64()); // Vector not specified.
        }

        if (null == a.components)
        {
            return (new VectorF64()); // Vector is empty.
        }

        int dimensions = a.Dimensions();

        VectorF64 result = VectorF64.Zero( dimensions );

        for (int i = 0; i < dimensions; i++)
        {
            result[i] = scale * a[i];
        }

        return (result);
    }




    // . . .




    public static void Test()
    {
        // . . .


        // Examples of vector addition, subtraction, and scaling:

        VectorF64 a = new VectorF640.01.02.03.0 );
        a.WriteLine(); // ( 0, 1, 2, 3 )
        VectorF64 b = new VectorF643.02.01.00.0 );
        b.WriteLine(); // ( 3, 2, 1, 0 )
        VectorF64 c = new VectorF64();
        c.WriteLine(); // ( )

        c = a + b;
        c.WriteLine(); // ( 3, 3, 3, 3 )

        c = a - b;
        c.WriteLine(); // ( -3, -1,  1,  3 )

        c = -b;
        c.WriteLine(); // ( -3, -2, -1,  0 )

        c = 3.0 * a;
        c.WriteLine(); // ( 0, 3, 6, 9 )


        // . . .
    }
}

3.8 (d)二维的基础上载体

正式的定义的“基础上”的向量空间:
(T)的一个基本类型(例如:实数,整数,复杂的号码,理性的号码等) 。
任何一个变量的基本类型命名为一个“标” 。
(V)是一个(T) “型(d)三维向量空间” 。
如果非零矢量{ u1, u2, ..., ud }(V)是这样的每一个向量(v)(V)可被写入为a的“线性组合,”这些载体, v = c1*u1 + c2*u2 + ...  + cd*ud ,其中{ c1, c2, ..., cd }是标型(T) ,然后(V)是“跨距”由载体{ u1, u2, ..., ud }
任何一套非零矢量{ u1, u2, ..., ud } “跨”向量空间(V)命名的“基础上” (V)
一个简单的“基础上”一(d)三维向量空间,是一套(d)鲜明的(d)三维向量,每一个组成部分,等于一和所有其他组件等于零。
这样的基础上向量“的正交” ,这意味着它们是相互垂直( “正交” )和每个向量有单位长度。
每一个这样的载体是一个单位向量平行的一对(d)坐标轴。
表达了一个任意向量作为一个“线性组合” ,这些载体的基础上,是直接;每一个组成部分,任意的矢量乘以相应的基础载体,这些产品加起来,形成任意向量。
下面的代码显示了如何矢量可表示为“线性组合”的基础上载体。
下面的代码定义了一个任意正交一套的基础载体。
public class VectorF64
{
    // . . .




    public static VectorF64 BasisVector( int dimensions, int componentIndex )
    {
        if (dimensions < 0)
        {
            // Invalid number of dimensions specified.
            return (new VectorF64());
        }

        VectorF64 basisVector = VectorF64.Zero( dimensions );

        if ((componentIndex >= 0) && (componentIndex < dimensions))
        {
            basisVector[ componentIndex ] = 1.0;
        }

        return (basisVector);
    }




    // . . .




    public static void Test()
    {

        // . . .


        // The 4 basis vectors of 4-dimensional space,
        // each with 4 64-bit floating-point components:

        VectorF64 b0 = VectorF64.BasisVector( 40 );
        b0.WriteLine(); // ( 1, 0, 0, 0 )

        VectorF64 b1 = VectorF64.BasisVector( 41 );
        b1.WriteLine(); // ( 0, 1, 0, 0 )

        VectorF64 b2 = VectorF64.BasisVector( 42 );
        b2.WriteLine(); // ( 0, 0, 1, 0 )

        VectorF64 b3 = VectorF64.BasisVector( 43 );
        b3.WriteLine(); // ( 0, 0, 0, 1 )


        // . . .
    }
}
任何载体,在(d)三维空间可表示为一笔的产品数量和载体的基础上:
public class VectorF64
{
    // . . .




    public static void Test()
    {

        // . . .


        // The following two vectors are equivalent:

        // A 4-dimensional vector with 64-bit floating-point components:
        VectorF64 va = new VectorF640.11.12.23.3 );
        va.WriteLine(); // ( 0.1, 1.1, 2.2, 3.3 )

        // A 4-dimensional vector formed by scaling the 4 independent
        // basis vectors for 4-dimensional space:
        VectorF64 vb =
              0.1 * VectorF64.BasisVector( 40 )
            + 1.1 * VectorF64.BasisVector( 41 )
            + 2.2 * VectorF64.BasisVector( 42 )
            + 3.3 * VectorF64.BasisVector( 43 );
        vb.WriteLine(); // ( 0.1, 1.1, 2.2, 3.3 )


        // . . .
    }
}

3.9 (d)三维空间:之间的距离点

(P)是一个(d)维向量,代表点在(d)三维空间。
(Q)是一个(d)维向量,代表点在(d)三维空间。
(R)是一个(d)维向量代表的改变(d)坐标,以获得从点(P)(Q) ; R = (Q - P)
在一个三维空间, P = ( p0 )Q = ( q0 )R = (Q - P) = ( q0 - p0 )
之间的距离,有两点是: Abs( q0 - p0 )
在两维空间, P = ( p0, p1 )Q = ( q0, q1 )R = (Q - P) = ( q0-p0, q1-p1 )
解释二垂直位移为垂直双方的权利,三角,之间的距离点对应到长度的hypotenuse该三角。
该Pythagorean公式, (a*a) + (b*b) = (c*c) ,其中(a)(b)是长度的垂直双方的权利,三角,和(c)是长度的hypotenuse (斜方) ,可以用来确定之间的距离两点: Sqrt( Sq(q0-p0) + Sq(q1-p1) )
在三维空间, P = ( p0, p1, p2 )Q = ( q0, q1, q2 )R = (Q - P) = ( q0-p0, q1-p1, q2-p2 )
解释位移( q0-p0, q1-p1, 0 )作为垂直双方的权利,三角,以及使用Pythagorean公式,给出了之间的距离(P)点和点( q0, q1, p2 )d01 = Sqrt( Sq(q0-p0) + Sq(q1-p1) )
位移( q0-p0, q1-p1, 0 )是垂直位移( 0, 0, q2-p2 ) ,另有右三角可以形成,以及Pythagorean公式可再次使用。
因此,距离(P)点,以点(Q)是由于: Sqrt( Sq(d01) + Sq(q2-p2) ) = Sqrt( (Sq(q0-p0) + Sq(q1-p1)) + Sq(q2-p2) ) = Sqrt( Sq(q0-p0) + Sq(q1-p1) + Sq(q2-p2) )
该方法延长距离公式,从两维空间,以三维立体空间,可用于反复,最终确定距离公式为(d)三维空间: Sqrt( (Sq(q0-p0) + Sq(q1-p1)) + Sq(q2-p2) + ...  + Sq(qd-pd) )
下面的代码定义了一个函数的命名“长度”计算的长度一(d)维向量。
当一个载体,代表了位移两点之间在(d)三维空间中,长度的向量代表之间的距离,这些两点。
public class VectorF64
{
    // . . .




    public double Length()
    {
        if (null == this.components)
        {
            return (0.0); // Vector empty.
        }

        int dimensions = this.Dimensions();

        double sumOfSquares = 0.0;
        for (int i = 0; i < dimensions; i++)
        {
            sumOfSquares += (this[i] * this[i]);
        }

        double length = Math.Sqrt( sumOfSquares );

        return (length);
    }




    public static double Length( VectorF64 a )
    {
        if (null == a)
        {
            return (0.0); // Vector not specified.
        }

        if (null == a.components)
        {
            return (0.0); // Vector is empty.
        }

        return (a.Length());
    }




    // . . .




    public static void Test()
    {
        // . . .


        // Example of vector length:

        // A 6-dimensional vector representing a point (p):
        VectorF64 p = new VectorF640.01.02.03.04.05.0 );
        p.WriteLine(); // ( 0, 1, 2, 3, 4, 5 )

        // A 6-dimensional vector representing a point (q):
        VectorF64 q = new VectorF64-5.04.0-3.02.0-1.00.0 );
        q.WriteLine(); // ( -5,  4, -3,  2, -1,  0 )

        // A 6-dimensional vector representing the displacement
        // from point (p) to point (q):
        VectorF64 r = q - p;
        r.WriteLine(); // ( -5,  3, -5, -1, -5, -5 )

        // The distance between point (p) and point (q)
        // in 6-dimensional space:
        double distance = r.Length();
        Log.WriteLine( distance ); // 10.4880884817015


        // . . .
    }
}

3.10 (d)三维矢量:斑点产品

“网络产品”转换为2 (d)三维向量来一个号码。
下面的代码计算一个点的产物,两个矢量:
public class VectorF64
{
    // . . .





    public static double Dot( VectorF64 a, VectorF64 b )
    {
        if ((null == a) ¦¦ (null == b))
        {
            return (0.0); // Vector not specified.
        }

        if ((null == a.components) ¦¦ (null == b.components))
        {
            return (0.0); // Vector is empty.
        }

        if (a.Dimensions() != b.Dimensions())
        {
            return (0.0); // Vectors not the same size.
        }

        int dimensions = a.Dimensions();

        double dotProduct = 0.0;
        for (int i = 0; i < dimensions; i++)
        {
            dotProduct += (a[i] * b[i]);
        }

        return (dotProduct);
    }




    // . . .
}
任何载体, (A)Length(A) = Sqrt(Dot(A,A))

3.11 (d)三维矢量:定义“并行”

载体(A)(B) “平行”如果所有的下列情况:
( 1 ) A.Length() > 0 ;
( 2 ) B.Length() > 0 ;
( 3 ) Abs(Dot(A,B)) = A.Length()*B.Length()
下面的代码决定,如果对向量平行(可能反不结盟) 。
浮点型号码可以累积误差在小数部分,由于有限的精度,因此,计算机代码应包括非零公差时,比较浮动点的数目。
该守则包括,例如容忍的价值观,但例如容忍的价值观可能是不恰当的一些任务。
public class VectorF64
{
    // . . .




    public static bool Parallel( VectorF64 a, VectorF64 b )
    {
        // Smallest normalized float : 1.1754943e-38
        // Smallest normalized double: 2.2250738585072020e-308
        double nonZeroThreshold = 1.0e-38// conservative for double
        // double: (52+1)-bit mantissa; log10(2^53)=15.95 decimal digits
        double fractionalDifferenceThreshold = 1.0e-14// conservative

        if ((null == a) ¦¦ (null == b))
        {
            return (false); // Vector is not specified.
        }

        if ((null == a.components) ¦¦ (null == b.components))
        {
            return (false); // Vector is empty.
        }

        if (a.Dimensions() != b.Dimensions())
        {
            return (false); // Vectors not the same size.
        }

        double lengthA = a.Length();
        if (lengthA <= nonZeroThreshold)
        {
            return (false);
        }

        double lengthB = b.Length();
        if (lengthB <= nonZeroThreshold)
        {
            return (false);
        }

        double oneImpliesParallel =
            Math.Abs( VectorF64.Dot( a, b ) ) / (lengthA * lengthB);

        double absoluteDifferenceFromOne =
            Math.Abs( oneImpliesParallel - 1.0 );

        if (absoluteDifferenceFromOne <= fractionalDifferenceThreshold)
        {
            return (true);
        }

        return (false);
    }




    // . . .




    public static void Test()
    {
        // . . .


        // Example of testing for parallel vectors:

        // A 6-dimensional vector:
        VectorF64 vf = new VectorF640.01.02.03.04.05.0 );
        vf.WriteLine(); // ( 0, 1, 2, 3, 4, 5 )

        // A 6-dimensional vector:
        VectorF64 vg = new VectorF640.0-2.0-4.0-6.0-8.0-10.0 );
        vg.WriteLine(); // (   0,  -2,  -4,  -6,  -8, -10 )

        // Determine if the specified vectors are parallel
        // (or "anti-aligned"):
        bool parallel = VectorF64.Parallel( vf, vg );
        Log.WriteLine( parallel ); // True

        // Add a non-negligible displacement to a component of a vector:
        vf[0] += 1.0e-5;
        vf.WriteLine(); // ( 1E-05,     1,     2,     3,     4,     5 )

        // Determine if the specified vectors are parallel
        // (or "anti-aligned"):
        parallel = VectorF64.Parallel( vf, vg );
        Log.WriteLine( parallel ); // False


        // . . .
    }
}

3.12 (d)三维矢量:定义“垂直”

载体(A)(B) “垂直”如果所有的下列情况:
( 1 ) A.Length() > 0 ;
( 2 ) B.Length() > 0 ;
( 3 ) Abs(Dot(A,B)) = 0
下面的代码决定,如果对向量垂直。浮点型号码可以累积误差在小数部分,由于有限的精度,因此,计算机代码应包括非零公差时,比较浮动点的数目。
该守则包括,例如容忍的价值观,但例如容忍的价值观可能是不恰当的一些任务。
public class VectorF64
{
    // . . .




    public static bool Perpendicular( VectorF64 a, VectorF64 b )
    {
        // Smallest normalized float : 1.1754943e-38
        // Smallest normalized double: 2.2250738585072020e-308
        double nonZeroThreshold = 1.0e-38// conservative for double
        // double: (52+1)-bit mantissa; log10(2^53)=15.95 decimal digits
        double fractionalDifferenceThreshold = 1.0e-14// conservative

        if ((null == a) ¦¦ (null == b))
        {
            return (false); // Vector is not specified.
        }

        if ((null == a.components) ¦¦ (null == b.components))
        {
            return (false); // Vector is empty.
        }

        if (a.Dimensions() != b.Dimensions())
        {
            return (false); // Vectors not the same size.
        }

        double lengthA = a.Length();
        if (lengthA <= nonZeroThreshold)
        {
            return (false);
        }

        double lengthB = b.Length();
        if (lengthB <= nonZeroThreshold)
        {
            return (false);
        }

        double zeroImpliesPerpendicular =
            Math.Abs( VectorF64.Dot( a, b ) ) / (lengthA * lengthB);

        double absoluteDifferenceFromZero =
            Math.Abs( zeroImpliesPerpendicular );

        if (absoluteDifferenceFromZero <= fractionalDifferenceThreshold)
        {
            return (true);
        }

        return (false);
    }




    // . . .




    public static void Test()
    {
        // . . .


        // Example of testing for perpendicular vectors:

        // A 6-dimensional vector:
        VectorF64 vf2 = new VectorF640.01.02.00.04.05.0 );
        vf2.WriteLine(); // ( 0, 1, 2, 0, 4, 5 )

        // A 6-dimensional vector:
        VectorF64 vg2 = new VectorF6410.00.00.0-5.00.00.0 );
        vg2.WriteLine(); // ( 10,  0,  0, -5,  0,  0 )

        // Determine if the specified vectors are perpendicular
        bool perpendicular = VectorF64.Perpendicular( vf2, vg2 );
        Log.WriteLine( perpendicular ); // True

        // Add a non-negligible displacement to a component of a vector:
        vf2[0] += 1.0e-13;
        vf2.WriteLine(); // ( 1E-13,    1,    2,    0,    4,    5 )

        // Determine if the specified vectors are perpendicular
        perpendicular = VectorF64.Perpendicular( vf2, vg2 );
        Log.WriteLine( perpendicular ); // False


        // . . .
    }
}

3.13 矩阵

“矩阵” :收集了变数,例如,每个变量有其独特的组合, “连续”的名称和“栏的”名称。
“项目” :一个变量在一个矩阵。
整数的价值可以被用来作为“行”的名称和“列”名称为变数,在一个矩阵。
例如,如果一个矩阵已(totalRows)行和(totalColumns)栏目,然后整数价值观{ 0, 1, ..., (totalRows-1) }可以的姓名,分配给行,和整数的价值观{ 0, 1, ..., (totalColumns-1) }可以的姓名,分配到各栏。
因此,一个变量在一个矩阵可以指定由指定一个对整数, ( row, column ) ,显示相结合的行和列指标,相应的具体的变数。
大小矩阵被指定为“(totalRows) * (totalColumns)” (或“(totalRows)(totalColumns) )” 。
这项命令的尺寸是一样的秩序方面用于指定项目,在矩阵( “( row, column )” ) 。
[本公约是有点不幸,因为许多两维的用途(例如:图像,图形等) ,一般的公约,是指定的尺寸作为“width * height”和坐标作为“( horizontal, vertical )” (或“( x, y )” ) 。
这是相反的顺序尺寸和坐标用来描述矩阵和他们的作品。 ]
矩阵与(totalRows)等于(totalColumns)名为“广场” ;否则,矩阵命名为“矩形” 。
一个矩阵,可被视为包含了一套“行向量” ,其中的变数,每列的被解释为属于一个载体。
一个矩阵也可以被视为含有一套“柱载体” ,而变量在每一列中被解释为属于一个载体。
矩阵可以代表各种各样的数学关系。
含义矩阵,以及行动可能是适当的处理作品的矩阵,依赖于上下文。
但是,也有基本规则的矩阵算法相关的许多背景下,这些基本规则,将被界定在随后的一节。
1阵列和(totalColumns)价值足以代表一个矩阵。
数组可以有(totalRows * totalColumns)变数,进入在( row, column )可以对应到阵列变数,指数((totalColumns * row) + column)
下面的代码定义了一个矩阵,与64位浮点型项目。
1阵列和(totalColumns)价值足以代表一个矩阵。
下面的代码有一个数组和一个(totalColumns)价值中所载的一类,只为方便。
下面的代码是不打算效率。
一个结构(例如: “struct” ,价值型)代表矩阵,特别是固定尺寸(例子: 2*23*3 ,或4*4 )很可能是更为有效比一般(totalRows * totalColumns)阶层在这里显示。
虽然下面的代码定义了一个矩阵与浮点型项目,此文章还利用矩阵的整数参赛作品。
下面的代码可以很容易地修改,以实施矩阵与整数参赛作品。
using System;
using System.Collections.Generic;
using System.Text;

// Matrix with 64-bit floating-point entries:

public class MatrixF64
{
    private int totalRows;
    private int totalColumns;
    private double[] entries;
    // matrix[ row, column ] = entries[ (totalColumns * row) + column ]




    public int Columns()
    {
        return (this.totalColumns);
    }




    public int Rows()
    {
        return (this.totalRo