How to get rid of the Error in Transcendental equation ?
2 次查看(过去 30 天)
显示 更早的评论
Can anyone help to solve this problem . The error I am getting is : "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.Error in (line 17) :NEFF1(ii)=double(vpasolve(Eqn));" My code is given below:
clc
clearvars
close all
nf=1.84;
ns=1.48;
nc=1.3;
rho=1;
lambda=950:10:1850;
hf = 120;
m= 0;
syms neff
NEFF = zeros(size(lambda));
for ii=1:numel(lambda)
phi_c = -atan((nf/nc)^(2*rho)*sqrt ((neff^2-nc^2)/(nf^2-neff^2)));
phi_s = -atan((nf/ns)^(2*rho)*sqrt ((neff^2-ns^2)/(nf^2-neff^2)));
Eqn = (((2*pi./lambda(ii))*(sqrt(nf^2-neff^2)*hf))+phi_c+ phi_s -(m*pi))==0;% equation 8 from paper
NEFF1(ii)=double(vpasolve(Eqn));
NEFF(ii)= abs(NEFF1(ii));
deltaz_c(ii) = (lambda(ii)./2*pi).*(NEFF(ii)^2-nc^2).^(-0.5).*((NEFF(ii)./nf).^2+(NEFF(ii)./(nc.^2)-1)).^(-rho);%equation 6 from paper
deltaz_s(ii) = (lambda(ii)./2*pi).*(NEFF(ii)^2-ns^2).^(-0.5).*((NEFF(ii)./nf).^2+(NEFF(ii)./(ns.^2)-1)).^(-rho);
heff(ii) = deltaz_c( ii)+ deltaz_s(ii) + hf; %equation 5 from paper
P_c(ii)= ((nf.^2-NEFF(ii).^2)./(nf^2-nc^2)).*(deltaz_c(ii)./heff(ii)); %equation 4 from paper
S(ii)= (NEFF(ii)./nc).* P_c(ii).*((2*(NEFF(ii)./nc).^2)-1).^rho;%equation 7 from paper
end
plot(lambda, NEFF)
hold on;
plot(lambda , S)
Help me to solve this
1 个评论
Jan
2021-11-5
Note: This is not twitter, so we do not use # before the tags. All questions concern "matlab", so I've removed this hint.
采纳的回答
Star Strider
2021-11-5
The problem is that ‘Eqn’ has no solution. The symbolic result is an empty vector, and that is throwing the error. The fsolve function just gives up aftar a while and returns the minimum, since ‘Eqn’ has no apparent root. (If ‘Eqn’ had a solution, it would have two values since it is a function of
and the single indexing would throw the same error, although for a different reason.)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/791199/image.png)
nf=1.84;
ns=1.48;
nc=1.3;
rho=1;
lambda=950:10:1850;
hf = 120;
m= 0;
syms neff
NEFF = zeros(size(lambda));
for ii=1:numel(lambda)
phi_c = -atan((nf/nc)^(2*rho)*sqrt ((neff^2-nc^2)/(nf^2-neff^2)));
phi_s = -atan((nf/ns)^(2*rho)*sqrt ((neff^2-ns^2)/(nf^2-neff^2)));
Eqn = (((2*pi./lambda(ii))*(sqrt(nf^2-neff^2)*hf))+phi_c+ phi_s -(m*pi)) % equation 8 from paper
NEFF1_Numeric = fsolve(matlabFunction(Eqn),rand*10)
NEFF1(ii)=double(vpasolve(Eqn))
NEFF{ii}= abs(NEFF1{ii})
deltaz_c{ii} = (lambda(ii)./2*pi).*(NEFF(ii)^2-nc^2).^(-0.5).*((NEFF(ii)./nf).^2+(NEFF(ii)./(nc.^2)-1)).^(-rho);%equation 6 from paper
deltaz_s{ii} = (lambda(ii)./2*pi).*(NEFF(ii)^2-ns^2).^(-0.5).*((NEFF(ii)./nf).^2+(NEFF(ii)./(ns.^2)-1)).^(-rho);
heff{ii} = deltaz_c( ii)+ deltaz_s(ii) + hf; %equation 5 from paper
P_c{ii}= ((nf.^2-NEFF(ii).^2)./(nf^2-nc^2)).*(deltaz_c(ii)./heff(ii)); %equation 4 from paper
S{ii}= (NEFF(ii)./nc).* P_c(ii).*((2*(NEFF(ii)./nc).^2)-1).^rho;%equation 7 from paper
end
plot(lambda, NEFF)
hold on;
plot(lambda , S)
.
0 个评论
更多回答(1 个)
Jan
2021-11-5
Use the debugger to find out, what's going on:
dbstop if error
Matlab will stop in this line:
NEFF1(ii)=double(vpasolve(Eqn));
Now check the output of the right side:
double(vpasolve(Eqn))
It is empty. There is no solution for the equation. Thefore you cannot assign it to the scalar NEFF1(ii).
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!