Oct-26-2020, 10:35 AM
I see,
this looks like as if the constrained optimization would probably do better (since L,C and R cannot be negative)
this looks like as if the constrained optimization would probably do better (since L,C and R cannot be negative)
import math from scipy.optimize import least_squares def f(LCR): # variables L = LCR[0] Cs = LCR[1] Rs = LCR[2] # global constants Pi = math.pi Rin = 10.0 Cl = 3.0e-12 # measurement-related constants f0 = 130e6 f1 = 140e6 f2 = 150e6 omg = [0, 0, 0] out = [0, 0, 0] omg[0] = 2*Pi*f0 omg[1] = 2*Pi*f1 omg[2] = 2*Pi*f2 out[0] = 6.658482971121064 out[1] = 25.89226207742419 out[2] = 7.013950018010094 # A and B arrays Ar = [0, 0, 0] Aj = [0, 0, 0] Br = [0, 0, 0] Bj = [0, 0, 0] equ = [0, 0, 0] # equation building for i in range(3): Ar[i] = 1 - omg[i]**2*Cl*L Aj[i] = omg[i]*Cs*Rs Br[i] = 1 - omg[i]**2*(L*(Cs + Cl) + Cl*Cs*Rin*Rs) Bj[i] = omg[i]*(Cs*Rs + Cl*Rin + Cl*Rs - omg[i]**2*Cl*Cs*Rin*L) equ[i] = out[i] - math.sqrt(Ar[i]*Ar[i] + Aj[i] * Aj[i])/math.sqrt(Br[i]*Br[i] + Bj[i]*Bj[i]) return equ LCR0 = [0.3e-6, 1e-12, 1] res = least_squares(f, (LCR0), bounds=((0, 0, 0), (1.0e-6, 1.0e-10, 2))) print(res)Let me know if this is closer to the expected solution.