Coding help needed to optimize my 3*3 Diagonal matrix with GA.

Hi. I am working on antenna design and for optimization of reactive elements or we can say to find the best parasitic reactance, I am using GA in Matlab. I looked at various resources but my problem is little different and haven't addressed earlier. I have tried below to explain my algorithm with the use of Matlab code it self.
clc;
clear all;
j = sqrt(-1);
c = 3*10^8;
f = 10^9;
lambda = c/f;
d = lambda/2;
h = lambda/2;
display(c);
display(f);
display(lambda);
display(d);
display(h);
z11 = 78.1+(j*35.5);
z12 = 96.8+(j*66.139);
z13 = 60.0824+(j*42.95);
Z_A = [z11 z12 z13; z12 z11 z12; z13 z12 z11]; % Antenna Impedance
display(Z_A);
Z_L = [j*x_1 0 0; 0 50+j*x_2 0; 0 0 j*x_3]; % Load Impedance
display(Z_L);
Z_T = [Z_A] + Z_L;
V = [0;
1;
0];
I = inv(Z_T)*V;
display(I);
display(fval);
In this code I am trying to find the minimum I by optimizing x1,x2 and x3. What I am trying is somehow I can generate x1, x2, x3 and then run GA over and over again on the same program until I get minimum I with my fitness function being
y = -((abs(I(1)-I(2))^2) + (abs(I(3)-I(2))^2));
If anyone has done something related to it or willing to help. your help would be much appreciated and If I write a paper I will surely acknowledge them.

7 Comments

You should avoid using inv(). Instead of
I = inv(Z_T)*V;
you should use
I = Z_T\V;
Are your x1, x2, x3 intended to be real-valued or complex valued? Are they intended to be real and non-negative? Do they have a maximum?
x1, x2 and x3 could be anywhere between -50j to -300j and GA should give me the value for x1, x2, x3 so that current I am getting is minimum.
None of the optimizers, including ga(), are designed to search over complex values. Any variable that is intended to be complex should be split into two variables, one for the real portion and one for the complex portion; you can then combine the two inside the objective function.
Let's just assume for the above mention problem that my x1, x2 and x3 varies between -50 to -300 and if I want to optimize those value to get minimum I. Can I do it with GA? if yes then how? I have tried running GA over only my fitness function which is y = -((abs(I(1)-I(2))^2) + (abs(I(3)-I(2))^2)); but the GA will give me I1 I2 and I3 but that doesn't take into consideration the variable X1, x2 and x3. How do you use GA when there is fitness function actually it self is taking some other function into consideration?
Hi Walter, You said you have to split the variable into real and imaginary and then I use it inside the objective function, if I want to do it here how can I do that? Could you show it with a relevant code?
Instead of (for example)
x(1).^2 - 3 * x(2)
where x(1) is complex, you would break it up into two variables
(x(1)+1i*x(3)).^2 - 3 * x(2)
Depending on the expression, you might be able to simplify the calculation after you do that; for example if there is a imag(x(1)) sub-expression in the original, you could replace that with x(3) directly instead of with imag(x(1)+1i*x(3))
So what could be the right code here? if my values are imaginary.
function best_imp = determine_impedence
c = 3*10^8;
f = 10^9;
lambda = c/f;
d = lambda/2;
h = lambda/2;
z11 = 78.1+(1j*35.5);
z12 = 96.8+(1j*66.139);
z13 = 60.0824+(1j*42.95);
Z_A = [z11 z12 z13; z12 z11 z12; z13 z12 z11]; % Antenna Impedance
nvar = 3;
A = [];
b = [];
Aeq = [];
beq = [];
lb = -300 * ones(nvar, 1);
ub = -50 * ones(nvar, 1);
best_imp = ga(@(x) obj(x, Z_A), nvar, A, b, Aeq, beq, lb, ub);
function y = obj(x, Z_A)
Z_L = [1j*x(1), 0, 0; 0, 50+1j*x(2), 0; 0, 0, 1j*x(3)]; % Load Impedance
Z_T = Z_A + Z_L;
V = [0; 1; 0];
I = Z_T \ V;
y = -((abs(I(1)-I(2))^2) + (abs(I(3)-I(2))^2));
end

Sign in to comment.

 Accepted Answer

function best_imp = determine_impedence
c = 3*10^8;
f = 10^9;
lambda = c/f;
d = lambda/2;
h = lambda/2;
z11 = 78.1+(1j*35.5);
z12 = 96.8+(1j*66.139);
z13 = 60.0824+(1j*42.95);
Z_A = [z11 z12 z13; z12 z11 z12; z13 z12 z11]; % Antenna Impedance
nvar = 3;
A = [];
b = [];
Aeq = [];
beq = [];
lb = -300 * ones(nvar, 1);
ub = -50 * ones(nvar, 1);
best_imp = ga(@(x) obj(x, Z_A), nvar, A, b, Aeq, beq, lb, ub);
function y = obj(x, Z_A)
Z_L = [1j*x(1), 0, 0; 0, 50+1j*x(2), 0; 0, 0, 1j*x(3)]; % Load Impedance
Z_T = Z_A + Z_L;
V = [0; 1; 0];
I = Z_T \ V;
y = -((abs(I(1)-I(2))^2) + (abs(I(3)-I(2))^2));

8 Comments

Woh You are too good Walter. Awesome work I was stuck with this since last 3 weeks. I can surely go further now with the design. Just a last question I am getting a heuristic nature of response here, so is there any way to get the same answer everytime I run or what if I just take the value at some iteration like after 1000.
You can use rng() to set the random number seed.
Remember, you can run ga multiple times and take the best answer.
Hi Walter a small question so I tried running the code and after getting the values of I which are 0.0008 - 0.0012i 0.0025 + 0.0088i 0.0008 - 0.0127i, I don't understand why it is giving me 2 negative and one positive angle it should either be all positive or negative. Do you have any idea what could be the reason for that. I am doing 1000 runs. so rng(1000,'twister). and getting this value.
? I am not sure of the connection between "1000 runs" and rng(1000,'twister') ? The first parameter to rng() controls the seed, but ga() internally calls the random number generator a number of times that might depend upon the response of the function. If you start with rng(1) and call rand() to produce two numbers, the current state would become something that did not bear much relationship to calling rng() using 2 or 3 as the seed.
ga is not designed for complex values; see my above discussion about splitting the complex variables into two parts.
I understand that GA doesn't work on complex variables but if I run your(above) code which is almost similar to what I am trying to get, It gives me 3 values for I and all of them are complex. so my question is why aren't they similar in sign? It should atleast give me the same sign. if ga works correctly. since all the phases will be same or at most couple degrees apart.
The false premise implies all premises. When you use code to do something it is not intended to do, then it may return any result, including working the way you "want" until the time your Senior Vice President is watching you demonstrate it, at which time it could instead decide to say out loud "The boss is a fat-head!" and send an email message to your mother that says "Please wash the elephant with ice cubes and haggis!"
My tests appear to indicate that the zeros of obj occur when x1 = x3, with x2 irrelevant. I am having difficulty interpreting some of my findings, but it appears there might be a small set of values that x1 and x3 must be chosen from, and that y becomes 0 in those cases, no matter what the value of x2.
The formula for y is
- 10000 * ((156250000000000 * x1^2 * x3^2 + 11093750000000000 * x1^2 * x3 + 31762187500000000 * x1 * x3^2 + 1149978125000000000 * x1^2 + 3736521112425000000 * x1 * x3 + 6393827550156250000 * x3^2 - 38063162015837500000 * x1 - 121983908458654175000 * x3 + 4521408223111359099409)^2 / (1562500000000000000 * x1^2 * x2^2 * x3^2 + 110937500000000000000 * x1^2 * x2^2 * x3 + 110937500000000000000 * x1^2 * x2 * x3^2 + 110937500000000000000 * x1 * x2^2 * x3^2 + 11499781250000000000000 * x1^2 * x2^2 + 23488664621875000000000 * x1^2 * x2 * x3 + 27609156250000000000000 * x1^2 * x3^2 + 13392788405500000000000 * x1 * x2^2 * x3 + 23488664621875000000000 * x1 * x2 * x3^2 + 11499781250000000000000 * x2^2 * x3^2 - 1754386725423437500000000 * x1^2 * x2 - 2611325850423437500000000 * x1^2 * x3 - 247315150029750000000000 * x1 * x2^2 - 2981558817028312500000000 * x1 * x2 * x3 - 2611325850423437500000000 * x1 * x3^2 - 247315150029750000000000 * x2^2 * x3 - 1754386725423437500000000 * x2 * x3^2 + 68952991611446745376562500 * x1^2 + 52512019412360693584500000 * x1 * x2 + 159527293499906478503125000 * x1 * x3 + 14996843569186297188840000 * x2^2 + 52512019412360693584500000 * x2 * x3 + 68952991611446745376562500 * x3^2 - 2518083174982482155091812500 * x1 - 2207798895986669961611370000 * x2 - 2518083174982482155091812500 * x3 + 81824373462710400660974340041)^2)^(1 / 2) - 10000 * ((156250000000000 * x1^2 * x3^2 + 31762187500000000 * x1^2 * x3 + 11093750000000000 * x1 * x3^2 + 6393827550156250000 * x1^2 + 3736521112425000000 * x1 * x3 + 1149978125000000000 * x3^2 - 121983908458654175000 * x1 - 38063162015837500000 * x3 + 4521408223111359099409)^2 / (1562500000000000000 * x1^2 * x2^2 * x3^2 + 110937500000000000000 * x1^2 * x2^2 * x3 + 110937500000000000000 * x1^2 * x2 * x3^2 + 110937500000000000000 * x1 * x2^2 * x3^2 + 11499781250000000000000 * x1^2 * x2^2 + 23488664621875000000000 * x1^2 * x2 * x3 + 27609156250000000000000 * x1^2 * x3^2 + 13392788405500000000000 * x1 * x2^2 * x3 + 23488664621875000000000 * x1 * x2 * x3^2 + 11499781250000000000000 * x2^2 * x3^2 - 1754386725423437500000000 * x1^2 * x2 - 2611325850423437500000000 * x1^2 * x3 - 247315150029750000000000 * x1 * x2^2 - 2981558817028312500000000 * x1 * x2 * x3 - 2611325850423437500000000 * x1 * x3^2 - 247315150029750000000000 * x2^2 * x3 - 1754386725423437500000000 * x2 * x3^2 + 68952991611446745376562500 * x1^2 + 52512019412360693584500000 * x1 * x2 + 159527293499906478503125000 * x1 * x3 + 14996843569186297188840000 * x2^2 + 52512019412360693584500000 * x2 * x3 + 68952991611446745376562500 * x3^2 - 2518083174982482155091812500 * x1 - 2207798895986669961611370000 * x2 - 2518083174982482155091812500 * x3 + 81824373462710400660974340041)^2)^(1 / 2)

Sign in to comment.

More Answers (0)

Categories

Find more on Design, Analysis, Benchmarking, and Verification in Help Center and File Exchange

Asked:

on 27 Mar 2016

Commented:

on 14 Sep 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!