Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "cmath"
- #include "iostream"
- #include "locale.h"
- using namespace std;
- void Input(int n,int A[][100])
- {
- int i,j;
- for (i=0;i<n;i++)
- for (j=0;j<n;j++){
- cout << "Введите A[" << i << "][" << j << "]: ";
- cin >> A[i][j];
- }
- }
- void Matrix(int A[][100],int n, int itc)
- {
- float w0[100],w[100],summ=0,w0norm[100],e,d,d0;
- int i,j;
- w0[0]=1;
- for (i=1;i<n;i++)
- w0[i]=0;
- do
- {
- //нормируем вектор
- for (i=0;i<n;i++)
- summ=summ+w0[i]*w0[i];
- d0=sqrt(summ);
- for (i=0;i<n;i++)
- w0norm[i]=w0[i]/d0;
- //умножаем матрицу A на нормированный вектор
- for (i=0;i<n;i++)
- {
- w[i]=0;
- for (j=0;j<n;j++)
- w[i]=w[i]+A[i][j]*w0norm[j];
- }
- //
- summ=0;
- for (i=0;i<n;i++)
- summ=summ+w[i]*w[i];
- d=sqrt(summ);
- //выведем первые itc итераций
- if(itc>0)
- {
- cout << d << endl;
- itc--;
- }
- //
- e=fabs(d-d0);
- for (i=0;i<n;i++)
- w0[i]=w[i];
- summ=0;
- } while(e>0.001);
- cout << "\nL = " << d << endl;
- }
- int main()
- {
- int n,A[100][100],itc;
- setlocale(LC_ALL, "rus");
- cout << "Размерность матрицы = ";
- cin >> n;
- Input(n,A);
- cout << "\nМатрица А:\n";
- for (int i=0;i<n;i++)
- {
- for (int j=0;j<n;j++)
- cout << A[i][j] << " ";
- cout << endl;
- }
- cout << endl;
- cout << "Сколько итераций вывести? ";
- cin >> itc;
- Matrix(A,n, itc);
- cin.get();
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement