MATLAB: Coding help needed to optimize the 3*3 Diagonal matrix with GA.

antenna optimization using gaesparminimizing current using gaoptimization of parasitic antennas

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.

Best 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));