public override ILinAlgMat _Inv(ILinAlgMat A) { using (new Matlab.NamedLock("LA")) { Matlab.PutMatrix("LA.A", A.ToArray()); CMatrix inv = Matlab.GetMatrix("inv(LA.A)"); Matlab.Clear(); return(inv); } }
public override ILinAlgMat _Diag(ILinAlgMat mat) { using (new Matlab.NamedLock("LA")) { Matlab.PutMatrix("LA.A", mat.ToArray()); CMatrix diag = Matlab.GetMatrix("diag(LA.A)"); Matlab.Clear(); return(diag); } }
public override double _Det(ILinAlgMat mat) { using (new Matlab.NamedLock("LA")) { Matlab.PutMatrix("LA.A", mat.ToArray()); double det = Matlab.GetValue("det(LA.A)"); Matlab.Clear(); return(det); } }
public override ILinAlgMat _LinSolve(ILinAlgMat A, ILinAlgMat B) { using (new Matlab.NamedLock("LA")) { Matlab.PutMatrix("LA.A", A.ToArray()); Matlab.PutMatrix("LA.B", B.ToArray()); CMatrix X = Matlab.GetMatrix(@"LA.A \ LA.B"); /// A X = B => X = A\B Matlab.Clear(); return(X); } }
public override Tuple <ILinAlgMat, double[]> _EigSymm(ILinAlgMat A) { using (new Matlab.NamedLock("LA")) { Matlab.PutMatrix("LA.A", A.ToArray()); Matlab.Execute("LA.A = (LA.A + LA.A)/2;"); Matlab.Execute("[LA.V, LA.D] = eig(LA.A);"); Matlab.Execute("LA.D = diag(LA.D);"); CMatrix V = Matlab.GetMatrix("LA.V"); double[] D = Matlab.GetVector("LA.D"); if (HDebug.IsDebuggerAttached) { Matlab.Execute("LA.ERR = LA.A - (LA.V * diag(LA.D) * LA.V');"); Matlab.Execute("LA.ERR = max(max(abs(LA.ERR)));"); double err = Matlab.GetValue("LA.ERR"); HDebug.AssertTolerance(0.00000001, err); } Matlab.Clear(); return(new Tuple <ILinAlgMat, double[]>(V, D)); } }