Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double
- norm(matrix *matr, double *sol){
- double *nev = (double*)calloc(matr->m, sizeof(double));
- long double sum = 0.0;
- for(int i = 0; i < matr->m; i++)
- {
- for(int j = 0; j < matr->m; j++)
- {
- nev[i] += matr[i][j] * sol[j];
- }
- nev[i] -= matr[i][matr->m];
- }
- for(int i = 0; i < matr->m; i++)
- {
- sum += nev[i] * nev[i];
- }
- free(nev);
- return sqrt(sum);
- }
- void
- uprel(matrix *matr, double omega, double eps){
- double *sol = (double*)calloc(matr->m, sizeof(double))
- double sum[2] = {0.0, 0.0};
- do{
- for(int i = 0; i < matr->m; i++){
- sum[0] = 0.0;
- sum[1] = 0.0;
- for(int j = 0; j <= i-1; j++){
- sum[0] += matr->mas[ matr->str[i] ][ matr->col[j] ] * sol[j];
- }
- for(int j = i; j < matr->m; j++){
- sum[1] += matr->mas[ matr->str[i] ][ matr->col[j] ] * sol[j];
- }
- sol[i] += (omega/matr->mas[ matr->str[i] ][ matr->col[i] ]) * (matr[ matr->str[i] ][ matr->col[matr->m] ] - sum[0] - sum[1]);
- }
- }
- while(norm(matr, sol) > eps);
- for (int i = 0; i < matr->m; i++){
- printf("%lf ", sol[i]);
- }
- printf ("\n");
- free(sol);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement