How to plot transcendental equation?

조회 수: 10 (최근 30일)
Vaswati Biswas
Vaswati Biswas 2021년 11월 5일
댓글: Vaswati Biswas 2021년 11월 7일
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
Paul
Paul 2021년 11월 5일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 11월 5일
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
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 11월 7일
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 2021년 11월 7일
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));

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by