示例#1
0
    static void probA2()
    {
        Write("\nProblem A2:\n");
        // Need to make the tests for A2
        var rand = new System.Random();

        // Remember, square matrix:
        Write("\nMake a random square matrix, A, with random dimmensions, and a random vector, b, of the same dimmension:\n");
        int    n = 2 + rand.Next(10);
        matrix A = makeRandomMatrix(n, n);
        vector b = makeRandomVector(n);

        A.print("A = ");
        b.print("b = ");

        qr_gs decomposer = new qr_gs(A);

        Write("\nSolve the system A*x = b for the vector x:\n");
        //decomposer.Q.print("Decomposition Q: ");
        //decomposer.R.print("Decomposition R: ");
        //(decomposer.Q.transpose()*b).print("Q^(T)*b = ");
        vector x = decomposer.solve(b);

        x.print("Solution: x = ");
        Write("\nCheck that the vector x satisfies A*x=b:\n");
        (A * x - b).print("A*x-b = ");
    }
示例#2
0
    public static vector calculateC(data dat, Func <double, double>[] fs)
    {
        matrix A      = calculateA(dat, fs);
        vector b      = calculateb(dat);
        qr_gs  solver = new qr_gs(A);
        vector c      = solver.solve(b);

        return(c);
    }