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

Jens Vollinga jensv at nikhef.nl
Tue Jun 2 19:35:08 CEST 2009


Lisa Maletzki schrieb:
> I have a smallish problem with the method mentioned above 
> (matrix::solve(..)). I have two nxn numeric matrices A and b (from the 
> equation Ax=b) and of course want the matrix x in the end but I keep on 
> getting the error that the first argument must be a matrix of symbols. 
> Now my question how can I do that? I tried it with ex 
> symbolic_matrix(..) but I couldn't get it to work since it is of the 
> type ex and not matrix.

take the following example as a guide:

	matrix A(2,2);
	A = 1, 2, 3, 4;
	symbol x1("x1"), x2("x2");
	matrix x(2,1);
	x = x1, x2;
	matrix b(2,1);
	b = 5, 6;
	cout << A.solve(x, b) << endl;

As the manual warns, you will get an exception thrown if the system is 
overdetermined. A more robust version is shown in the following example 
using no matrices:

	symbol x1("x1"), x2("x2");
	lst equations;
	equations.append(1*x1 + 2*x2 == 5);
	equations.append(3*x1 + 4*x2 == 6);
	cout <<  lsolve(equations, lst(x1,x2)) << endl;


More information about the GiNaC-list mailing list