solving a symbolic equation in a for loop and store them
Show older comments
I have been trying to solve a symbolic equation in a for loop and then store the data in matrix form. I've attached my code and error txt below;
c = 2.99792458e+08;
mu_0=4*pi*1e-7;
eps_0 = 8.8541878176e-12;
n_1 = 1.5;
% n_2 = 1.5;
% n_3 = 1.5;
thetad=30;
phid = 0;
nu_bar_0_cm=1000;
% nu_bar_0_cm = 1000;
nu_bar_0 = nu_bar_0_cm * 1e2;
lambda_0 = 1/nu_bar_0;
%%%%%%% dielectric tensor epsilon using eq(1)%%%%%%%%%%%%
% eps_2 = ((n_2)^2)*eps_0*eye(3);
% eps_3 = ((n_3)^2)*eps_0*eye(3);
nu = c/lambda_0;
lambda_1 = lambda_0/n_1;
Al = 2*pi*sind(thetad)*cosd(phid)/lambda_1;%alpha
Bt = 2*pi* sind(thetad) * sind(phid)/lambda_1; % beta
w=2*pi*nu;
eps_1 = (n_1)^2*eps_0*eye(3);
e_delta=1:20;
eps_33=eps_1(3,3);
len_Edelta=length(e_delta);
gamma = sym('gamma');
x11 = (w^2)*mu_0*eps_1(1,1)-(Bt^2)-(gamma^2);
x12 = (w^2)*mu_0*eps_1(1,2)+Al*Bt;
x13 = (w^2)*mu_0*eps_1(1,3)+Al*gamma;
x21 = (w^2)*mu_0*eps_1(2,1)+Al*Bt;
x22 = (w^2)*mu_0*eps_1(2,2)-(Al^2)-(gamma^2);
x23 = (w^2)*mu_0*eps_1(2,3)+Bt*gamma;
x31 = (w^2)*mu_0*eps_1(3,1)+Al*gamma;
x32 = (w^2)*mu_0*eps_1(3,2)+Bt*gamma;
% epsilon1=zeros(3,60);
% lendel=3*len_Edelta;
g1_store=zeros(4,len_Edelta);
p_store = zeroes(3,len_Edelta);
for ii=1:len_Edelta
new_eps33 = eps_33+eps_0*10^(-e_delta(ii));
eps_1(3,3) = new_eps33;
x33= w^2*mu_0*eps_1(3,3)-Bt^2-Al^2;
M = [x11 x12 x13; x21 x22 x23; x31 x32 x33];
detM = det(M(:,:));
DetM(ii)=detM;
% eqn = DetM(ii)==0;
gg= solve(DetM(ii),gamma);
gamma=gg;
g1(:,:) = double(gamma);
g1_store(:,ii) = g1(:);
p_x = (w.^2.*mu_0.*(eps_1(2,2))-Al.^2-(g1(1,1)).^2).*(w.^2.*mu_0.*eps_1(3,3)-Al.^2-Bt.^2)-(w.^2.*mu_0.*(eps_1(2,3))+Bt.*g1(1,1)).^2 ;
p_y = (w.^2.*mu_0.*eps_1(2,3)+Bt.*g1(1,1)).*(w.^2.*mu_0.*eps_1(3,1)+Al.*g1(1,1))-(w.^2.*mu_0.*eps_1(1,2)+Al.*Bt).*(w.^2.*mu_0.*(eps_1(3,3)+eps_0*1e-1)-Al.^2-Bt.^2);
p_z = (w.^2.*mu_0.*eps_1(1,2)+Al.*Bt).*(w.^2.*mu_0.*eps_1(2,3)+Bt.*g1(1,1))-(w.^2.*mu_0.*eps_1(1,3)+Al.*g1(1,1)).*(w.^2.*mu_0.*eps_1(2,2)-Al.^2-(g1(1,1)).^2);
p_store(:,ii) = [p_x; p_y; p_z];
end
and the error,
>> delta
Error using sym.getEqnsVars>checkVariables (line 87)
Second argument must be a vector of symbolic variables.
Error in sym.getEqnsVars (line 54)
checkVariables(vars);
Error in solve>getEqns (line 429)
[eqns, vars] = sym.getEqnsVars(argv{:});
Error in solve (line 226)
[eqns,vars,options] = getEqns(varargin{:});
Error in delta (line 62)
gg= solve(DetM(ii),gamma);
I would really appreciate any help. have been working on this for days now. Thanks in advance.
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!