Suppose you initialize a square sparse matrix Q of size 8x8.
initialize a vector of known terms, also spread in this way:
b = sparse ([1] [1] [1], 8.1)The system represented by Q and b can be solved by traditional method (Gauss elimination) with the following command:
x = Q \\ band this command applies to the sparse matrix for full ones.
If the array is larger (much larger) may be required less traditional methods, potentially less accurate, but often the only effective. The system pruò be solved by iterative methods, the following command solves the system using the Preconditioned Conjugate Gradient iterative method:
x = pcg (Q, b)For systems particularly difficult to solve so-called preconditioners can be used:
[L, U, P, R] = luinc (Q, 1.e-3)
x = pcg (Q, b, 1.e-6, 500, L * U)
example:
1.e-6, is the error threshold below which the solution is considered acceptable
500, represents the maximum number of iterations allowed
0 comments:
Post a Comment