Optimization of complex function
1 回表示 (過去 30 日間)
古いコメントを表示
Hello,
After solving a linear equation to find a transmission coefficient for dialectric structure I get the next function -
T_coeff_opt = @(x) (256*(cos(2*(pi)*(2*x(1) + x(2))) - sin(2*(pi)*(2*x(1) + x(2)))*(1i)))/(- 144*cos(2*(pi)*(8*x(1)*(1i) - x(2)*(1i))*(1i)) + 400*cos(2*(pi)*(8*x(1)*(1i) + x(2)*(1i))*(1i)) - 306*sin(2*(pi)*(8*x(1)*(1i) - x(2)*(1i))*(1i))*(1i) + 850*sin(2*(pi)*(8*x(1)*(1i) + x(2)*(1i))*(1i))*(1i) + 900*sin(2*(pi)*x(2))*(1i));
Where x(1), x(2) are the thicknesses of the structure.
I want to optimize the function so I can get the thicknesses x(1), x(2) that satisfy:
1, Maximum transmission (that is defined [T_coeff_opt*conj(T_coeff_opt)].
2, I want to do that for a range of [0, 2*pi].
So for every phase point between [0, 2*pi] i'll get x(1), x(2) that gives me the correct phase with maximum transmission.
I've tried to do that with LSQNONLIN but the results are not what I expected. So maybe there is some other function that handles complex functions better.
I'm using for initial guass for w(n) [n>2] the previous solution to create a smooth (continuous) solution without many jumps or discontinuities.
Also the solution should be periodic [2*pi period].
My code goes like this:
startpoint = 1;
endpoint = 360;
dev = 360;
x_p = linspace(-1,1,dev);
T_phase = (pi)*x_p;
T_coeff_opt = @(x) (256*(cos(2*(pi)*(2*x(1) + x(2))) - sin(2*(pi)*(2*x(1) + x(2)))*(1i)))/(- 144*cos(2*(pi)*(8*x(1)*(1i) - x(2)*(1i))*(1i)) + 400*cos(2*(pi)*(8*x(1)*(1i) + x(2)*(1i))*(1i)) - 306*sin(2*(pi)*(8*x(1)*(1i) - x(2)*(1i))*(1i))*(1i) + 850*sin(2*(pi)*(8*x(1)*(1i) + x(2)*(1i))*(1i))*(1i) + 900*sin(2*(pi)*x(2))*(1i));
x0a = [0.4 0.6]; % Staring initial
lb = [0.08 0.08]; % Lower bound of width
ub = [1 1]; % Upper bound of width
options.Algorithm = 'trust-region-reflective';
options.StepTolerance = 1e-6;
options.FunctionTolerance = 1e-30;
% options = optimoptions('lsqnonlin','Display','off');
options = optimoptions(@lsqnonlin,'Algorithm','trust-region-reflective', 'Display', 'off');
F = @(x)Opt(x,startpoint,T_phase);
[w(startpoint,:), resnorm(startpoint,:), residual(startpoint,:)] = lsqnonlin(F, x0a, lb,ub,options);
for i = startpoint+1:1:endpoint
F = @(x)Opt(x,i,T_phase);
counter = 0;
[w(i,:), resnorm(i,:), residual(i,:)] = lsqnonlin(F, w(i-1,:),lb,ub,options);
minRes = residual(i,:);
while (residual(i,:) > 1e-6 | counter < 10) % Trying to find a better solution.
r = 0.0001*rand(1,1);
[curr_w, resnorm(i,:), residual(i,:)] = lsqnonlin(F, r*w(i-1,:),lb,ub,options);
if (residual(i,:) < minRes)
minRes = residual(i,:);
w(i,:) = curr_w;
end
counter = counter + 1;
end
end
function F = Opt(x,i, T_phase)
T_coeff_opt = (256*(cos(2*(pi)*(2*x(1) + x(2))) - sin(2*(pi)*(2*x(1) + x(2)))*(1i)))/(- 144*cos(2*(pi)*(8*x(1)*(1i) - x(2)*(1i))*(1i)) + 400*cos(2*(pi)*(8*x(1)*(1i) + x(2)*(1i))*(1i)) - 306*sin(2*(pi)*(8*x(1)*(1i) - x(2)*(1i))*(1i))*(1i) + 850*sin(2*(pi)*(8*x(1)*(1i) + x(2)*(1i))*(1i))*(1i) + 900*sin(2*(pi)*x(2))*(1i));
F(1) = (((T_coeff_opt)*conj(T_coeff_opt)) - 1);
F(2) = (angle(T_coeff_opt) - (T_phase(i)));
end
Thanks for any help!
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で QSP, PKPD, and Systems Biology についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!