Oct-27-2020, 08:15 AM
(Oct-26-2020, 05:28 PM)Askic Wrote: Hello Sancho,
please double check your equations. I'm looking your last code. Is it Ar = 1 - omega**2*Cs*Cl or
Ar = 1 - omega**2*Cl*L???
Hello Askic.
Here is the solution, which works fine.
Modifications that was made:
- I replaced the capacitance Cl by the resistor Rl which drastically simplifies the transfer function, which in turn simplifies the work of the fsolve function.
- The equations are now generated by transformations performed on the circuit, created by the Circuit function, which minimizes typos.
from lcapy import Circuit, j, omega import numpy as np from math import pi from scipy.optimize import fsolve def f(LCR, *args): omg = np.array([args[0], args[1], args[2]]) out = np.array([args[3], args[4], args[5]]) cct = Circuit(''' ... Rin 1 2 ... Cs 2 4 ... La 2 3 ... Rs 3 4 ... Rl 4 0''') cct1 = cct.subs({'Rin': 50, 'Cs':LCR[1], 'La': LCR[0], 'Rs': LCR[2], 'Rl': 100}) H = cct1.transfer(1,0,4,0) A = H(j*omega).simplify() Am = A.magnitude equ = np.zeros(3) # equation building for i in range(3): equ[i] = out[i] - Am.evaluate(omg[i]) return equ # Define frequencies in MHz f1 = 130 f2 = 140 f3 = 150 omg = np.array([f1, f2, f3])*1.0e6*2*pi # Define outputs: out = [0.27175539, 0.24606606, 0.22193977] # Define guesses for L [uH], Cs [pF], Rs [Ohm] L0 = 0.3e-6 Cs0 = 1e-12 Rs0 = 1 LCR0 = np.array([L0, Cs0, Rs0]) LCR = fsolve(f, LCR0, args=tuple(np.concatenate((omg, out))), maxfev=10000) print(LCR)Here is output:
Output:[3.20000543e-07 9.99996130e-13 4.99951198e+00]
Here are real values:0.32e-6, 1.0e-12, 5.0
Sincerely,
Sancho.