0

I have a system of 52 equations with float coefficients (usually not rationals). This long list of equations is stored in variable concrete_eqs, and the list of unknowns (Lagrangians) in lagran. The system is linear.

Using solve, the solution would be:

result = solve(
              concrete_focs, lagran
              ,simplify = False 
              ,exclude = []

              )

Using linsolve, it would be:

linresult = list(linsolve(concrete_focs, lagran))

I checked the solution using solve by substituting back into the equations and it gives the correct result. Using linsolve, not only are the solutions different, but they are wrong: they do not solve the system when I substitute them back.

linsolve does not throw any errors. I transformed the system of equations into matrix form by using linear_eq_to_matrix, and the system has full rank. Since the unknowns are indexed variables, I also tried to solve the system with linsolve and only symbols, but this didn't solve the issue.

I would like to solve this linear system with linsolve, since it is much faster than solve, even for this simple system.

I tried to reproduce the issue in simpler problems, using indexed variables, but I got the correct result.

Any hints on why this may be happening? (I suspect it is because of the handling of the float irrational coefficients, but I'm not sure.)

econbernardo
  • 98
  • 1
  • 7
  • 1
    A bug to do with float coefficients and linsolve was recently fixed but the fix is not yet released. Try using sympy master. https://github.com/sympy/sympy/issues/21520 – Oscar Benjamin Aug 24 '21 at 17:54
  • @OscarBenjamin Thank you, I will try that. – econbernardo Aug 24 '21 at 17:59
  • @OscarBenjamin I tried installing sympy from Github master by using ```$ git clone https://github.com/sympy/sympy.git``` and then ```$ python setup.py install``` in the directory where I cloned the master branch. My version is ```'1.9.dev'```. However, the same error persists: ```linsolve``` and ```solve``` are still giving different results. If I could tell ```solve``` that the system is linear, perhaps there could be performance gains, but as far as I know, you can't do that. ```solve``` seems too slow for this simple problem... – econbernardo Aug 24 '21 at 21:47
  • This could be a bug in `linsolve`. I suggest opening an issue with sympy on GitHub. It won't be possible to investigate this further without seeing the actual equations though. – Oscar Benjamin Aug 25 '21 at 18:17
  • Thanks. I will open an issue when I am able to. I can show the equations too, even though they are somewhat burdensome. – econbernardo Aug 31 '21 at 19:56

0 Answers0