from sympy import * a,b=0,0 n = Symbol('n') k= Symbol('k') with open("ab.txt") as f: for line in f.readlines(): ab=line.split('\t') line = line.strip('\n') a=eval(ab[0]) b=eval(ab[1]) solved_value = solve([n ** 2 - k ** 2 - a, 2 * n * k - b], [n, k]) print("a value is {}, b value is {} answer is {}".format(a,b,solved_value)) print("Program done!")
其中方程组是n ** 2 - k ** 2 - a = 0和2 * n * k - b = 0。ab.txt文件内容格式如下,中间是制表符分割。
-472.441 69.17
-516.871 83.004
-604.484 83.004
等等
参考文章:
https://blog.csdn.net/weixin_36474809/article/details/104476870