yefj
Advanced Member level 4
Hello , I got this article which is attached.
i am trying to recreate its result where basicly i have incident wave ,anomal reflection waves and evanesant waves.
I have built the code using the mathematical logic shown in the photo bellow.
In the article they dont say how they got the optimised expression so i have built the full expression for E tangential and H tangential and tried to find the complex coeeficients of the evanecant waves.
unfortunetly my GA matlab mechanism the i am trying to use in the end is not runningas shown in the error bellow.
I just said to it to find parameters so my S bunction will be between some values.
Where did i go wriong implementing this GA optimization?
Is the some alternative optimization function i could use?
Error in optim2 (line 46)
[sol,fval] = solve(prob);
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
Hello, i forgot that the coefficents of the evanecant waves are complex.
updated code shown bellow.
But still the GA algorithms gives me a bug when i try to run it.
Is there some wat to make the optimization work?
Infeasible individuals are present in the final population.
Optimization terminated: average change in the spread of Pareto solutions less than options.FunctionTolerance.
Constraints are not satisfied within constraint tolerance.
Error using optim.problemdef.OptimizationProblem/solve
Unable to perform assignment because the size of the left side is 1-by-100 and the size of the right side
is 10-by-10.
Error in optim2 (line 46)
[sol,fval] = solve(prob);
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
:
i am trying to recreate its result where basicly i have incident wave ,anomal reflection waves and evanesant waves.
I have built the code using the mathematical logic shown in the photo bellow.
In the article they dont say how they got the optimised expression so i have built the full expression for E tangential and H tangential and tried to find the complex coeeficients of the evanecant waves.
unfortunetly my GA matlab mechanism the i am trying to use in the end is not runningas shown in the error bellow.
I just said to it to find parameters so my S bunction will be between some values.
Where did i go wriong implementing this GA optimization?
Is the some alternative optimization function i could use?
Error in optim2 (line 46)
[sol,fval] = solve(prob);
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
Code:
clc
clear all
f=6;
lambda=300/6;
theta_in_rad=(0/180)*pi;
theta_out_rad=(70/180)*pi;
x=linspace(-0.5*lambda,0.5*lambda,50);
y=0*linspace(-0.5*lambda,0.5*lambda,50);
[xx,yy]=meshgrid(x,y);
k=2*pi/lambda;
E_i=1;
E_r=E_i*sqrt(cos(theta_in_rad)/cos(theta_out_rad));
eta=377;
D_x=1.064*lambda;
k_x=k*sin(theta_in_rad)+2*pi/D_x;
k_y=sqrt(k^2-k_x.^2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n=[2,3,4,5,6,7,8];
k_x_n=k*sin(theta_in_rad)+(2*pi.*n)/D_x;
k_y_n=sqrt(k^2-k_x_n.^2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%E_t=E_i.*exp(-j*k*xx*sin(theta_in_rad)+j*k*yy*cos(theta_in_rad))+E_r.*exp(-j*k_x*xx-j*k_y*yy);%E_z
%E_t=E_i.*exp(-j*k*xx*sin(theta_in_rad)+j*k*yy*cos(theta_in_rad));%E_z
%E_t=E_i.*exp(-j*k*xx*sin(theta_in_rad)+j*k*yy*cos(theta_in_rad))+E_r.*exp(-j*k_x*xx-j*k_y*yy)
%E_t_evanesent=E_opt(1).*exp(-j*k_x_n(1)*xx-j*k_y_n(1)*yy)+E_opt(2).*exp(-j*k_x_n(2)*xx-j*k_y_n(2)*yy)+...
%E_t=E_i.*exp(-j*k*xx*sin(theta_in_rad)+j*k*yy*cos(theta_in_rad))+E_r.*exp(-j*k_x*xx-j*k_y*yy)+E_t_evanesent;
%E_t_ev=E_i.*exp(-j*k*xx*sin(theta_in_rad)+j*k*yy*cos(theta_in_rad))+E_r.*exp(-j*k_x*xx-j*k_y*yy)+E_opt(1).*exp(-j*k_x_n(1)*xx-j*k_y_n(1)*yy)+E_opt(2).*exp(-j*k_x_n(2)*xx-j*k_y_n(2)*yy)+E_opt(3).*exp(-j*k_x_n(3)*xx-j*k_y_n(3)*yy)+E_opt(4).*exp(-j*k_x_n(4)*xx-j*k_y_n(4)*yy)+E_opt(5).*exp(-j*k_x_n(5)*xx-j*k_y_n(5)*yy)+E_opt(6).*exp(-j*k_x_n(6)*xx-j*k_y_n(6)*yy)+E_opt(7).*exp(-j*k_x_n(7)*xx-j*k_y_n(7)*yy);
%H_t_ev=(j*k*cos(theta_in_rad))*E_i.*exp(-j*k*xx*sin(theta_in_rad)+j*k*yy*cos(theta_in_rad))+(-j*k_y)*E_r.*exp(-j*k_x*xx-j*k_y*yy)+(-j*k_y_n(1))*E_opt(1).*exp(-j*k_x_n(1)*xx-j*k_y_n(1)*yy)+(-j*k_y_n(2))*E_opt(2).*exp(-j*k_x_n(1)*xx-j*k_y_n(2)*yy)+(-j*k_y_n(3))*E_opt(3).*exp(-j*k_x_n(3)*xx-j*k_y_n(3)*yy)+(-j*k_y_n(4))*E_opt(4).*exp(-j*k_x_n(4)*xx-j*k_y_n(4)*yy)+(-j*k_y_n(5))*E_opt(5).*exp(-j*k_x_n(5)*xx-j*k_y_n(5)*yy)+(-j*k_y_n(6))*E_opt(6).*exp(-j*k_x_n(6)*xx-j*k_y_n(6)*yy)+(-j*k_y_n(7))*E_opt(7).*exp(-j*k_x_n(7)*xx-j*k_y_n(7)*yy);
E_opt = optimvar('E_opt',7,'Lower',0,'Upper',1);
S=@(E_opt)abs(E_i.exp(-j*k*x*sin(theta_in_rad)+j*k*y*cos(theta_in_rad))+E_r.*exp(-j*k_x*x-j*k_y*y)+E_opt(1).*exp(-j*k_x_n(1)*x-j*k_y_n(1)*yy)+E_opt(2).*exp(-j*k_x_n(2)*x-j*k_y_n(2)*y)+E_opt(3).*exp(-j*k_x_n(3)*xx-j*k_y_n(3)*y)+E_opt(4).*exp(-j*k_x_n(4)*x-j*k_y_n(4)*y)+E_opt(5).*exp(-j*k_x_n(5)*x-j*k_y_n(5)*y)+E_opt(6).*exp(-j*k_x_n(6)*xx-j*k_y_n(6)*y)+E_opt(7).*exp(-j*k_x_n(7)*x-j*k_y_n(7)*y).*conj((1/(-j*k*eta))(j*k*cos(theta_in_rad))*E_i.*exp(-j*k*x*sin(theta_in_rad)+j*k*yy*cos(theta_in_rad))+(-j*k_y)*E_r.*exp(-j*k_x*xx-j*k_y*y)+(-j*k_y_n(1))*E_opt(1).*exp(-j*k_x_n(1)*x-j*k_y_n(1)*y)+(-j*k_y_n(2))*E_opt(2).*exp(-j*k_x_n(1)*x-j*k_y_n(2)*y)+(-j*k_y_n(3))*E_opt(3).*exp(-j*k_x_n(3)*x-j*k_y_n(3)*y)+(-j*k_y_n(4))*E_opt(4).*exp(-j*k_x_n(4)*x-j*k_y_n(4)*y)+(-j*k_y_n(5))*E_opt(5).*exp(-j*k_x_n(5)*x-j*k_y_n(5)*y)+(-j*k_y_n(6))*E_opt(6).*exp(-j*k_x_n(6)*x-j*k_y_n(6)*y)+(-j*k_y_n(7))*E_opt(7).*exp(-j*k_x_n(7)*xx-j*k_y_n(7)*y)));
S_max=@(E_opt)max(abs(E_i.exp(-j*k*x*sin(theta_in_rad)+j*k*y*cos(theta_in_rad))+E_r.*exp(-j*k_x*x-j*k_y*y)+E_opt(1).*exp(-j*k_x_n(1)*x-j*k_y_n(1)*yy)+E_opt(2).*exp(-j*k_x_n(2)*x-j*k_y_n(2)*y)+E_opt(3).*exp(-j*k_x_n(3)*xx-j*k_y_n(3)*y)+E_opt(4).*exp(-j*k_x_n(4)*x-j*k_y_n(4)*y)+E_opt(5).*exp(-j*k_x_n(5)*x-j*k_y_n(5)*y)+E_opt(6).*exp(-j*k_x_n(6)*xx-j*k_y_n(6)*y)+E_opt(7).*exp(-j*k_x_n(7)*x-j*k_y_n(7)*y).*conj((1/(-j*k*eta))(j*k*cos(theta_in_rad))*E_i.*exp(-j*k*x*sin(theta_in_rad)+j*k*yy*cos(theta_in_rad))+(-j*k_y)*E_r.*exp(-j*k_x*xx-j*k_y*y)+(-j*k_y_n(1))*E_opt(1).*exp(-j*k_x_n(1)*x-j*k_y_n(1)*y)+(-j*k_y_n(2))*E_opt(2).*exp(-j*k_x_n(1)*x-j*k_y_n(2)*y)+(-j*k_y_n(3))*E_opt(3).*exp(-j*k_x_n(3)*x-j*k_y_n(3)*y)+(-j*k_y_n(4))*E_opt(4).*exp(-j*k_x_n(4)*x-j*k_y_n(4)*y)+(-j*k_y_n(5))*E_opt(5).*exp(-j*k_x_n(5)*x-j*k_y_n(5)*y)+(-j*k_y_n(6))*E_opt(6).*exp(-j*k_x_n(6)*x-j*k_y_n(6)*y)+(-j*k_y_n(7))*E_opt(7).*exp(-j*k_x_n(7)*xx-j*k_y_n(7)*y))));
S_min=@(E_opt)min(abs(E_i.exp(-j*k*x*sin(theta_in_rad)+j*k*y*cos(theta_in_rad))+E_r.*exp(-j*k_x*x-j*k_y*y)+E_opt(1).*exp(-j*k_x_n(1)*x-j*k_y_n(1)*yy)+E_opt(2).*exp(-j*k_x_n(2)*x-j*k_y_n(2)*y)+E_opt(3).*exp(-j*k_x_n(3)*xx-j*k_y_n(3)*y)+E_opt(4).*exp(-j*k_x_n(4)*x-j*k_y_n(4)*y)+E_opt(5).*exp(-j*k_x_n(5)*x-j*k_y_n(5)*y)+E_opt(6).*exp(-j*k_x_n(6)*xx-j*k_y_n(6)*y)+E_opt(7).*exp(-j*k_x_n(7)*x-j*k_y_n(7)*y).*conj((1/(-j*k*eta))(j*k*cos(theta_in_rad))*E_i.*exp(-j*k*x*sin(theta_in_rad)+j*k*yy*cos(theta_in_rad))+(-j*k_y)*E_r.*exp(-j*k_x*xx-j*k_y*y)+(-j*k_y_n(1))*E_opt(1).*exp(-j*k_x_n(1)*x-j*k_y_n(1)*y)+(-j*k_y_n(2))*E_opt(2).*exp(-j*k_x_n(1)*x-j*k_y_n(2)*y)+(-j*k_y_n(3))*E_opt(3).*exp(-j*k_x_n(3)*x-j*k_y_n(3)*y)+(-j*k_y_n(4))*E_opt(4).*exp(-j*k_x_n(4)*x-j*k_y_n(4)*y)+(-j*k_y_n(5))*E_opt(5).*exp(-j*k_x_n(5)*x-j*k_y_n(5)*y)+(-j*k_y_n(6))*E_opt(6).*exp(-j*k_x_n(6)*x-j*k_y_n(6)*y)+(-j*k_y_n(7))*E_opt(7).*exp(-j*k_x_n(7)*xx-j*k_y_n(7)*y))));
cam=fcn2optimexpr( S,E_opt);
camMax=fcn2optimexpr( S_max,E_opt);
camMin=fcn2optimexpr( S_min,E_opt);
prob = optimproblem("Objective",cam);
prob.Constraints.camUpper=camMax<=0.5;
prob.Constraints.camLower=camMin>=0;
[sol,fval] = solve(prob);
sol.E_opt
fval
--- Updated ---
Hello, i forgot that the coefficents of the evanecant waves are complex.
updated code shown bellow.
But still the GA algorithms gives me a bug when i try to run it.
Is there some wat to make the optimization work?
Infeasible individuals are present in the final population.
Optimization terminated: average change in the spread of Pareto solutions less than options.FunctionTolerance.
Constraints are not satisfied within constraint tolerance.
Error using optim.problemdef.OptimizationProblem/solve
Unable to perform assignment because the size of the left side is 1-by-100 and the size of the right side
is 10-by-10.
Error in optim2 (line 46)
[sol,fval] = solve(prob);
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
:
Code:
clc
clear all
f=6;
lambda=300/6;
theta_in_rad=(0/180)*pi;
theta_out_rad=(70/180)*pi;
x=linspace(-0.5*lambda,0.5*lambda,10);
y=0*linspace(-0.5*lambda,0.5*lambda,10);
[xx,yy]=meshgrid(x,y);
k=2*pi/lambda;
E_i=1;
E_r=E_i*sqrt(cos(theta_in_rad)/cos(theta_out_rad));
eta=377;
D_x=1.064*lambda;
k_x=k*sin(theta_in_rad)+2*pi/D_x;
k_y=sqrt(k^2-k_x.^2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n=[2,3,4,5,6,7,8];
k_x_n=k*sin(theta_in_rad)+(2*pi.*n)/D_x;
k_y_n=sqrt(k^2-k_x_n.^2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%E_t=E_i.*exp(-j*k*xx*sin(theta_in_rad)+j*k*yy*cos(theta_in_rad))+E_r.*exp(-j*k_x*xx-j*k_y*yy);%E_z
%E_t=E_i.*exp(-j*k*xx*sin(theta_in_rad)+j*k*yy*cos(theta_in_rad));%E_z
%E_t=E_i.*exp(-j*k*xx*sin(theta_in_rad)+j*k*yy*cos(theta_in_rad))+E_r.*exp(-j*k_x*xx-j*k_y*yy)
%E_t_evanesent=E_opt(1).*exp(-j*k_x_n(1)*xx-j*k_y_n(1)*yy)+E_opt(2).*exp(-j*k_x_n(2)*xx-j*k_y_n(2)*yy)+...
%E_t=E_i.*exp(-j*k*xx*sin(theta_in_rad)+j*k*yy*cos(theta_in_rad))+E_r.*exp(-j*k_x*xx-j*k_y*yy)+E_t_evanesent;
%E_t_ev=E_i.*exp(-j*k*xx*sin(theta_in_rad)+j*k*yy*cos(theta_in_rad))+E_r.*exp(-j*k_x*xx-j*k_y*yy)+E_opt(1).*exp(-j*k_x_n(1)*xx-j*k_y_n(1)*yy)+E_opt(2).*exp(-j*k_x_n(2)*xx-j*k_y_n(2)*yy)+E_opt(3).*exp(-j*k_x_n(3)*xx-j*k_y_n(3)*yy)+E_opt(4).*exp(-j*k_x_n(4)*xx-j*k_y_n(4)*yy)+E_opt(5).*exp(-j*k_x_n(5)*xx-j*k_y_n(5)*yy)+E_opt(6).*exp(-j*k_x_n(6)*xx-j*k_y_n(6)*yy)+E_opt(7).*exp(-j*k_x_n(7)*xx-j*k_y_n(7)*yy);
%H_t_ev=(j*k*cos(theta_in_rad))*E_i.*exp(-j*k*xx*sin(theta_in_rad)+j*k*yy*cos(theta_in_rad))+(-j*k_y)*E_r.*exp(-j*k_x*xx-j*k_y*yy)+(-j*k_y_n(1))*E_opt(1).*exp(-j*k_x_n(1)*xx-j*k_y_n(1)*yy)+(-j*k_y_n(2))*E_opt(2).*exp(-j*k_x_n(1)*xx-j*k_y_n(2)*yy)+(-j*k_y_n(3))*E_opt(3).*exp(-j*k_x_n(3)*xx-j*k_y_n(3)*yy)+(-j*k_y_n(4))*E_opt(4).*exp(-j*k_x_n(4)*xx-j*k_y_n(4)*yy)+(-j*k_y_n(5))*E_opt(5).*exp(-j*k_x_n(5)*xx-j*k_y_n(5)*yy)+(-j*k_y_n(6))*E_opt(6).*exp(-j*k_x_n(6)*xx-j*k_y_n(6)*yy)+(-j*k_y_n(7))*E_opt(7).*exp(-j*k_x_n(7)*xx-j*k_y_n(7)*yy);
E_opt_amp = optimvar('E_opt_amp',7,'Lower',0,'Upper',1);
E_opt_ph = optimvar('E_opt_ph',7,'Lower',0,'Upper',360);
S_max=@(E_opt_amp,E_opt_ph)max(abs(E_i.exp(-j*k*x*sin(theta_in_rad)+j*k*y*cos(theta_in_rad))+E_r.*exp(-j*k_x*x-j*k_y*y)+E_opt_amp(1)*exp(j(E_opt_ph(1)/180)pi).*exp(-j*k_x_n(1)*x-j*k_y_n(1)*yy)+E_opt_amp(2)*exp(j(E_opt_ph(2)/180)pi).*exp(-j*k_x_n(2)*x-j*k_y_n(2)*y)+E_opt_amp(3)*exp(j(E_opt_ph(3)/180)pi).*exp(-j*k_x_n(3)*xx-j*k_y_n(3)*y)+E_opt_amp(4)*exp(j(E_opt_ph(4)/180)pi).*exp(-j*k_x_n(4)*x-j*k_y_n(4)*y)+E_opt_amp(5)*exp(j(E_opt_ph(5)/180)pi).*exp(-j*k_x_n(5)*x-j*k_y_n(5)*y)+E_opt_amp(6)*exp(j(E_opt_ph(6)/180)pi).*exp(-j*k_x_n(6)*xx-j*k_y_n(6)*y)+E_opt_amp(7)*exp(j(E_opt_ph(7)/180)pi).*exp(-j*k_x_n(7)*x-j*k_y_n(7)*y).*conj((1/(-j*k*eta))(j*k*cos(theta_in_rad))E_i.*exp(-j*k*x*sin(theta_in_rad)+j*k*yy*cos(theta_in_rad))+(-j*k_y)*E_r.*exp(-j*k_x*xx-j*k_y*y)+(-j*k_y_n(1))*E_opt_amp(1)*exp(j(E_opt_ph(1)/180)pi).*exp(-j*k_x_n(1)*x-j*k_y_n(1)*y)+(-j*k_y_n(2))*E_opt_amp(2)*exp(j(E_opt_ph(2)/180)pi).*exp(-j*k_x_n(1)*x-j*k_y_n(2)*y)+(-j*k_y_n(3))*E_opt_amp(3)*exp(j(E_opt_ph(3)/180)pi).*exp(-j*k_x_n(3)*x-j*k_y_n(3)*y)+(-j*k_y_n(4))*E_opt_amp(4)*exp(j(E_opt_ph(4)/180)pi).*exp(-j*k_x_n(4)*x-j*k_y_n(4)*y)+(-j*k_y_n(5))*E_opt_amp(5)*exp(j(E_opt_ph(5)/180)pi).*exp(-j*k_x_n(5)*x-j*k_y_n(5)*y)+(-j*k_y_n(6))*E_opt_amp(6)*exp(j(E_opt_ph(6)/180)pi).*exp(-j*k_x_n(6)*x-j*k_y_n(6)*y)+(-j*k_y_n(7))*E_opt_amp(7)*exp(j(E_opt_ph(7)/180)*pi).*exp(-j*k_x_n(7)*xx-j*k_y_n(7)*y))));
S_min=@(E_opt_amp,E_opt_ph)min(abs(E_i.exp(-j*k*x*sin(theta_in_rad)+j*k*y*cos(theta_in_rad))+E_r.*exp(-j*k_x*x-j*k_y*y)+E_opt_amp(1)*exp(j(E_opt_ph(1)/180)pi).*exp(-j*k_x_n(1)*x-j*k_y_n(1)*yy)+E_opt_amp(2)*exp(j(E_opt_ph(2)/180)pi).*exp(-j*k_x_n(2)*x-j*k_y_n(2)*y)+E_opt_amp(3)*exp(j(E_opt_ph(3)/180)pi).*exp(-j*k_x_n(3)*xx-j*k_y_n(3)*y)+E_opt_amp(4)*exp(j(E_opt_ph(4)/180)pi).*exp(-j*k_x_n(4)*x-j*k_y_n(4)*y)+E_opt_amp(5)*exp(j(E_opt_ph(5)/180)pi).*exp(-j*k_x_n(5)*x-j*k_y_n(5)*y)+E_opt_amp(6)*exp(j(E_opt_ph(6)/180)pi).*exp(-j*k_x_n(6)*xx-j*k_y_n(6)*y)+E_opt_amp(7)*exp(j(E_opt_ph(7)/180)pi).*exp(-j*k_x_n(7)*x-j*k_y_n(7)*y).*conj((1/(-j*k*eta))(j*k*cos(theta_in_rad))E_i.*exp(-j*k*x*sin(theta_in_rad)+j*k*yy*cos(theta_in_rad))+(-j*k_y)*E_r.*exp(-j*k_x*xx-j*k_y*y)+(-j*k_y_n(1))*E_opt_amp(1)*exp(j(E_opt_ph(1)/180)pi).*exp(-j*k_x_n(1)*x-j*k_y_n(1)*y)+(-j*k_y_n(2))*E_opt_amp(2)*exp(j(E_opt_ph(2)/180)pi).*exp(-j*k_x_n(1)*x-j*k_y_n(2)*y)+(-j*k_y_n(3))*E_opt_amp(3)*exp(j(E_opt_ph(3)/180)pi).*exp(-j*k_x_n(3)*x-j*k_y_n(3)*y)+(-j*k_y_n(4))*E_opt_amp(4)*exp(j(E_opt_ph(4)/180)pi).*exp(-j*k_x_n(4)*x-j*k_y_n(4)*y)+(-j*k_y_n(5))*E_opt_amp(5)*exp(j(E_opt_ph(5)/180)pi).*exp(-j*k_x_n(5)*x-j*k_y_n(5)*y)+(-j*k_y_n(6))*E_opt_amp(6)*exp(j(E_opt_ph(6)/180)pi).*exp(-j*k_x_n(6)*x-j*k_y_n(6)*y)+(-j*k_y_n(7))*E_opt_amp(7)*exp(j(E_opt_ph(7)/180)*pi).*exp(-j*k_x_n(7)*xx-j*k_y_n(7)*y))));
S=@(E_opt_amp,E_opt_ph)abs(E_i.exp(-j*k*x*sin(theta_in_rad)+j*k*y*cos(theta_in_rad))+E_r.*exp(-j*k_x*x-j*k_y*y)+E_opt_amp(1)*exp(j(E_opt_ph(1)/180)pi).*exp(-j*k_x_n(1)*x-j*k_y_n(1)*yy)+E_opt_amp(2)*exp(j(E_opt_ph(2)/180)pi).*exp(-j*k_x_n(2)*x-j*k_y_n(2)*y)+E_opt_amp(3)*exp(j(E_opt_ph(3)/180)pi).*exp(-j*k_x_n(3)*xx-j*k_y_n(3)*y)+E_opt_amp(4)*exp(j(E_opt_ph(4)/180)pi).*exp(-j*k_x_n(4)*x-j*k_y_n(4)*y)+E_opt_amp(5)*exp(j(E_opt_ph(5)/180)pi).*exp(-j*k_x_n(5)*x-j*k_y_n(5)*y)+E_opt_amp(6)*exp(j(E_opt_ph(6)/180)pi).*exp(-j*k_x_n(6)*xx-j*k_y_n(6)*y)+E_opt_amp(7)*exp(j(E_opt_ph(7)/180)pi).*exp(-j*k_x_n(7)*x-j*k_y_n(7)*y).*conj((1/(-j*k*eta))(j*k*cos(theta_in_rad))E_i.*exp(-j*k*x*sin(theta_in_rad)+j*k*yy*cos(theta_in_rad))+(-j*k_y)*E_r.*exp(-j*k_x*xx-j*k_y*y)+(-j*k_y_n(1))*E_opt_amp(1)*exp(j(E_opt_ph(1)/180)pi).*exp(-j*k_x_n(1)*x-j*k_y_n(1)*y)+(-j*k_y_n(2))*E_opt_amp(2)*exp(j(E_opt_ph(2)/180)pi).*exp(-j*k_x_n(1)*x-j*k_y_n(2)*y)+(-j*k_y_n(3))*E_opt_amp(3)*exp(j(E_opt_ph(3)/180)pi).*exp(-j*k_x_n(3)*x-j*k_y_n(3)*y)+(-j*k_y_n(4))*E_opt_amp(4)*exp(j(E_opt_ph(4)/180)pi).*exp(-j*k_x_n(4)*x-j*k_y_n(4)*y)+(-j*k_y_n(5))*E_opt_amp(5)*exp(j(E_opt_ph(5)/180)pi).*exp(-j*k_x_n(5)*x-j*k_y_n(5)*y)+(-j*k_y_n(6))*E_opt_amp(6)*exp(j(E_opt_ph(6)/180)pi).*exp(-j*k_x_n(6)*x-j*k_y_n(6)*y)+(-j*k_y_n(7))*E_opt_amp(7)*exp(j(E_opt_ph(7)/180)*pi).*exp(-j*k_x_n(7)*xx-j*k_y_n(7)*y)));
cam=fcn2optimexpr( S,E_opt_amp,E_opt_ph);
camMax=fcn2optimexpr( S_max,E_opt_amp,E_opt_ph);
camMin=fcn2optimexpr( S_min,E_opt_amp,E_opt_ph);
prob = optimproblem("Objective",cam);
prob.Constraints.camUpper=camMax<=0.5;
prob.Constraints.camLower=camMin>=0;
[sol,fval] = solve(prob);
sol.E_opt_amp
fval
Attachments
Last edited: