符号变量替换:Python

时间:2018-07-30 07:14:37

标签: python sympy symbolic-math

我希望通过代入符号变量'x'的值来找到给定方程的值。但是,输出仍然包含变量:

import math
from sympy import *

m = var ('x')
x = m
i = 1

while i <= 100:
    m = sin(m)
    i = i + 1

i = 1

while i <= 7:
    k = diff(m,x)
    i = i + 1

print(k.subs(x, 0))  

输出:

cos(x)*cos(sin(x))*cos(sin(sin(x)))*cos(sin(sin(sin(x))))*cos(sin(sin(sin(sin(x)))))*cos(sin(sin(sin(sin(sin(x))))))*cos(sin(sin(sin(sin(sin(sin(x)))))))*cos(sin(sin(sin(sin(sin(sin(sin(x))))))))*cos(sin(sin(sin(sin(sin(sin(sin(sin(x)))))))))*cos(sin(sin(sin(sin(sin(sin(sin(sin(sin(x))))))))))

先谢谢您!

1 个答案:

答案 0 :(得分:0)

根据标题进行回答,使用

k.evalf(subs={x: 0})

但是我真的认为您应该处理您的代码。它不是Pythonic,可能无法满足您的目的。