Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solve system of equations
#20
(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.
Gribouillis likes this post
Reply


Messages In This Thread
Solve system of equations - by Sancho_Pansa - Oct-22-2020, 06:53 AM
RE: Solve system of equations - by Gribouillis - Oct-22-2020, 09:41 AM
RE: Solve system of equations - by metulburr - Oct-22-2020, 09:44 AM
RE: Solve system of equations - by Sancho_Pansa - Oct-22-2020, 09:57 AM
RE: Solve system of equations - by Gribouillis - Oct-22-2020, 11:37 AM
RE: Solve system of equations - by Sancho_Pansa - Oct-22-2020, 12:02 PM
RE: Solve system of equations - by Sancho_Pansa - Oct-22-2020, 12:17 PM
RE: Solve system of equations - by Gribouillis - Oct-22-2020, 12:09 PM
RE: Solve system of equations - by Gribouillis - Oct-22-2020, 12:55 PM
RE: Solve system of equations - by Sancho_Pansa - Oct-22-2020, 01:12 PM
RE: Solve system of equations - by Sancho_Pansa - Oct-23-2020, 09:21 AM
RE: Solve system of equations - by Sancho_Pansa - Oct-23-2020, 03:25 PM
RE: Solve system of equations - by Gribouillis - Oct-24-2020, 08:55 PM
RE: Solve system of equations - by Sancho_Pansa - Oct-26-2020, 08:22 AM
RE: Solve system of equations - by Askic - Oct-26-2020, 10:05 AM
RE: Solve system of equations - by Sancho_Pansa - Oct-26-2020, 10:22 AM
RE: Solve system of equations - by Askic - Oct-26-2020, 10:35 AM
RE: Solve system of equations - by Sancho_Pansa - Oct-26-2020, 10:55 AM
RE: Solve system of equations - by Askic - Oct-26-2020, 05:28 PM
RE: Solve system of equations - by Sancho_Pansa - Oct-27-2020, 08:15 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Heart how to solve complex equations in python HoangF 3 2,784 Dec-26-2021, 07:04 PM
Last Post: HoangF
Question Help with code to solve polynomials equations hiviera 1 1,785 Jul-31-2021, 01:56 AM
Last Post: hiviera
  Difference between os.system("clear") and os.system("cls") chmsrohit 7 16,608 Jan-11-2021, 06:30 PM
Last Post: ykumar34
  How to solve equations, with groups of variables and or constraints? ThemePark 0 1,679 Oct-05-2020, 07:22 PM
Last Post: ThemePark
  Solve a system of linear equations with binary variables lopeslimagabriel 3 2,486 Sep-24-2020, 07:09 AM
Last Post: scidam
  How to solve difficult non-linear equations? shreeniket 3 2,380 Apr-23-2020, 01:36 AM
Last Post: shreeniket
Question Difference between Python's os.system and Perl's system command Agile741 13 6,802 Dec-02-2019, 04:41 PM
Last Post: Agile741
  System of 3 non-linear equations in 3 unknowns (how-to-solve?) samsonite 2 3,568 Mar-23-2019, 10:14 AM
Last Post: samsonite
  Beginner: System of Equations Mahdi1994 2 2,497 Mar-19-2018, 12:37 AM
Last Post: Tiskolin

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020