Advertisement
Guest User

Lab2

a guest
May 27th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "linalg.h"
  2. #include "solvers.h"
  3. #include <iostream>
  4.  
  5. using namespace alglib;
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     {
  11.         float lambda = 100;
  12.         float S = 10;
  13.         float length = 1000;
  14.         float q = 5;
  15.         int alpha = 6;
  16.         float tsredi = 273;
  17.         float size = length / alpha;
  18.  
  19.         ae_int_t m = alpha;
  20.         ae_int_t n = alpha;
  21.  
  22.         real_2d_array a;
  23.         real_1d_array b;
  24.         real_1d_array x;
  25.        
  26.        
  27.         a.setlength(m, n);
  28.         b.setlength(n);
  29.         x.setlength(n);
  30.  
  31.         for (size_t i = 0; i < alpha; i++)
  32.         {
  33.             for (size_t j = 0; j < alpha; j++)
  34.             {
  35.                 a[i][j] = 0;
  36.             }
  37.             cout << endl;
  38.         }
  39.  
  40.         a[0][0] = lambda*S;
  41.         a[alpha - 1][alpha - 1] = lambda*S/length + alpha*S;
  42.  
  43.         for (size_t i = 0; i < alpha; i++)
  44.         {
  45.             b[i] = 0;
  46.         }
  47.  
  48.         b[0] = -q*S;
  49.         b[alpha - 1] = alpha*S*tsredi;
  50.  
  51.         for (int i = 1; i < alpha-1; i++)
  52.         {
  53.             a[i][i] = lambda*S / ((size)*i) + lambda*S / ((size)*(i + 1));
  54.         }
  55.  
  56.         for (size_t i = 1; i < alpha; i++)
  57.         {
  58.             a[i - 1][i] = -1.0*lambda*S / ((size)*i);
  59.             a[i][i - 1] = -1.0*lambda*S / ((size)*i);
  60.         }
  61.  
  62.        
  63.  
  64.         for (size_t i = 0; i < alpha; i++)
  65.         {
  66.             for (size_t j = 0; j < alpha; j++)
  67.             {
  68.                 cout << a[i][j] << " ";
  69.             }
  70.             cout << endl;
  71.         }
  72.         //
  73.         // rmatrixgemm() function allows us to calculate matrix product C:=A*B or
  74.         // to perform more general operation, C:=alpha*op1(A)*op2(B)+beta*C,
  75.         // where A, B, C are rectangular matrices, op(X) can be X or X^T,
  76.         // alpha and beta are scalars.
  77.         //
  78.         // This function:
  79.         // * can apply transposition and/or multiplication by scalar to operands
  80.         // * can use arbitrary part of matrices A/B (given by submatrix offset)
  81.         // * can store result into arbitrary part of C
  82.         // * for performance reasons requires C to be preallocated
  83.         //
  84.         // Parameters of this function are:
  85.         // * M, N, K            -   sizes of op1(A) (which is MxK), op2(B) (which
  86.         //                          is KxN) and C (which is MxN)
  87.         // * Alpha              -   coefficient before A*B
  88.         // * A, IA, JA          -   matrix A and offset of the submatrix
  89.         // * OpTypeA            -   transformation type:
  90.         //                          0 - no transformation
  91.         //                          1 - transposition
  92.         // * B, IB, JB          -   matrix B and offset of the submatrix
  93.         // * OpTypeB            -   transformation type:
  94.         //                          0 - no transformation
  95.         //                          1 - transposition
  96.         // * Beta               -   coefficient before C
  97.         // * C, IC, JC          -   matrix C and offset of the submatrix
  98.         //
  99.         // Below we perform simple product C:=A*B (alpha=1, beta=0)
  100.         //
  101.         //double alpha = 1.0;
  102.  
  103.         //rmatrixgemm(m, n, k, alpha, a, ia, ja, optypea, b, ib, jb, optypeb, beta, c, ic, jc);
  104.         //printf("%s\n", a.tostring(3).c_str()); // EXPECTED: [[4,3],[2,4]]
  105.         ae_int_t info;
  106.         densesolverreport rep;
  107.  
  108.         alglib::rmatrixsolve(a,n,b,info,rep,x);
  109.  
  110.         cout << info << endl;
  111.  
  112.         for (size_t i = 0; i < alpha; i++)
  113.         {
  114.             cout << x[i] << " ";
  115.         }
  116.         system("pause");
  117.     }
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement