Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "linalg.h"
- #include "solvers.h"
- #include <iostream>
- using namespace alglib;
- using namespace std;
- int main()
- {
- {
- float lambda = 100;
- float S = 10;
- float length = 1000;
- float q = 5;
- int alpha = 6;
- float tsredi = 273;
- float size = length / alpha;
- ae_int_t m = alpha;
- ae_int_t n = alpha;
- real_2d_array a;
- real_1d_array b;
- real_1d_array x;
- a.setlength(m, n);
- b.setlength(n);
- x.setlength(n);
- for (size_t i = 0; i < alpha; i++)
- {
- for (size_t j = 0; j < alpha; j++)
- {
- a[i][j] = 0;
- }
- cout << endl;
- }
- a[0][0] = lambda*S;
- a[alpha - 1][alpha - 1] = lambda*S/length + alpha*S;
- for (size_t i = 0; i < alpha; i++)
- {
- b[i] = 0;
- }
- b[0] = -q*S;
- b[alpha - 1] = alpha*S*tsredi;
- for (int i = 1; i < alpha-1; i++)
- {
- a[i][i] = lambda*S / ((size)*i) + lambda*S / ((size)*(i + 1));
- }
- for (size_t i = 1; i < alpha; i++)
- {
- a[i - 1][i] = -1.0*lambda*S / ((size)*i);
- a[i][i - 1] = -1.0*lambda*S / ((size)*i);
- }
- for (size_t i = 0; i < alpha; i++)
- {
- for (size_t j = 0; j < alpha; j++)
- {
- cout << a[i][j] << " ";
- }
- cout << endl;
- }
- //
- // rmatrixgemm() function allows us to calculate matrix product C:=A*B or
- // to perform more general operation, C:=alpha*op1(A)*op2(B)+beta*C,
- // where A, B, C are rectangular matrices, op(X) can be X or X^T,
- // alpha and beta are scalars.
- //
- // This function:
- // * can apply transposition and/or multiplication by scalar to operands
- // * can use arbitrary part of matrices A/B (given by submatrix offset)
- // * can store result into arbitrary part of C
- // * for performance reasons requires C to be preallocated
- //
- // Parameters of this function are:
- // * M, N, K - sizes of op1(A) (which is MxK), op2(B) (which
- // is KxN) and C (which is MxN)
- // * Alpha - coefficient before A*B
- // * A, IA, JA - matrix A and offset of the submatrix
- // * OpTypeA - transformation type:
- // 0 - no transformation
- // 1 - transposition
- // * B, IB, JB - matrix B and offset of the submatrix
- // * OpTypeB - transformation type:
- // 0 - no transformation
- // 1 - transposition
- // * Beta - coefficient before C
- // * C, IC, JC - matrix C and offset of the submatrix
- //
- // Below we perform simple product C:=A*B (alpha=1, beta=0)
- //
- //double alpha = 1.0;
- //rmatrixgemm(m, n, k, alpha, a, ia, ja, optypea, b, ib, jb, optypeb, beta, c, ic, jc);
- //printf("%s\n", a.tostring(3).c_str()); // EXPECTED: [[4,3],[2,4]]
- ae_int_t info;
- densesolverreport rep;
- alglib::rmatrixsolve(a,n,b,info,rep,x);
- cout << info << endl;
- for (size_t i = 0; i < alpha; i++)
- {
- cout << x[i] << " ";
- }
- system("pause");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement