49 int rows,
int maxit,
double sor,
double error)
51 int i, j, k, center, finished = 0;
59 for (k = 0; k < maxit; k++) {
63 for (j = 0; j < rows; j++) {
67 for (i = 0; i < rows; i++) {
70 for (j = 0; j < Asp[i]->
cols; j++) {
72 if (Asp[i]->index[j] == i)
75 Enew[i] = x[i] - sor * (E - b[i]) / Asp[i]->values[center];
77 for (j = 0; j < rows; j++) {
78 err += (x[j] - Enew[j]) * (x[j] - Enew[j]);
84 G_message(
_(
"sparse Jacobi -- iteration %5i error %g\n"), k, err);
119 int rows,
int maxit,
double sor,
double error)
121 int i, j, k, finished = 0;
131 for (k = 0; k < maxit; k++) {
135 for (j = 0; j < rows; j++) {
139 for (i = 0; i < rows; i++) {
142 for (j = 0; j < Asp[i]->
cols; j++) {
144 if (Asp[i]->index[j] == i)
147 Enew[i] = x[i] - sor * (E - b[i]) / Asp[i]->values[center];
149 for (j = 0; j < rows; j++) {
150 err += (x[j] - Enew[j]) * (x[j] - Enew[j]);
156 G_message(
_(
"sparse SOR -- iteration %5i error %g\n"), k, err);
191 int maxit,
double sor,
double error)
201 for (j = 0; j < rows; j++) {
205 for (k = 0; k < maxit; k++) {
206 for (i = 0; i < rows; i++) {
208 for (j = 0; j < rows; j++) {
211 Enew[i] = x[i] - sor * (E - b[i]) / A[i][i];
214 for (j = 0; j < rows; j++) {
215 err += (x[j] - Enew[j]) * (x[j] - Enew[j]);
218 G_message(
_(
"Jacobi -- iteration %5i error %g\n"), k, err);
248 double sor,
double error)
258 for (j = 0; j < rows; j++) {
262 for (k = 0; k < maxit; k++) {
263 for (i = 0; i < rows; i++) {
265 for (j = 0; j < rows; j++) {
266 E += A[i][j] * Enew[j];
268 Enew[i] = x[i] - sor * (E - b[i]) / A[i][i];
271 for (j = 0; j < rows; j++) {
272 err += (x[j] - Enew[j]) * (x[j] - Enew[j]);
275 G_message(
_(
"SOR -- iteration %5i error %g\n"), k, err);
The row vector of the sparse matrix.
void G_free(void *)
Free allocated memory.
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)
void G_message(const char *,...) __attribute__((format(printf
int G_math_solver_sparse_jacobi(G_math_spvector **Asp, double *x, double *b, int rows, int maxit, double sor, double error)
The iterative jacobi solver for sparse matrices.
double * G_alloc_vector(size_t)
Vector matrix memory allocation.
int G_math_solver_jacobi(double **A, double *x, double *b, int rows, int maxit, double sor, double error)
The iterative jacobi solver for quadratic matrices.
int G_math_solver_sparse_gs(G_math_spvector **Asp, double *x, double *b, int rows, int maxit, double sor, double error)
The iterative gauss seidel solver for sparse matrices.
int G_math_solver_gs(double **A, double *x, double *b, int rows, int maxit, double sor, double error)
The iterative gauss seidel solver for quadratic matrices.