How to keep calculation precision at equations solving using linear algebra of root?

___I use linear algebra of root and c++ codes by myself to solve equations:


the coefficients of the equations is:
Bi86_vector_Fazekas.txt (423 Bytes)
Aij86_matrix_Fazekas.txt (3.2 KB)
ant the result by my c++ code is:
4.234800822336149e+02
-8.156127777281255e+02
5.942013904498536e+02
-1.698128947296208e+02
-1.814064793026619e+01
2.684494321505973e+01
-7.809183721387632e+00
1.025160202933659e+00
-5.279662705325613e-02

and the result by linear algebra of root is:
4.232980e+02
-8.507327e+02
6.020703e+02
-1.683711e+02
-2.084173e+01
2.803771e+01
-8.073064e+00
1.055285e+00
-5.421381e-02

there is some difference between the two results,
my question is how to control the tolerance in the calculation process?
Please read tips for efficient and successful posting and posting code

ROOT Version: 6.24/04
Platform: Ubuntu 20.04
Compiler: GCC 9.3.0


I think @moneta can help you.
But you did not post your code. Can you post the C++ code producing these results ?

EquationSolving.cpp (15.3 KB)

the file up is about my c++ codes

here it is the codes by the linear algebra of root
EquationSolving.cpp (4.6 KB)

Hi
Running your ROOT code I am getting a very different result than you

7.931703e+16
-1.379945e+17
1.104058e+17
-3.786798e+16
3.037788e+15
2.034487e+15
-7.288125e+14
9.924564e+13
-5.106192e+12

Your standalone code does not compile for me.

I would check the matrix condition, it is normal that if the condition is large you are getting numerical error.
You can try using also a different decomposition for the matrix or a different tolerance.
Look on how the Determinant is computed and you can play with that code.
See ROOT: math/matrix/src/TMatrixT.cxx Source File

Lorenzo

i will continue studying linear algebra in root about the resolutions of equation solving.

I do not kwon why the big difference between your result and mine occurs, it seems the results shauld be the same.
and sorry for “Your standalone code does not compile for me”, my codes are compiled by visual studio 2019 on windows 10 platform.

I change all datas of long double to double in my c++ codes, the results are exactly same. so i doubt linear algebra in root can not keep high precision at equations solving.

and by the way, how to control tolerance of linear algebra in root?

Hi,
This explains then the difference. Linear algebra in ROOT is based on double precision.

TO control the tolerance you can try to use TMatrixD::SetTol( tolerance).
The default value is already the double precision tolerance 2.2204460e-16. So if you want to decrease, I don’t think it will work, but you can increase it

Lorenzo

sorry, i meant the results are the exactly same using my c++ codes with double or long double.

I used “Determinant Solution” and “Decomposition Solution” to do equation solving, the root codes are upload:
EquationSolving.cpp (6.3 KB)
MatrixDecomposition.cpp (2.0 KB)

the result from “Determinant Solution” is:
4.232980e+02
-8.507327e+02
6.020703e+02
-1.683711e+02
-2.084173e+01
2.803771e+01
-8.073064e+00
1.055285e+00
-5.421381e-02

the result from “Decomposition Solution” is:
4.325485e+02
-8.299728e+02
6.008439e+02
-1.683699e+02
-2.084173e+01
2.803771e+01
-8.073064e+00
1.055285e+00
-5.421381e-02

there is some apparent difference, why?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.