Reputation: 238
I'm trying to use optimization to tackle an antenna matching problem where I want to minimize the phase of the resulting matched impedance (through a pi-matching network), subject to Q > 100 (for example), and the real of the impedance =50.
Strangely, it only gives a solution if my initial guesses are 50 for the three variables. Furthermore, it finds a solution when the inequality constraint is >10, but not >1.....I don't understand this since if it >10, it is greater than 1....
If I change the upper and lower bounds, that also affects the solver. With lb=-1000 and ub=1000, I get , x2=1000, x3= -125.57, x4=22.53. But, if I change the lower bound to -200, which should still allow the -125.57 solution, the solver cannot find a solution.
Perhaps I'm setting up the optimization problem incorrectly? This is my problem statement: objective function: minimize the imaginary part of Zin (for resonance) inequality constraint: subject to Q > some number equality constraint: and real part of Zin =50
Here's the simple python script I wrote:
from gekko import GEKKO
m = GEKKO()
x2,x3,x4, = m.Array(m.Var,3,lb=-1000,ub=1000) # upper and lower bounds for unknowns
x2.value = 50; x3.value =50; x4.value =50; # initial guess
#equations
m.Equation((-9.84*x2**2*x4)/(96.786*(x2+x3)*(x2+x3+4)+(120.11*x3+x2*(120.11+x3))*(120.11*(x3+x4)+x2*(120.11+x3+x4))) > 10) # inequality constraint
m.Equation((9.84*(x2**2)*(x4**2))/((9.84*(x2+x3+x4))**2+(120.11*(x2+x3+x4)+x2*(x3+x4))**2) ==50) # equality constraint
#objective
m.Obj((x4*(96.79*(x2+x3)*(x2+x3+x4)+(120.109*x3+ x2*(120.11+x3))*(120.11*(x3+x4)+x2*(120.11+x3+x4))))/(96.9*(x2+x3+x4)**2+(120.11*(x3+x4)+x2*(120.11+x3+x4))**2))
#m.options.IMODE=3
m.options.SOLVER=3
#Solve
#m.solve(disp=False)
m.solve()
print('x2 =' ,x2.value,'x3 =',x3.value,'x4 =',x4.value)
Here's a schematic of the circuit analyzed (jX1==0),
and the equations derived:
ReZinpi=(R1 X2^2 X4^2)/(R1^2 (X2 + X3 + X4)^2 + ((X3 + X4) XL + X2 (X3 + X4 + XL))^2)
ImZinpi = (X4 (R1^2 (X2 + X3) (X2 + X3 + X4) +
(X3 XL + X2 (X3 + XL)) ((X3 + X4) XL + X2 (X3 + X4 + XL))))
/(R1^2 (X2 + X3 + X4)^2 + ((X3 + X4) XL + X2 (X3 + X4 + XL))^2)
Qpi= -((R1 X2^2 X4)/(R1^2 (X2 + X3) (X2 + X3 + X4) +
(X3 XL + X2 (X3 + XL)) ((X3 + X4) XL + X2 (X3 + X4 + XL))))
Is this approach to optimize the component values in my pi matching network to maximize the match (minimize the phase) while achieving a high Q wrong?
Upvotes: 2
Views: 153
Reputation: 14346
I can't verify your equations but can give some insight on the problem characteristics. It appears that your problem is very nonlinear. The interior point algorithm may take a different route because of different bounds. Here is a contour plot of your solution with x2=1000 to reduce it down to just x3 and x4 as variables.
There is the objective function, inequality constraint (>10) as the black lines and the equality constraint (=50) as the blue line. The variables in the denominator may be getting small (approaching zero). Sometimes it helps to multiply a denominator term to the other side of the equation such as x/y==50
to x=y*50
.
from gekko import GEKKO
m = GEKKO(remote=False)
# upper and lower bounds for unknowns
x2,x3,x4 = m.Array(m.Var,3,lb=-1000,ub=1000)
x2.value = 50; x3.value =50; x4.value =50; # initial guess
#equations
m.Equation((-9.84*x2**2*x4)/(96.786*(x2+x3)*(x2+x3+4)+\
(120.11*x3+x2*(120.11+x3))*(120.11*(x3+x4)+\
x2*(120.11+x3+x4))) > 10) # inequality constraint
m.Equation((9.84*(x2**2)*(x4**2))/((9.84*(x2+x3+x4))**2+\
(120.11*(x2+x3+x4)+x2*(x3+x4))**2) ==50) # equality constraint
#objective
m.Minimize((x4*(96.79*(x2+x3)*(x2+x3+x4)+(120.109*x3+ \
x2*(120.11+x3))*(120.11*(x3+x4)+x2*\
(120.11+x3+x4))))/(96.9*(x2+x3+x4)**2+\
(120.11*(x3+x4)+x2*(120.11+x3+x4))**2))
#m.options.IMODE=3
m.options.SOLVER=3
#Solve
#m.solve(disp=False)
m.solve()
print('x2 =' ,x2.value,'x3 =',x3.value,'x4 =',x4.value)
# solution
x2_opt = 1000.0
x3_opt = -125.57474673
x4_opt = 22.537916773
## Generate a contour plot
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
# Design variables at mesh points
x2 = x2_opt
x3 = np.arange(-150.0, -100.0, 0.2)
x4 = np.arange(10, 30, 0.1)
x3,x4 = np.meshgrid(x3, x4)
# Equations and Constraints
eq1 = (-9.84*x2**2*x4)/(96.786*(x2+x3)*(x2+x3+4)+\
(120.11*x3+x2*(120.11+x3))*(120.11*(x3+x4)+x2*(120.11+x3+x4)))
eq2 = (9.84*(x2**2)*(x4**2))/((9.84*(x2+x3+x4))**2+\
(120.11*(x2+x3+x4)+x2*(x3+x4))**2)
obj = (x4*(96.79*(x2+x3)*(x2+x3+x4)+(120.109*x3+ x2*(120.11+x3))*\
(120.11*(x3+x4)+x2*(120.11+x3+x4))))/(96.9*(x2+x3+x4)**2+\
(120.11*(x3+x4)+x2*(120.11+x3+x4))**2)
# Create a contour plot
# Visit https://matplotlib.org/examples/pylab_examples/contour_demo.html
# for more examples and options for contour plots
plt.figure()
# Objective contours
CS = plt.contour(x3,x4,obj)
plt.clabel(CS, inline=1, fontsize=10)
# eq1>10
CS = plt.contour(x3,x4,eq1,[10.0,15.0,20.0],colors='k',linewidths=[2.0,0.5,0.5])
plt.clabel(CS, inline=1, fontsize=10)
# eq2=50
CS = plt.contour(x3,x4,eq2,[50],colors='b',linewidths=[4.0])
plt.clabel(CS, inline=1, fontsize=10)
plt.plot(x3_opt,x4_opt,'.',color='orange',markersize=15)
# Add some labels
plt.xlabel('x3')
plt.ylabel('x4')
# Save the figure as a PNG
plt.savefig('contour_plot.png')
# Show the plots
plt.show()
Upvotes: 1