[GiNaC-list] GiNaC::marix::solve(..)

Lisa Maletzki l.maletzki at tu-bs.de
Wed Jun 3 23:58:15 CEST 2009


Zitat von Alexei Sheplyakov <varg at metalica.kh.ua>:

> 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
>
>

Thanks again, I think that will do the trick but when compiling it I  
get a linker error which I cannot solve (I'm fairly new to c++) I  
can't say if it is just missing a library of if I wrote something in  
the code wrong.

This is the output:

g++ -Xlinker `pkg-config --cflags --libs ginac` -o"sep"   
./src/bezierPoints.o ./src/testmain.o ./src/xml.o ./src/xmlParser.o
./src/bezierPoints.o: In function `bezierPoints::solve(GiNaC::matrix, int)':
/my_folder/Debug/../src/bezierPoints.cpp:63: undefined reference to  
`bezierPoints::generate_symbols(std::vector<GiNaC::symbol,  
std::allocator<GiNaC::symbol> >&, std::basic_string<char,  
std::char_traits<char>, std::allocator<char> > const&)'

The method is declared in the header file and called with the write  
name in the source file, so typing error can be ruled out. Any help?

Kind regards,

Lisa



More information about the GiNaC-list mailing list