Linear algebra

  Linear algebra basic calculation
  'MATRIX' command was added as unofficial command.
  How to view the Manual from the App. (Full version)
  Type the [M] key and touch the right side of blue
  [MATRIX] letter that appears in the upper right corner.
  It can view by pop-up help.
  This function is unguarantee during unofficial command.

  MATRIX


 [Features] To execute various calculations of Linear algebra.

 [Format] MATRIX "Array1= eigen(Array2)"

 [Explanation]
    Description method:
    matrix "VariableName = Linear algebra Formula"
    Right side is the various function names exclusive for 'MATRIX'
     and Array-variable name of the data source in parentheses.
    The format in the case of Four-arithmetic-operations calculation,
    "Array-variable1 Formula Array-variable2"
    The variable name is Numeric array variable without a parenthesis.
    The case of which left side is numerical value variable not Array:
    ->Determinant and rank.
    The array variables to be used must be declared at the beginning of the program in advance.
    If the size of array for substitute is different than requested one, automatically resized.
    (When different scope in [Array variable] and ['MATRIX' command execution],
     since resizing is impossible, it become an error)
    *About Complex numbers of input and output values, these are not supported at this stage.
    *About processing of eigenvectors in cases where eigenvalues are duplicate solutions,
     there is room for improvement.

    Matrix data are given by Array variable.
    (Think of array variables as matrix)
    If the columns count is [x] and the rows count is [y], it declare as [ dim dv1(y,x) ].
    If declaring [ dim dv1(2) ] in 'Basic' Array variable,
     3 variables of [0-2] will be declared.
    This is one larger size than the desired size,
    option base -1  (Please see the manual [OPTION BASE] for details)
    By writing this command, to make it to allocate 2 data from [0-1].
    This allocate become the same number as general language, C or Java.
    When dealing with linear algebra,
     be sure to write [option base -1] at the beginning of the program.
    When not writting, correct calculation result isn't obtained.

    About errors in linear algebra.
    If uncalculable error occurs in Linear algebra calculation,
     the program is not interrupted, it only return error code to 'ERR' function.
    Please check the success or failure of calculation in the state of 'ERR' function.
    'ERR' function is reset to 0 at the beginning of 'MATRIX' command execution.
    Linear algebra related errors.
     error 69:"Matrix error, uncalculable or cofactor 0"
     error 70:"Array size of matrix does not fit"

    Four arithmetic operations of Linear algebra.
    e.g
     10 option base-1
     20 dimdv1(2,2),dv2(2,2),dv3(2,2)
     30 dv2(0,0)=4:dv2(0,1)=-2:dv2(1,0)=1:dv2(1,1)=1
     40 dv3(0,0)=1:dv3(0,1)=2:dv3(1,0)=3:dv3(1,1)=4
     50 matrix "dv1=dv2+dv3"
     60 for y=0 to 1 : for x=0 to 1
     70 print dv1(y,x);
     80 next : print : next

    As something defined already up to 40 line, to explained using an example
     in which only [line50 'MATRIX' parameter] is changed.
    ('matrix' next line is result)
    Addition, Subtraction: It must be the same size in two calculation arrays.
    Multiply: It must be the same size in [left array column count] and [right array row count]
    Division: The two arrays must be square matricx of the same size.

    [Addition]
     matrix "dv1=dv2+dv3"
     5 0
     4 5

    [Subtraction]
     matrix "dv1=dv2-dv3"
     3 -4
     -2 -3

    [Multiply]
     matrix "dv1=dv2*dv3"
     -2 0
     4 6

    [Division]
     matrix "dv1=dv2/dv3"
     -7 5
     5.5 -3.5
    There is no division in linear algebra,
     it return the value obtained by multiplying by
     [Inverse matrix of division-matrix-dv3] from left side of dv2.

    --Internal function of 'MATRIX' command exclusive use--

    e.g. forEigenvalue
     10 optionbase-1
     20 dimdv1(2,2),dv2(2,2)
     30 dv2(0,0)=4:dv2(0,1)=-2:dv2(1,0)=1:dv2(1,1)=1
     40 matrix "dv1=eigen(dv2)"
     50 for y=0 to 1 : for x=0 to 1
     60 print dv1(y,x);
     70 next : print : next

    As something defined already up to 30 line, to explained using an example
     in which only [line40 'MATRIX' parameter] is changed.
    ('matrix' next line is result)

    [ DET ]
    To calculate Determinant from given Matrix.
     matrix "var=det(dv2)"
     6
    The left side specifies the usual numeric variable, not an array.
    The array(dv2) that give the data must be a square matrix.

    [ INV ]
    To calculate Inverse from given Matrix.
    matrix "dv1=inv(dv2)"
    0.1666 0.333
    -0.1666 0.666

    The array(dv1) to substitute must be a square matrix
     of the same size as the array(dv2) giving data.
    If Determinant of the given matrix is 0, Inverse matrix doesn't exist,
     so it become ['ERR' function=69] and it isn't calculated.
    (Program dosn't interruption)
    Others that use the inverse matrix during the calculation
    (Division, Simultaneous equations),
     if the Determinant becomes 0, to become ['ERR' function=69].

    [ EQUAT ]
    To find the solution of simultaneous equations with a matrix.
    e.g.  for Simultaneous equations.
    x+2y=4
    3x+5y=9
    Data to prepare(2x3)
    1 2 4
    3 5 9
    Program to find the solution of simultaneous equations of matrix with 'EQUAT' function.
     10 option base -1
     20 dim dv1(2,1),dv2(2,3)
     30 dv2(0,0)=1:dv2(0,1)=2:dv2(0,2)=4
     40 dv2(1,0)=3:dv2(1,1)=5:dv2(1,2)=9
     50 matrix "dv1=equat(dv2)"
     60 for y=0 to 1
     70 print dv1(y,0);
     80 next
    Output solution
    -2
    3<BR>    (x=-2,y=3)

    When the right side of the expression is all 0.
    x-3y=0
    2x-6y=0
    Data in an array.
    1 -3 0
    2 -6 0
    The mutual ratio between each character expression.
    9
    3

    If the right side is all 0,
     the solution become impossible or indetermination,
     it cann't find a solution.
    But if it is indetermination, it's possible to calculate
     [The mutual ratio between each character expression].
    So in this case, the ratio is returned.(by integer)
    In this example,
     to verify with [substitute 9 for x],[substitute 3 for y]
    It becomes 0, same as the right side,
     it turns out that the result is right.
    In the case of this ratio, if the calculation is impossible,
     it become ['ERR' function=69], and the calculation is not performed.

    About the size of the array used.
    The array(dv2) that give the equation data,
     it prepare columns count 1 larger than a square matrix.
    The rightmost column will enter the numbers on right side of the equation.
    It set size [columns count=1, rows count=same as array that give the data]
     that the array be substitutioned the solution.
    It become that the solutions is lined up in a column vertical.

    [ EIGEN ]
    To calculate Eigenvalue from given Matrix.
    matrix "dv1=eigen(dv2)"
    3 0
    0 2
    The eigenvalues are arranged diagonally in the array as in the example, and returned.
    Because it doesn't supported to a complex number,
    If the eigenvalue is complex number, unregular value is returned.
    The array(dv1) to substitute must be a square matrix
     of the same size as the array(dv2) giving data.

    [ EVEC ]
    To calculate Eigenvector from given Matrix.
    matrix "dv1=evec(dv2)"
    2 1
    1 1
    The format of the returned array is this:
     The Eigenvector of the 0th Eigenvalue is in 0th column,
     The Eigenvector of the 1th Eigenvalue is in 1th column...
    The array(dv1) to substitute must be a square matrix
     of the same size as the array(dv2) giving data.

    [ TRANS ]
    To return Transpose matrix from given Matrix.
    matrix "dv1=trans(dv2)"
    4 1
    -2 1
    The array(dv1) to substitute must be a square matrix
     of the same size as the array(dv2) giving data.

    [ RANK ]
    To return Rank from given Matrix.
    matrix "var=rank(dv2)"
    2
    The left side specifies the usual numeric variable, not an array.

    [ UNIT ]
    To return Unit matrix of specified number.
    matrix "dv1=unit(2)"
    1 0
    0 1
    To specify the square size in a number of the function.

    [ INTCV ]
    The data in array is integer-ized.
    Format: intcv(ArrayName,ProcessingLine,MaxInspectionValue,DetermineDigits)
    e.g.: matrix "dv1=intcv(dv2,-1,100,0.00001)"
    It examine whether [Each value in the given array] will be [Shaped integer ratio],
    If possible, Each value is converted to data in the ratio of integer, and returned.
    If it can't change to integer, to return the array of original values as is.
    ('ERR' function=69, None interruption)
    The range to be integerized can be specified either [Whole of array] or [Specified row].
    To use it in this case. For example,
    Matrix question made by a person that have an integer in the solution.
    It try to make this be integer-ized.

   Left side:
     Array(dv1) to substitute the result.
    -Parameter in the function-
   ArrayName:
     Array(dv2) which try to be integer-ized.
   ProcessingLine:  (Specify from 0-)
     To specify which row to be integer-ized.
     If -1 is specified, everything in the array is targeted.
   MaxInspectionValue:
    It is investigated to which integral number
     actually corresponds to minimum value that be standard integer.
    To set the upper limit value of the survey.
    If the survey reaches the upper limit and there is no prospect of integer-ized,
     it is judged that integer-izing is impossible.
    ('ERR' function=69, None interruption)
    The larger this value, the more likely it is to be integer-ization,
     but the processing load will be large.
   DetermineDigits:
    The larger digit numbers of a decimal(small number),
     the stricter judge criteria of integer-ized.
    The smaller digit numbers(big number) then roughly.
    If the value is not well known, please use the value of
     [ intcv(ArrayName,-1,100,0.00001) ] like the example.
    The array(dv1) to substitute must be a square matrix
     of the same size as the array(dv2) giving data.

    [ SETTING ]
    This is function which do setting, not calculation.
    matrix "var=setting(ret,0)"
    Various setting of Linear algebraic.
    To write the type of setting in the first parameter of function.
    (This word don't need to be enclosed in double quotation)
    The kind of setting-word is [ret] only one at present.
    -First parameter-
    ret:
     To set whether the return value of Eigenvector is returned as a decimal or an integer.
    -Second parameter-
    0: Return value as a normalized decimal.(default)
    1: Return value as an integer.
     The left side is a temporary variable without meaning.
     Please specify a normal numeric variable, not an array.


 ---------------------------
 How to use the sample "linear.bas"
 ---------------------------

  When executed, the command selection screen appears.
  Enter the number.
 
  1.input 2.save 3.load 4.calc
 
  First, enter the data with '1.input'
  To enter the size of the row and column of the matrix.
 
  size x? (Enter columns count)
  size y? (Enter rows count)
  Let's enter the size of '2x2' as an example.
  (When equation data, to make the columns count increase by 1)

  Next enter the data.
  4 -2
  1 1
  Let's enter this matrix data.
  The columns number are counted from the right side.
  0,0 ? 4
  0,1 ? -2
  1,0 ? 1
  1,1 ? 1
 
  Let's saves the input data. (to memo the size of the matrix.)
  Please select [ 2.save ]
  Enter the save number. To try saving to number 1.
  No.1
  It was saved by pressing [Enter].
 
  Let's actually see the calculation result.
  Please select [ 4.calc ]
  Matrix data
  (Rank)
  (det)
  (mult:squared)
  displayed in this order.
  To tap the key to display more data.
  (inv)
  (Eigen)
  (Evec)
  This data will be displayed.
 
  Finally, the loading procedure is explained.
  Please select [ 3.load ]
  To enter the load number. Then try to load [No.1] earlier.
  No.1
  It's necessary to input the matrix size.
  Enter the size you noted earlier.
  size x? 2 (Enter columns count)
  size y? 2 (Enter rows count)
  It is now loaded.
 
  It's possible to make calculation result indicate variously
   by choosing [4.calc] by the procedure earlier.