How to plot transcendental equation?
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
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.
Akzeptierte Antwort
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
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.
Weitere Antworten (1)
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
Siehe auch
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!