简体   繁体   中英

Simultaneous equations using sympy python

I have pasted the code as well as the image of the output below. I keep getting 'm' and 'c' in the output instead of getting the values for m and 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 ). 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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