Advertisement
karlicoss

oche slozhny linal

Jul 1st, 2012
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. /* Author: Gerasimov Dmitry, 1538
  7.  * Modul' 3. Zadanie III
  8.  *
  9.  * Punkt 1.  Schitaem tenzor v novom bazise.
  10.  * formula:
  11.  * A'[a][b][c][d] = sum_i sum_j sum_k sum_l T[a][i] * T[b][j] * T[c][k] * T[d][l] * A[i][j][k][l]
  12.  * a, b - indexi sverxy, c, d - snizu
  13.  *
  14.  * A: matrica tenzora
  15.  *     _____l=0____________l=1____
  16.  *     ||              |        ||
  17.  *     ||A[i][j][0][0] |        ||
  18.  * k=0 ||              |        ||
  19.  *     ||              |        ||
  20.  *     ||-----------------------||
  21.  *     ||              |        ||
  22.  *     ||A[i][j][1][0] |        ||
  23.  * k=1 ||              |        ||
  24.  *     ||_____________ |________||
  25.  *
  26.  * k, l - vneshnie indexy
  27.  * i, j - vnutrennie indexy (i - stroki, j - stolbci)
  28.  *
  29.  * T: matrica perexoda v noviy basis
  30.  * zadaetsya kak obichno, i - stroki, j - stolbci
  31.  *
  32.  * --------------
  33.  * Punkt 2. Schitaem svertku tenzora
  34.  * formula:
  35.  * Summiruem po povtoruaushimsya indexam, iz nepovtoryaushixsya obrazuem matricy-svertku.
  36.  *
  37.  * primer 1:
  38.  * Schitaem svertku A[i][j][i][k]
  39.  * Sv[j][k] = A[0][j][0][k] + A[1][j][1][k]
  40.  *
  41.  * primer 2:
  42.  * Schotaem svertku A[i][i][j][j]
  43.  * Sv = A[0][0][0][0] + A[0][0][1][1] + A[1][1][0][0] + A[1][1][1][1]
  44.  * ----------------
  45.  *
  46.  * Esli Cap nichego ne izmenit, to nuzhno tolko izmenit' matricy v inite. Variamt 6 uzhe vbit
  47.  * Powered by Vim, Rammstein and green tea.
  48.  * Have fun :)
  49.  * */
  50.  
  51. int A[2][2][2][2];
  52. int T[2][2];
  53.  
  54. void init()
  55. {
  56.         A[0][0][0][0] = -1;
  57.         A[0][1][0][0] = 0;
  58.         A[1][0][0][0] = 0;
  59.         A[1][1][0][0] = 4;
  60.  
  61.         A[0][0][0][1] = 2;
  62.         A[0][1][0][1] = -4;
  63.         A[1][0][0][1] = 0;
  64.         A[1][1][0][1] = 9;
  65.  
  66.         A[0][0][1][0] = 2;
  67.         A[0][1][1][0] = 2;
  68.         A[1][0][1][0] = -4;
  69.         A[1][1][1][0] = 0;
  70.  
  71.         A[0][0][1][1] = -8;
  72.         A[0][1][1][1] = 1;
  73.         A[1][0][1][1] = 3;
  74.         A[1][1][1][1] = -3;
  75.  
  76.         T[0][0] = 2;
  77.         T[0][1] = 1;
  78.         T[1][0] = 1;
  79.         T[1][1] = 2;
  80. }
  81.  
  82. void part1(int a, int b,
  83.            int c, int d) //pereveod v noviu basis
  84. {
  85.         cout << "Schitaem element A'[" << a << "][" << b << "][" << c << "][" << d << "] v novom bazise" << endl;
  86.         int ans = 0;
  87.         for (int i = 0; i < 2; i++)
  88.                 for (int j = 0; j < 2; j++)
  89.                         for (int k = 0; k < 2; k++)
  90.                                 for (int l = 0; l < 2; l++)
  91.                                 {
  92.                                         int add = T[a][i] * T[b][j] * T[c][k] * T[d][l] * A[i][j][k][l];  
  93.                                         ans += add;
  94.                                         cout << T[a][i] << " * " << T[b][j] << " * " << T[c][k] << " * " << T[d][l] << " * " << A[i][j][k][l] << "  ( " << add << " )" <<  endl;
  95.                                         cout << "+" << endl;
  96.                                 }
  97.         cout << " = " << ans << endl;
  98.         cout << endl;
  99. }
  100.  
  101.  
  102. void part2() //svertka
  103. {
  104.         cout << "Svertka 1: a^ij_ki" << endl;
  105.         for (int j = 0; j < 2; j++)
  106.                 for (int k = 0; k < 2; k++)
  107.                 {
  108.                         cout << "j = " << j << " ; k = " << k << " value = ";
  109.                         for (int i = 0; i < 2; i++)
  110.                                 cout << A[i][j][k][i] << " + ";
  111.                         cout << endl;
  112.                 }
  113.         cout << endl;
  114.  
  115.         cout << "Svertka 2: a^ij_kj" << endl;
  116.         for (int i = 0; i < 2; i++)
  117.                 for (int k = 0; k < 2; k++)
  118.                 {
  119.                         cout << "i = " << i << " ; k = " << k << " value = ";
  120.                         for (int j = 0; j < 2; j++)
  121.                                 cout << A[i][j][k][j] << " + ";
  122.                         cout << endl;
  123.                 }
  124.         cout << endl;
  125.  
  126.         cout << "Svertka 3: a^ij_ij" << endl;
  127.         cout << " value = ";
  128.         for (int i = 0; i < 2; i++)
  129.                 for (int j = 0; j < 2; j++)
  130.                         cout << A[i][j][i][j] << " + ";
  131.         cout << endl;
  132.         cout << endl;
  133.  
  134.         cout << "Svertka 4: a^ij_ji" << endl;
  135.         cout << " value = ";
  136.         for (int i = 0; i < 2; i++)
  137.                 for (int j = 0; j < 2; j++)
  138.                         cout << A[i][j][j][i] << " + ";
  139.         cout << endl;
  140.         cout << endl;
  141. }
  142.  
  143. int main()
  144. {
  145.         init();
  146.         part1(1, 0,
  147.                   0, 1);
  148.         part1(1 , 1,
  149.                   0 , 0);
  150.         part2();
  151.         return 0;
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement