You are here: Symbol Reference > MtxParseExpr Namespace > Classes > TMtxExpression Class > public > DefineMatrix Method > TMtxExpression.DefineMatrix Method (string, TMtx)
MtxVec VCL
ContentsIndex
PreviousUpNext
TMtxExpression.DefineMatrix Method (string, TMtx)

DefineMatrix defines new matrix variable.

Pascal
function DefineMatrix(const AVarName: string; const mtx: TMtx): TMatrixValue; overload;

If variable with name AVarName already was definded, it will be redefined and all expressions which contain the symbol AVarName will be recompiled before the next evaluation. External matrix may be assigned as values holder. If external matrix is not assigned, internal matrix will be used.

Use parser to evaluate the "A+2*B" formula where A=(2,1; 3, 0) B=(1,0; 1,1) are 2x2 matrices.

uses MtxParseExpr, MtxExpr, MtxParseClass; procedure Example(MyParser: TMtxExpression); var A,B: TMatrixValue; res: Matrix; begin // 1. Define variables A := MyParser.DefineMatrix('A'); B := MyParser.DefineDouble('B'); // 2. Set values A.Value.SetIt(2,2, false, [2,1,3,0]); B.Value.SetIt(2,2, false, [1,0,1,1]); // 3. Add formula and evaluate, MyParser.AddExpr('A+2*B'); res := MyParser.EvaluateMatrix; // res = (4,1; 5,2) end;
Examples on GitHub
Copyright (c) 1999-2025 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!