简体   繁体   English

使用 sympy python 的联立方程

[英]Simultaneous equations using sympy python

I have pasted the code as well as the image of the output below.我在下面粘贴了代码以及 output 的图像。 I keep getting 'm' and 'c' in the output instead of getting the values for m and c.我在 output 中不断得到“m”和“c”,而不是得到 m 和 c 的值。 Why is this happening?为什么会这样?

import math
from sympy import solve, Eq
from sympy.abc import m, c
import sympy as sym

std = 100
std_half = std/2

m,c = sym.symbols('m,c')

eq1 = sym.Eq(0-(math.log(g_value3/g_value2)),(m*std_half)+c)       #y=mx+c, where y is absorbance, x is known concentration
eq2 = sym.Eq(0-(math.log(g_value4/g_value2)),(m*std)+c)

result = sym.solve([eq1,eq2],(m,c))

conc = ((0-math.log(g_value1/g_value2))-c)/m    #re-arranging y=mx+c in order to get x which is the concentration[![This is the output I'm getting][1]][1]

solve doesn't assign a value, it determines a value and assigns it to the output (which you have stored as result ). solve分配值,它确定一个值并将其分配给 output (您已将其存储为result )。 I you want to see what conc is with the values of m and c that are in result , I recommend that you use dict=True with solve and do as shown below:我想看看concresult中的mc的值是什么,我建议您使用dict=Truesolve并执行如下所示:

result = sym.solve([eq1,eq2],(m,c),dict=True)  # get a list of one or more dict
conc = ((0-math.log(g_value1/g_value2))-c)/m  # c and m are still symbols
print([conc.subs(r) for r in result])  # replaces c and m with values from solve

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM