How to get rid of the Error in Transcendental equation ?

2 ビュー (過去 30 日間)
Vaswati Biswas
Vaswati Biswas 2021 年 11 月 5 日
回答済み: Star Strider 2021 年 11 月 5 日
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
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
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.)
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
Eqn = 
No solution found. fsolve stopped because the relative size of the current step is less than the value of the step size tolerance squared, but the vector of function values is not near zero as measured by the value of the function tolerance.
NEFF1_Numeric = 7.9015
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
plot(lambda, NEFF)
hold on;
plot(lambda , S)
.

その他の回答 (1 件)

Jan
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).

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by