Matrix, Array, and Variable Math

Top  Previous  Next

FreeFlyer provides Matrix, Array, and Variable objects to allow the user to perform various mathematical operations. Many of the properties of other objects in FreeFlyer are Variable, Array, or Matrix properties. Examples of each are: Spacecraft.A (Variable), Spacecraft.Position (Array), and Spacecraft.MOI (Matrix).

 

This page gives an overview of working with the Variable, Array, and Matrix objects in FreeFlyer. All of the properties and methods of each of these objects are presented in detail on these pages:

Matrix Properties and Methods

Array Properties and Methods

Variable Properties and Methods

 

Note: FreeFlyer also includes a Vector object, which can be displayed in 2D and 3D visualizations, easily determine the magnitude and direction to a specified target, and calculate intersections with ProximityZones or define custom CoordinateSystems. Vectors always have three elements, unlike an Array, which can have any number of elements. You can convert between Vectors and Arrays using syntax such as: Array1 = Vector1.Element or Vector1.Element = Array1.

 

 

Creating Variables, Arrays, and Matrices


The Variable object can be used to represent a number in FreeFlyer. Variables can be used as counters in For loops, indices in Arrays, flags for conditional control in While and If statements, combined in mathematical operations, and more. The syntax examples below show how to create Variables in FreeFlyer's FreeForm script editors.

 

 

The Array object contains a one-dimensional set of numbers.  Arrays can be used to store and manipulate data, such as through the use of various mathematical operators and functions. The examples below show some syntax options for creating Arrays.

 

 

The Matrix object provides numerous properties and methods for calculating various matrix statistics and decompositions. FreeFlyer also supports a variety of matrix operations. These features enable users to perform many analyses in FreeFlyer, such as custom attitude modeling, without needing to interface with external programs to execute complex calculations. You can create a Matrix using any of the following syntax options. A Matrix is initialized with a particular size, but can also be resized at any time after it has been created.

 

 

The Resize() Method allows the user to adjust the number of rows and columns in the matrix. When the matrix size is decreased, existing elements remain in their original positions, while elements outside the new matrix are discarded. When the matrix size is increased, existing elements stay in place, and the new rows and columns are filled with zeros.

 

 

Output Report:

 

       m

      2.000000000       4.000000000

      1.000000000       3.000000000

     

 

 

      m2

      3.000000000       24.00000000      9.000000000       0.000000000

      6.000000000       39.00000000      3.000000000       0.000000000

      12.00000000       7.000000000      32.00000000       0.000000000

      0.000000000       0.000000000      0.000000000       0.000000000

 

 

The Matrix object can only represent numeric, two-dimensional sets of data (i.e., n x n). However, you can manage multi-dimensional data by creating Lists of objects. For example, you could create a List of a List of a List of Variables to create a three dimensional set of numerical data. The syntax for creating such a List would be:

 

 

Variables, Arrays, and Matrices can also be created in FreeFlyer's Object Browser.

 

 

Assigning Values to Variables, Arrays, and Matrices


You can assign values to Variables, Arrays, and Matrices when they are created, or at any point in the Mission Sequence after they've been created. They can be assigned in a FreeForm script editor or using the Assignment command editor. Variables, Arrays, and Matrices can also be manipulated using various mathematical and logical operators and math functions.

 

It is very straightforward to assign any desired value to a Variable:

 

 

Arrays can be assigned using the syntax such as the examples shown below. Note that the definition of a virtual Array is surrounded by curly brackets, and each element is separated by a comma. Colons (:) can be used to indicate a range of elements.

 

 

You can assign the contents of a Matrix using any of the syntax options shown below. Note that the definition of a virtual Matrix is surrounded by square brackets, each element is separated by a comma, and each row is separated by a semicolon. Colons (:) can be used to indicate a range of elements.

 

 

Matrices can also be defined by combining Variables, Arrays, Vectors, row Matrices, column Matrices, or m x n Matrices.

 

 

Similar syntax is also available for working with StringArrays. Note that the definition of a virtual StringArray is surrounded by curly brackets, and each element is separated by a comma. Colons (:) can be used to indicate a range of elements.

 

 

 

Accessing Values from Variables, Arrays, and Matrices


The examples below show how to access the values of Variables, Arrays, and Matrices. These objects can be used to generate output for the user, such as using the Report command as shown below, or accessed to perform other calculations. Arrays and Matrices are indexed from zero in FreeFlyer. Colons (:) can be used to indicate a range of elements.

 

 

These objects can be also be reported to a file or ReportInterface, as shown below:

 

Report an Array to a ReportInterface:

 

 

Output Report:

 

       a3[0]

        None

  -3410.673000000

 

     a3[2:5][0]        a3[2:5][1]        a3[2:5][2]        a3[2:5][3]

        None              None              None              None

  -1788.627000000       1.893006000      -1.071993000      -7.176346000

 

     a3[5:2][0]        a3[5:2][1]        a3[5:2][2]        a3[5:2][3]

        None              None              None              None

     -7.176346000      -1.071993000       1.893006000   -1788.627000000

 

     a3[:4][0]         a3[:4][1]         a3[:4][2]         a3[:4][3]         a3[:4][4]

        None              None              None              None              None

  -3410.673000000    5950.957000000   -1788.627000000       1.893006000      -1.071993000

 

     a3[4:][0]         a3[4:][1]         a3[4:][2]         a3[4:][3]         a3[4:][4]         a3[4:][5]         a3[4:][6]         a3[4:][7]

        None              None              None              None              None              None              None              None

     -1.071993000      -7.176346000       1.893006000      -1.071993000      -7.176346000       5.000000000       6.000000000       7.000000000

 

     a3.Format("%1.3e")

        None

      9.823e+01 0.000e+00 1.000e+00 2.000e+00 3.000e+00 4.000e+00 1.893e+00 -1.072e+00 -7.176e+00 5.000e+00 6.000e+00 7.000e+00

 

 

 

 

Report a Matrix to a ReportInterface:

 

 

Output Report:

 

 

      m9[:,0]           m9[:,1]           m9[:,2]           m9[:,3]

        None              None              None              None

      1.000000000       1.000000000       1.000000000       5.000000000

      1.000000000       1.000000000       1.000000000       5.000000000

      1.000000000       1.000000000       1.000000000       5.000000000

      1.000000000       2.000000000       3.000000000       4.000000000

      0.000000000       0.000000000       0.000000000       0.000000000

 

    m9[0,:][:,0]      m9[0,:][:,1]      m9[0,:][:,2]      m9[0,:][:,3]

        None              None              None              None

      1.000000000       1.000000000       1.000000000       5.000000000

 

    m9[:,0][:,0]

        None

      1.000000000

      1.000000000

      1.000000000

      1.000000000

      0.000000000

 

   m9[0,2:0][:,0]    m9[0,2:0][:,1]    m9[0,2:0][:,2]

        None              None              None

      1.000000000       1.000000000       1.000000000

 

   m9.Format("%1.1e")

   None

   1.0e+00 1.0e+00 1.0e+00 5.0e+00

   1.0e+00 1.0e+00 1.0e+00 5.0e+00

   1.0e+00 1.0e+00 1.0e+00 5.0e+00

   1.0e+00 2.0e+00 3.0e+00 4.0e+00

   0.0e+00 0.0e+00 0.0e+00 0.0e+00

 

 

Converting between Arrays, Matrices, Vectors, and CoordinateSystems


Several methods and shorthand notations are provided for converting between Arrays and Matrices. Please see the Literal Operators section of the Script Operators page for more information.

 

To convert an Array to a Matrix, the following methods are available:

 

 

To convert a Matrix to an Array, the following methods are available:

 

 

You can also convert between Vectors and Arrays or Matrices using the syntax:

 

 

Similarly, you can convert a CoordinateSystem to a Matrix using the syntax:

 

 

 

Matrix Decomposition


The Matrix.Solve() method has several decomposition methods available to solve a system of linear equations written 'A * x = b' where A and b are matrices for the vector x. Requirements for individual decomposition methods are provided below.

 

 

 

See Also


Script Operators

Matrix Properties and Methods

Array Properties and Methods

Variable Properties and Methods

StringArray Properties and Methods

Vector Properties and Methods

CoordinateSystem Properties and Methods

Vectors and CoordinateSystems