[GiNaC-list] GiNaC::marix::solve(..)
Alexei Sheplyakov
varg at metalica.kh.ua
Wed Jun 3 14:53:47 CEST 2009
Hi,
On Wed, Jun 03, 2009 at 01:17:59PM +0200, Lisa Maletzki wrote:
> But the problem I have is, that I do not know how big my
> matrix will be. In the smallest case it is a 18x18 matrix, so getting all
> those symbols would be rather complicated, or am I just thinking that?
You might want to use something like this:
void generate_symbols(vector<symbol>& vars, const string& pattern)
{
for (unsigned i = 0; i < vars.size(); ++i) {
std::ostringstream ostr;
ostr << pattern << i;
symbol tmp(ostr.str());
vars[i] = tmp;
}
}
unsigned n = 18;
vector<symbol> vars(n);
generate_symbols(vars, "x"); // populates vars with symbols "x0", "x1", etc.
matrix A(n, n);
// your code to fill it in
matrix b(n, 1);
// your code fill it in
matrix x(n, 1);
for (unsigned i = 0; i < n; ++i)
x(i, 1) = xv[i];
matrix result = A.solve(x, b);
Also, be forewarned: using GiNaC for numerical computations (including
solving linear systems with coefficients being floating-point numbers)
incurs substantial overhead, so you'd better use some linear algebra
software, such as GSL, ATLAS, etc.
Best regards,
Alexei
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: Digital signature
URL: <http://www.cebix.net/pipermail/ginac-list/attachments/20090603/023105cd/attachment.sig>
More information about the GiNaC-list
mailing list