0
votes

symbolic model function passing Hi! I stuck in my fitting due to my symbolic function, Please kindly let me know how this issue could be solved here is my code, I need to pass tow independent_var which are xCl and XI and a is parameter:

import numpy as np
import lmfit
import sympy as sp    
anion = {'I': 1, 'Cl': 1}
xa = {'I': 0.2, 'Cl': 0.3}
xCl = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
xI = [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.1, 0.8, 0.11, 0.12]

def g(anion, xa, a):
    xzc = 0
    for k1, k2 in zip(anion, xa):
        xzc += sp.symbols(f"x{k1}") * sp.symbols(f"x{k2}") + a
    return xzc
obj = lmfit.Model(g, independent_vars=['xCl', 'xI'])
pars = obj.make_params(a=0.1)

result = mod.fit(ydat, pars, xCl, xI)
print(result.fit_report())

but I' ve found;


Traceback (most recent call last): File "F:\Zohreh\MainZohreh\postdoc-field\CSU\pythonProject\simple_Lmfit.py", line 36, in obj = lmfit.Model(g, independent_vars=['xCl', 'xI']) File "C:\Users\Zohreh\AppData\Roaming\Python\Python310\site-packages\lmfit\model.py", line 277, in init self._parse_params() File "C:\Users\Zohreh\AppData\Roaming\Python\Python310\site-packages\lmfit\model.py", line 541, in _parse_params raise ValueError(self._invalid_ivar % (arg, fname)) ValueError: Invalid independent variable name ('xCl') for function g