JavaScript
x
11
11
1
import numpy as np
2
from sympy import symbols, solve
3
x = symbols('x')
4
expr1 = -2*x + x**2 + 1
5
a = solve(expr1)
6
print(a)
7
p = a/2
8
expr2 = -4*x + x**2 + a
9
z = solve(expr2)
10
print(z)
11
JavaScript
1
8
1
5 a = solve(expr1)
2
6 print(a)
3
----> 7 p = a/2
4
8 expr2 = -4*x + x**2 + a
5
9 z = solve(expr2)
6
7
TypeError: unsupported operand type(s) for /: 'list' and 'int'
8
I solved an equation, the answer is an array. I am trying to use the answer for a new equation. I wrote a sample code to explain my problem!
Advertisement
Answer
I see you want to “use the answer for a new equation”.
The previous equation solution is a
, a list with 1 element [1]
then you can use a[0] in your next equation
JavaScript
1
4
1
expr2 = -4*x + x**2 + a[0]
2
z = solve(expr2)
3
print(z)
4
and p=a/2
is totally useless, you didn’t use p
after that.