New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Success of linsolve depends on how the unknowns are sorted (sympy>=1.7) #22237
Comments
The internal implementation of In [17]: construct_domain([f(t)])[0]
Out[17]: ZZ[f(t)]
In [18]: construct_domain([f(t).diff(t)])[0]
Out[18]: ZZ[Derivative(f(t), t)]
In [19]: construct_domain([f(t).diff(t)+f(t)])[0]
Out[19]: EX The EX domain can be very slow which is essentially why this becomes slow. If we replace the functions and derivatives with separate symbols then everything works fine and we get a reasonably simple expression for the result: In [20]: t0,t1,t2 = symbols('t0,t1,t2')
In [21]: x0,x1,x2 = symbols('x0,x1,x2')
In [22]: rep = {th:t0, th.diff(): t1, th.diff(t, 2):t2, x:x0, x.diff():x1, x.diff(t, 2):x2}
In [23]: lsys.subs(rep)
Out[23]:
⎡Kₜ⋅V(t) ⎛Kₜ⋅Kᵥ ⎞ ⎛ 2⎞ ⎛ Kₜ⋅Kᵥ b⎞ ⎛ Iₘ ⎞⎤
⎢─────── - M⋅g⋅l⋅t₀ + t₁⋅⎜───── + b⎟ + t₂⋅⎝Iₘ + J + M⋅l ⎠ + x₁⋅⎜- ───── - ─⎟ + x₂⋅⎜- ── + M⋅l⎟⎥
⎢ R ⎝ R ⎠ ⎝ R⋅r r⎠ ⎝ r ⎠⎥
⎢ ⎥
⎢ ⎛Kₜ⋅Kᵥ ⎞ ⎛ Kₜ⋅Kᵥ b⎞ ⎥
⎢ t₁⋅⎜───── + b⎟ x₁⋅⎜- ───── - ─⎟ ⎥
⎢ Kₜ⋅V(t) ⎛ Iₘ ⎞ ⎛I Iₘ ⎞ ⎝ R ⎠ ⎝ R⋅r r⎠ ⎥
⎢ - ─────── + t₂⋅⎜- ── + M⋅l⎟ + x₂⋅⎜── + ── + M + m⎟ - ────────────── - ──────────────── ⎥
⎢ R⋅r ⎝ r ⎠ ⎜ 2 2 ⎟ r r ⎥
⎣ ⎝r r ⎠ ⎦
In [24]: %time ok = linsolve(lsys.subs(rep), [t2, x2])
CPU times: user 120 ms, sys: 0 ns, total: 120 ms
Wall time: 118 ms
In [25]: %time ok = linsolve(lsys.subs(rep), [x2, t2])
CPU times: user 112 ms, sys: 0 ns, total: 112 ms
Wall time: 115 ms I'm not sure whether it should be When you say that this worked perfectly with sympy 1.6 what exactly do you mean? When I try this with 1.6 I just get the empty set: In [3]: linsolve(lsys, [xs, ths])
Out[3]: ∅ |
Thank you for your quick answer, @oscarbenjamin!
One of the things I like about sympy over Matlab is being able to work with derivatives. I was used to creating intermediate symbols in Matlab, but I really like not needing to do so in sympy. Maybe this is not good practice anyway, and I should stick to using intermediate symbols. |
This is fixable. I'm just not sure whether it should be Alternatively there could be a more targeted fix just for Possibly it does not make sense to do this in I'm honestly not sure though. @jksuom what do you think? |
But then I suppose |
I am having a very strange issue with
linsolve
. After upgrading to a sympy version equal or higher than 1.7, the following code, which worked perfectly on sympy 1.6, gets stuck at solving the linear system:However, if I reverse the order of the unknowns, like this:
then everything works fine, regardless of the sympy version.
The text was updated successfully, but these errors were encountered: