How to plot transcendental equation?

10 Ansichten (letzte 30 Tage)
Vaswati Biswas
Vaswati Biswas am 5 Nov. 2021
Kommentiert: Vaswati Biswas am 7 Nov. 2021
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 Kommentar
Paul
Paul am 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 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 Kommentare
Sulaymon Eshkabilov
Sulaymon Eshkabilov am 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 am 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));

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 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 Kommentare
Sulaymon Eshkabilov
Sulaymon Eshkabilov am 7 Nov. 2021
You are doing something wrong while typing the script contents
Vaswati Biswas
Vaswati Biswas am 7 Nov. 2021
Sir I was talking about 'nf' that is involved in tan inverse equation. hf isn't involved in that equation.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Dialog Boxes finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by