У меня есть матрица с некоторыми неизвестными переменными, которые нужно решить с помощью компьютера. Как мне решить эту проблему??
Например, - K = [[1,0],[0, (1-p)**.5]] , где p - неизвестная переменная, которую необходимо выяснить.
Solving Equations
SymPy's
solve()
function can be used to solve equations and expressions that contain symbolic math variables.Equations with one solution A simple equation that contains one variable like
x−4−2=0
can be solved using the solve function. When only one value is part of the solution, the solution is in the form of a list.The code section below demonstrates SymPy's solve() function when an expression is defined with symbolic math variables.
from sympy import symbols, solve
x = symbols('x')
expr = x-4-2
sol = solve(expr)
print (sol)
Выход:
[6]
.
from sympy import symbols, solve
p = symbols('p')
expr = (1-p)**.5
sol = solve(expr)
print (sol)
выход:
[1.00000000000000]
.
from sympy import symbols, solve
K = [[1,0],[0, int(solve((1-symbols('p'))**.5)[0])]]
print (K)
выход:
[[1, 0], [0, 1]]