'Why Isn't smp.solve Solving This System?

Here is my code


import sympy as smp

i1, i2 = smp.symbols('i1 i2', Real=True)

eq1 = -40 + 2500*i2 - 2000*i1

eq2 = 8000*i1 - 2000*i2

i1_solved, i2_solved = smp.solve([eq1, eq2], [i1, i2])

I tried adding a [0] at the end of the smp.solve function but I get an error that states:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 0


Solution 1:[1]

solve() returns a dict. You can access it's elements e.g. with answer.get(i1) or answer[i1] (thanks to @hpaulj).

import sympy as smp

i1, i2 = smp.symbols('i1 i2', Real=True)

eq1 = -40 + 2500*i2 - 2000*i1
eq2 = 8000*i1 - 2000*i2

answer = smp.solve([eq1, eq2], [i1, i2])

print(answer)

Output:

{i1: 1/200, i2: 1/50}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1