#include "DewMathLib.h" // DewMathInitialize, DewMathFinalize
#include "MtxExpr.h" // Vector, Matrix
#include "Units.MtxExpr.h" // Mul, Divide, Ramp, RandGauss, ...
#include "Units.Math387.h" // TCplx, StrToCplx, Cplx, ...
#include <cstdio>
using namespace Dew;
using namespace Dew::Math;
using namespace Dew::Math::Units::MtxExpr;
using namespace Dew::Math::Units::Math387;
void QuickStart()
{
Matrix am, bm;
Vector av;
TCplx ac;
DewArray<TCplx> arr;
ac = StrToCplx("1+2i"); //Convert from string to complex number
am = RandGauss(5, 5, TMtxFloatPrecision::mvDoubleComplex); //5x5 complex matrix with Gaussian noise
av = Ramp(25, TMtxFloatPrecision::mvDouble); //real vector = [0, 1, 2,...., 23, 24]
bm = am*av + ac + 2; // (*,/) treat Matrices as vectors
// Same as: ./ and .* operators (not linear algebra)
//To make linear algebra multiplication and divison use functions
bm = Divide(am, bm) + 2; //matrix divison
bm = Mul(am, bm) + 2; //matrix multiply
//of course you can mix matrices and vectors
av.Resize(5);
av.ExtendToComplex(); //bm is complex: the vector must be complex too
av = Mul(av, bm) + 2; //vector from left and matrix multiply
av.CopyToArray(arr); //copy data to array of complex numbers
av.CopyFromArray(arr); //copy data from array to vector
for (int i = 0; i < am.GetRows(); i++) //standard loop example
{
av.CValues(i) = am.CValues(i, 0)*av.CValues(i);
}
}
int main()
{
DewMathInitialize(); //once, before the first MtxVec object is used
try
{
QuickStart();
}
catch (const EMtxVecException& e)
{
std::printf("MtxVec error: %s\n", e.Message.c_str());
return 1;
}
DewMathFinalize();
return 0;
}