Skip to content

Commit 6d97d40

Browse files
committed
linear_eq_to_matrix: fix for non-expanded terms
Fixes sympy#16577
1 parent 9f6d5af commit 6d97d40

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

sympy/solvers/solveset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,8 +1858,8 @@ def linear_coeffs(eq, *syms, **_kw):
18581858
elif f.is_Add:
18591859
d1 = linear_coeffs(f, *syms, **{'dict': True})
18601860
d[0].append(m*d1.pop(0))
1861-
xf, vf = list(d1.items())[0]
1862-
d[xf].append(m*vf)
1861+
for xf, vf in d1.items():
1862+
d[xf].append(m*vf)
18631863
else:
18641864
break
18651865
else:

sympy/solvers/tests/test_solveset.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,11 @@ def test_linear_eq_to_matrix():
10601060
Matrix([[1]]), Matrix([[-1]]))
10611061

10621062

1063+
def test_issue_16577():
1064+
assert linear_eq_to_matrix(Eq(a*(2*x + 3*y) + 4*y, 5), x, y) == (
1065+
Matrix([[2*a, 3*a + 4]]), Matrix([[5]]))
1066+
1067+
10631068
def test_linsolve():
10641069
x, y, z, u, v, w = symbols("x, y, z, u, v, w")
10651070
x1, x2, x3, x4 = symbols('x1, x2, x3, x4')
@@ -2025,3 +2030,4 @@ def test_linear_coeffs():
20252030
linear_coeffs(x + 2*x**2 + x**3, x, x**2))
20262031
raises(ValueError, lambda:
20272032
linear_coeffs(1/x*(x - 1) + 1/x, x))
2033+
assert linear_coeffs(a*(x + y), x, y) == [a, a, 0]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy