Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <iomanip>
- #include <cstdlib>
- using namespace std;
- //const int n=5;
- int main()
- {
- int n;
- //double A,B,C,D;
- cout << " Metoda Thomasa\n";
- cout << " Wprowadz stopien macierzy: ";
- cin >> n;
- double A[n],B[n],C[n],D[n];
- /*A = new double [n];
- B = new double [n];
- C = new double [n];
- D = new double [n];*/
- srand(time(0));
- for(int j = 0; j < n; j ++)
- {
- A[j]=(rand()%20) + 1;
- B[j]=(rand()%20) + 1;
- C[j]=(rand()%20) + 1;
- D[j]=(rand()%20) + 1;
- }
- cout << "\nWypelniona macierz A: ";
- for(int j = 0; j < n; j ++)
- {
- cout << A[j] << " ";
- }
- cout << endl;
- cout << "\nWypelniona macierz B: ";
- for(int j = 0; j < n; j ++)
- {
- cout << B[j] << " ";
- }
- cout << endl;
- cout << "\nWypelniona macierz C: ";
- for(int j = 0; j < n; j ++)
- {
- cout << C[j] << " ";
- }
- cout << endl;
- cout << "\nWypelniona macierz D: ";
- for(int j = 0; j < n; j ++)
- {
- cout << D[j] << " ";
- }
- cout << endl;
- /*
- for(int i = 0; i < n; i++)
- {
- A[i] = new double[n];
- B[i] = new double[n];
- C[i] = new double[n];
- D[i] = new double[n];
- }
- */
- /*double A[n]={0,2,1,1,1};
- double B[n]={1,2,2,2,1};
- double C[n]={3,2,1,6,0};
- double D[n]={1,5,5,2,2};*/
- double X[n];
- double beta[n];
- double gamma[n];
- beta[0]=-(C[0]/B[0]);
- gamma[0]=(D[0]/B[0]);
- for(int i=0;i<n;i++)
- {
- beta[i]=-(C[i]/(A[i]*beta[i-1]+B[i]));
- gamma[i]=(D[i]-A[i]*gamma[i-1])/(A[i]*beta[i-1]+B[i]);
- }
- for(int i=0;i<n;i++)
- {
- cout<<"\nWspolczynnik Beta " <<i+1<< " = "<< beta[i]<<endl;
- cout<<"Wspolczynnik Gamma " <<i+1<< " = " << gamma[i]<<endl;
- }
- X[n]=gamma[n];
- for(int i=(n-1);i>=0;i--)
- {
- X[i]=(beta[i]*X[i+1]+gamma[i]);
- }
- for(int i=0;i<n;i++)
- {
- cout<<"\n X" << i+1 << " = "<< X[i]<<"\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement