0

I have a parametric function as below:

cr = xxx;
ci = xxx;
pr = xxx;
pi = xxx;
d = xxx;
H = (cr+I ci)/(s-(pr+I pi)) + (cr-I ci)/(s-(pr-I pi)) + d;

As can be seen the numerator and denominator are in complex conjugate form. Now I have two list for poles and residues like below:

poles: -1.95307e+09 + -7.78828e+09j, -1.95307e+09 + 7.78828e+09j, -2.68057e+08 + -5.9168e+09j, -2.68057e+08 + 5.9168e+09j, ....



residues: 1.88115e+07 + -4.32942e+07j, 1.88115e+07 + 4.32942e+07j, -251105 + 3.24774e+06j, -251105 + -3.24774e+06j, 2.95035e+06 + -2.80015e+06j, ...

d = 1.1

every two nearby elements in poles or residues are in complex conjugate form.

I have to use the first two elements in the poles and the first two elements in residues list to make the first function. Then I have to use the next two pairs in my poles and residue lists to make the second function and so on.

I want to have my function for each pole and residue pairs and then do some calculations for each function, like calculating the zeros of each function. Thanks for any help

Hey There
  • 275
  • 3
  • 14
  • let's say `x` is a variable that stores a complex number, `x.real` is the real part and `x.imag` is the imaginary part. If that's not what you need then make the question clearer – Shinra tensei Jan 29 '19 at 20:11
  • I can have the real and imaginary parts of my lists. let's say for example for poles it would be something like this: 1,1, -2, -2, 8, 8, and so on. now let's say that the length of this list is 50. one way of making the function is to use only need 25 elements of this list. I have to skip the second similar value. – Hey There Jan 29 '19 at 20:19
  • I am so sorry but I really don't understand what you're trying to ask or do – Shinra tensei Jan 29 '19 at 20:21
  • That's Ok. Thanks for your time. I just want to make my function by using the first two elements in the poles and the first two elements in residues list. Then, I have to repeat this procedure for the next two pairs in poles and residues list. – Hey There Jan 29 '19 at 20:30
  • @AmirRezaJalali if you want to group `poles` and `residues` into groups of two values (depending on what datatypes each element is), you could create two new lists of sublists `ps = []` for `poles` then `for p in poles: ps.append(p.split(' + '))`, another same for `residues` which gives you groups of two 2 values (e.g. `['-1.95307e+09', '-7.78828e+09j'], ['-1.95307e+09', '7.78828e+09j'],`) to pass to your function. If this is not what you are asking, we may need a [mcve] to better understand your question – chickity china chinese chicken Jan 29 '19 at 21:08
  • Is *H* supposed to be a function of *s* after the other parameters are known? – Davis Herring Jan 30 '19 at 04:37
  • @DavisHerring yes. – Hey There Jan 30 '19 at 06:32

1 Answers1

1

We of course don’t need the complex conjugates; we can compute those ourselves. Then it’s just

d=…  # shared
def mkH(c,p):
  return lambda s: c/(s-p)+c.conjugate()/(s-p.conjugate())+d

funcs=map(mkH,residues,poles)

The factory function avoids the standard issue of having all the lambdas capture the same variables. The last line could of course be a list comprehension or explicit for if needed.

Davis Herring
  • 36,443
  • 4
  • 48
  • 76