필터 지우기
필터 지우기

how to use conditional ezplot ?

조회 수: 1 (최근 30일)
Ritesh Chaurasia
Ritesh Chaurasia 2016년 5월 30일
댓글: Walter Roberson 2016년 6월 7일
m=0;
nc=1.0;
na=2.0;
nb=1.0;
n=2;
lambda0=1.50e-6;
k0=2*pi/lambda0;
rc=5/k0;
a=1/k0; %0.211e-6;
b=1/k0; %0.305e-6;
%omega=rc core radius%
%W=beta/k;
%K=k/k0;
kc=@(K,W)k0*K*sqrt((nc)^2-(W)^2);
ka=@(K,W)k0*K*sqrt((na)^2-(W)^2);
kb=@(K,W)k0*K*sqrt((nb)^2-(W)^2);
t=@(K,W)(kc(K,W)*rc);
%For TE
xs=@(K,W)(cos(kb(K,W)*b)-(i/2)*((kb(K,W)/ka(K,W))+(ka(K,W)/kb(K,W)))*sin(kb(K,W)*b))*exp(-i*ka(K,W)*a);
ys=@(K,W)((i/2)*((kb(K,W)/ka(K,W))-(ka(K,W)/kb(K,W)))*sin(kb(K,W)*b))*exp(i*ka(K,W)*a);
xxs=@(K,W)real(xs(K,W));
xxxs=@(K,W)abs(xxs(K,W));
if xxxs<1;
Ritesh=@(K,W)(((-besselj(m+1,t(K,W))+(m/t(K,W))*besselj(m,t(K,W)))/besselj(m,t(K,W)))+((kc(K,W)*(((xxxxs(K,W))+sqrt((xxxxs(K,W))^2-1))^(n-1)-xs(K,W)-ys(K,W)))/(i*ka(K,W)*(((xxxxs(K,W))+sqrt((xxxxs(K,W))^2-1))^(n-1)-xs(K,W)+ys(K,W)))));
h1 = ezplot(Ritesh,[0.0*10^6/k0 31.4*10^6/k0 0 1]);
%h1 = ezplot(Ritesh,[0.0*10^6/k0 31.4*10^6/k0 0.008032 0.98394]);
set(h1,'Color','black','LineWidth',2);
else
end

답변 (1개)

Walter Roberson
Walter Roberson 2016년 5월 30일
Your xxxs is a function handle to a function that requires two arguments, but you are trying to use
if xxxs<1
which tests the function handle itself instead of applying the function handle to any arguments.
Are you trying to program it so that the formula in Ritesh applies in some parts of the ezplot but not in others? If so then what value should apply in the other parts? It is not possible to have ezplot apply only to some places -- but it is possible to create formula whose value is NaN in some places and meaningful values in others.
  댓글 수: 6
Ritesh Chaurasia
Ritesh Chaurasia 2016년 6월 7일
편집: Walter Roberson 2016년 6월 7일
I am thankful, You did effort for me. I have used your redeveloped mat programme... But i faced problem in using conditional statement with surfplot also as in ezplot.
Kindly, I request you first understand my problem and give me solution accordingly.the new program-me is fallowing-
%%%%%%%%%%%%%%%%%%%%%%%%
close all
clear all
clc
m = 0;
nc = 1.0;
na = 2.0;
nb = 1.0;
n = 2;
lambda0 = 1.50e-6;
k0 = 2.*pi./lambda0;
rc = 1./k0;
a = 1./k0; %0.211e-6;
b = 1./k0; %0.305e-6;
%omega=rc core radius%
%W = beta./k;
%K = k./k0;
refine = 375;
K = linspace(0.0*10^6/k0, 41.4*10^6/k0, refine);
W = linspace(0, 1, refine);
kc = @(K,W) k0.*K.*sqrt((nc).^2-(W).^2);
ka = @(K,W) k0.*K.*sqrt((na).^2-(W).^2);
kb = @(K,W) k0.*K.*sqrt((nb).^2-(W).^2);
t = @(K,W) (kc(K,W).*rc);
%For TE
xs = @(K,W) (cos(kb(K,W).*b)-(i/2).*((kb(K,W)./ka(K,W))+(ka(K,W)./kb(K,W))).*sin(kb(K,W).*b)).*exp(-i.*ka(K,W).*a);
ys = @(K,W) ((i/2).*((kb(K,W)./ka(K,W))-(ka(K,W)./kb(K,W))).*sin(kb(K,W).*b)).*exp(i.*ka(K,W).*a);
xxs = @(K,W) real(xs(K,W));
xxxs = @(K,W) abs(xxs(K,W));
xxxxs= xxxs(K,W);
if xxxxs < 1
xxxxs1=xxxxs;
Ritesh = @(K,W) (((-besselj(m+1,t(K,W))+(m./t(K,W)).*besselj(m,t(K,W)))./besselj(m,t(K,W)))+((kc(K,W).*(((xxxxs1(K,W))+sqrt((xxxxs1(K,W)).^2-1)).^(n-1)-xs(K,W)-ys(K,W)))./(i.*ka(K,W).*(((xxxxs1(K,W))+sqrt((xxxxs1(K,W)).^2-1)).^(n-1)-xs(K,W)+ys(K,W)))));
Ricond = @(K, W) Ritesh(K,W) ./ 1; %xxxs(K,W) <1; %< 1;
[KK, WW] = ndgrid(K, W);
Zric = Ricond(KK, WW)
surf(KK,WW,real(Zric), 'edgecolor','none');
else
end
%%%%%%%%%%%%%%%%%%%%%%%%
in this programme we have to calculate function ritesh for condition xxxxs<1 for which xxxxs1=xxxxs which is the part of the function ritesh. here xxxxs is the row matrix array which has the element equal to the refine value. we have to accept those value of xxxxs which has less then 1 and then compute "ritesh" and then plot the solution with KK and WW.
Walter Roberson
Walter Roberson 2016년 6월 7일
It is not possible to do what you want to do.
surf() needs as input a 2D matrix of X values, a 2D matrix of Y values, and a 2D matrix of Z values. Every element of those must exist -- MATLAB does not permit "ragged" arrays or arrays with holes.
Your code inherently requires arrays with holes in it, because you refuse to define a value for the positions where xxxs(K,W) >= 1.
The code I built (and tested) for you defines some value for every grid position. It takes the short-cut of evaluating the main function at every location on the grid (not just where xxxs(K,W) < 1), but then taking care that every location where xxxs(K,W) < 1 is false gets given a value that is either -inf, +inf, or nan. surf() will silently not draw anything at positions where the Z is -inf, +inf, or nan (it is a design feature of surf, not a bug.)
If you want to get any further, you will need to adopt a similar strategy: for every K, W pair, you must have some output, even if the value is nan or inf. This does not inherently require that you compute at every location and then invalidate some of them (like I do), but if you choose to compute at only some locations then you need to assign the outputs of those locations into appropriate places in a larger grid to surf() after everything is complete. If you do want to compute at only some locations then you should read about logical indexing.

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

카테고리

Help CenterFile Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by