I want to solve this system symbolically but it didn’t work. where did I make the mistake? and how can I solve it?
JavaScript
x
8
1
import numpy as np
2
from sympy import symbols,Matrix
3
Y, C, I0, G0, a, b = symbols('Y, C, I_0, G_0, a, b')
4
npA = np.array(([1, -1], [-b, 1]))
5
npd = np.array((I0 + G0, a))
6
x = np.linalg.solve(npA, npd)
7
x
8
I get this error
JavaScript
1
19
19
1
---------------------------------------------------------------------------
2
TypeError Traceback (most recent call last)
3
<ipython-input-42-7ec4f3174f18> in <module>
4
5 npA = np.array(([1, -1], [-b, 1]))
5
6 npd = np.array((I0 + G0, a))
6
----> 7 x = np.linalg.solve(npA, npd)
7
8 x
8
9
<__array_function__ internals> in solve(*args, **kwargs)
10
11
~anaconda3libsite-packagesnumpylinalglinalg.py in solve(a, b)
12
392 signature = 'DD->D' if isComplexType(t) else 'dd->d'
13
393 extobj = get_linalg_error_extobj(_raise_linalgerror_singular)
14
--> 394 r = gufunc(a, b, signature=signature, extobj=extobj)
15
395
16
396 return wrap(r.astype(result_t, copy=False))
17
18
TypeError: No loop matching the specified signature and casting was found for ufunc solve1
19
Advertisement
Answer
You are attempting to solve such an equation: Ax = b. I don’t think you can mix-up command from different libraries like that, there is some compatibility but you should check the documentation
Here a possibility
JavaScript
1
12
12
1
from sympy import symbols, Eq, solve
2
3
a_x, a_y, b_x, b_y = symbols('a_x, a_y, b_x, b_y')
4
5
eq_x = Eq(a_x - a_y, b_x)
6
eq_y = Eq(-b_x * a_x + a_y, b_y)
7
8
result = solve([eq_x, eq_y],(b_x, b_y))
9
10
print(result[b_x])
11
print(result[b_y])
12
Output
JavaScript
1
3
1
a_x - a_y
2
-a_x**2 + a_x*a_y + a_y
3