Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstdlib>
- using namespace std;
- int n = 3;
- int m = 3;
- double e = 0.001;
- int main()
- {
- int k = 0;
- double A[50][50];
- double B[50];
- double P2[50];
- double P[50][50];
- A[0][0]=2; A[0][1]=3; A[0][2]=8;
- A[1][0]=5; A[1][1]=4; A[1][2]=9;
- A[2][0]=2; A[2][1]=1; A[2][2]=3;
- for(int i = 0; i < n; i++)
- {
- for(int j = 0; j < m; j++)
- {
- cout << A[i][j]<<" ";
- }
- cout<<endl;
- }
- B[0]=5; B[1]=4; B[2]=5;
- P2[0]=0; P2[1]=0; P2[2]=0;
- double A1[n][m];
- for(int i = 0; i < n; i++)
- {
- for(int j = 0; j < m; j++)
- {
- if(i==j) A1[i][j] = B[i] / A[i][j];
- else A1[i][j] = A[i][j] / A[i][i]*(-1);
- }
- P[k][i]=P2[i];
- }
- cout<< endl;
- for(int i = 0; i < n; i++)
- {
- for(int j = 0; j < m; j++)
- {
- cout << A1[i][j]<<" ";
- }
- cout<<endl;
- }
- cout << endl;
- double sum;
- do
- {
- k++;
- sum=0;
- cout << "N=" << k << endl;
- for(int i = 0; i < n; i++)
- {
- double s=0;
- for(int j = 0; j < m; j++)
- {
- if (i==j) {
- s+=A1[i][j];
- cout << "+"<<A1[i][j];
- }
- else {
- s+=A1[i][j]*P2[j];
- cout <<A1[i][j]<<"*"<<P[k-1][j];
- }
- P2[i]=s;
- }
- P[k][i]=P2[i];
- cout<<"="<<P[k][i]<<" "<<endl;
- }
- cout <<endl;
- for (int i = 0; i < n; i++)
- {
- sum += (P[k][i] - P[k-1][i]) * (P[k][i] - P[k-1][i]);
- }
- }while(sqrt(sum)>= e);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement