public MatrixValue Function(MatrixValue x, MatrixValue y, MatrixValue f) { if (x.Length != y.Length) { throw new YAMPDifferentLengthsException(x.Length, y.Length); } if (x.Length != f.DimensionY) { throw new YAMPDifferentLengthsException(x.Length, f.DimensionY); } var m = f.DimensionX; if (m < 2) { throw new YAMPArgumentInvalidException("Linfit", "f", 3); } var M = f; var b = new MatrixValue(x.Length, 1); for (var j = 1; j <= M.Rows; j++) { b[j, 1] = y[j]; } var qr = QRDecomposition.Create(M); return(qr.Solve(b)); }
public static Object Qr(Double[,] matrix) { var qr = QRDecomposition.Create(matrix); return(ObjectHelpers.CreateObject( "q", qr.Q, "r", qr.R, "full", qr.HasFullRank )); }
public static Double[,] Inverse(Double[,] matrix) { var rows = matrix.GetLength(0); var cols = matrix.GetLength(1); var target = Helpers.One(cols); if (cols < 24) { var lu = new LUDecomposition(matrix); return(lu.Solve(target)); } else if (Helpers.IsSymmetric(matrix)) { var cho = new CholeskyDecomposition(matrix); return(cho.Solve(target)); } else { var qr = QRDecomposition.Create(matrix); return(qr.Solve(target)); } }
public MatrixValue Function(MatrixValue x, MatrixValue y, ScalarValue n) { if (x.Length != y.Length) { throw new YAMPDifferentLengthsException(x.Length, y.Length); } var nn = n.GetIntegerOrThrowException("n", Name); var m = nn + 1; if (m < 2) { throw new YAMPArgumentRangeException("n", 0.0); } var M = new MatrixValue(x.Length, m); var b = new MatrixValue(x.Length, 1); for (var j = 1; j <= M.Rows; j++) { var el = ScalarValue.One; var z = x[j]; for (var i = 1; i <= M.Columns; i++) { M[j, i] = el; el *= z; } b[j, 1] = y[j]; } var qr = QRDecomposition.Create(M); return(qr.Solve(b)); }
public ArgumentsValue Function(MatrixValue M) { var qr = QRDecomposition.Create(M); return(new ArgumentsValue(qr.Q, qr.R)); }