How to plot transcendental equation?

12 views (last 30 days)
I want to plot neff vs lambda graph following a analytical expression. But when I run my code it doesnot show me any error but also no graphical image is shown.Here I want to calculate the values of neff by varying the lambda following the expression given below.
My code is given below:
clc
clear all
close all
nf= 1.3;
ns=1.5;
nc=1;
rho=1;
hf=1.5;
lambda = 100:1:350;
m=1;
syms func(lambda,neff)
phi_c = - atand((nf/nc)^(2*rho)*sqrt ((neff^2-nc^2)/(nf^2-neff^2)));
phi_s = -atand((nf/ns)^(2*rho)*sqrt ((neff^2-ns^2)/(nf^2-neff^2)));
func(lambda,neff) = @(lambda,neff)(((2*pi/lambda)*(sqrt(nf^2-neff^2)*hf))+ phi_c + phi_s -(m*pi))==0;
ezplot(func)
Myouput is
How can I resolve the Problem? Kindly help.
  1 Comment
Paul
Paul on 5 Nov 2021
Are you sure that phi_c/s should be using atand() and not atan() ?
Are there any values of neff for which phi_c and phi_s are both real? It looks like phi_c is real for nc < abs(neff) < nf (1 < abs(neff) < 1.3) but those values of neff result in neff^2 - ns^2 < 0.

Sign in to comment.

Accepted Answer

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 5 Nov 2021
Here is how it can be solved and plotted:
clc
clearvars
close all
nf= 1.3;
ns=1.5;
nc=1;
rho=1;
hf=1.5;
lambda = 100:350;
m=1;
syms neff
phi_c = - atand((nf/nc)^(2*rho)*sqrt ((neff^2-nc^2)/(nf^2-neff^2)));
phi_s = -atand((nf/ns)^(2*rho)*sqrt ((neff^2-ns^2)/(nf^2-neff^2)));
NEFF = zeros(size(lambda));
for ii=1:numel(lambda)
Eqn = (((2*pi./lambda(ii))*(sqrt(nf^2-neff^2)*hf))+ phi_c + phi_s -(m*pi))==0;
NEFF(ii)=double(vpasolve(Eqn));
end
%%
plot(lambda, real(NEFF), 'r-o', 'DisplayName', 'neff: real part'), hold on
plot(lambda, imag(NEFF), 'b-d', 'DisplayName', 'neff: imag part'), hold on
legend; grid on
  5 Comments
Sulaymon Eshkabilov
Sulaymon Eshkabilov on 7 Nov 2021
Note that you're calling a different variable name NEFF1(ii)=double(vpasolve(Eqn)). That should be NEFF(ii)=double(vpasolve(Eqn))
The code does not have any problem with nf=2 and runs ok. It produces solutions correctly.
Vaswati Biswas
Vaswati Biswas on 7 Nov 2021
I am sorry sir but even if I am calling NEFF(ii)=double(vpasolve(Eqn)) still the same error is coming when I put nf = 2. I feel as tan inverse is involved in the equation therefore it is not taking all the values. I even tried to run the code by putting -pi +0.0001 still I am getting the same error.
"Unable to perform assignment because the left and right sides have a different number of elements."
Error in (line 17)
NEFF(ii)=double(vpasolve(Eqn));

Sign in to comment.

More Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 7 Nov 2021
clc
clearvars
close all
nf= 1.3;
ns=1.5;
nc=1;
rho=1;
hf=2;
lambda = 100:350;
m=1;
syms neff
phi_c = - atand((nf/nc)^(2*rho)*sqrt ((neff^2-nc^2)/(nf^2-neff^2)));
phi_s = -atand((nf/ns)^(2*rho)*sqrt ((neff^2-ns^2)/(nf^2-neff^2)));
NEFF = zeros(size(lambda));
for ii=1:numel(lambda)
Eqn = (((2*pi./lambda(ii))*(sqrt(nf^2-neff^2)*hf))+ phi_c + phi_s -(m*pi))==0;
NEFF(ii)=double(vpasolve(Eqn));
end
%%
plot(lambda, real(NEFF), 'r-o', 'DisplayName', 'neff: real part'), hold on
plot(lambda, imag(NEFF), 'b-d', 'DisplayName', 'neff: imag part'), hold on
legend; grid on
  2 Comments
Sulaymon Eshkabilov
Sulaymon Eshkabilov on 7 Nov 2021
You are doing something wrong while typing the script contents
Vaswati Biswas
Vaswati Biswas on 7 Nov 2021
Sir I was talking about 'nf' that is involved in tan inverse equation. hf isn't involved in that equation.

Sign in to comment.

Categories

Find more on Dialog Boxes 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!