how to use conditional ezplot ?
Mostra commenti meno recenti
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
Risposte (1)
Walter Roberson
il 30 Mag 2016
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 Commenti
Ritesh Chaurasia
il 31 Mag 2016
Walter Roberson
il 31 Mag 2016
Modificato: Walter Roberson
il 31 Mag 2016
That cannot be done. ezplot requires that the function value be defined for all pairs of values in the ranges you give. The defined value can be 0 or one of the infinities or nan, but it has to be some value. You are attempting to have the value not even be defined outside of a range.
Ritesh Chaurasia
il 31 Mag 2016
Walter Roberson
il 31 Mag 2016
No, as long as you use ezplot() you need to use a function that has some value for all values in the x and y range.
Your code was not vectorized; I did that for you.
Your code used xxxxs but did not define it. In the below, I guessed that it might be the same as xxxs. You should adjust that at need.
In the below, the Ricond function uses a little bit of a trick to force NaN or inf to be assigned in places that are out of bounds. The code does that by dividing by the result of the logical test. The logical test is 1 when the location is in-bounds, which does not change the answer. The logical test is 0 when the location is out of bounds, which causes a division by 0, which gives +inf or -inf or nan, none of which will be plotted.
ezplot does not sample the grid finely enough to see any results, so I switched to surf.
If you increase the refine past about 150, you will see a spike up to about 10000 that washes out everything else. If you rotate the surface you can see that there are a bunch of spikes; there is a pattern to them.
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));
xxxxs = xxxs; %GUESS
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)))));
Ricond = @(K, W) Ritesh(K,W) ./ (xxxs(K,W) < 1);
refine = 75;
K_ = linspace(0.0*10^6/k0, 31.4*10^6/k0, refine);
W_ = linspace(0, 1, refine);
[KK, WW] = ndgrid(K_, W_);
Zric = Ricond(KK, WW);
surf(KK,WW,real(ZRic), 'edgecolor','none');
The imaginary part is small and probably mostly numeric round off. But right along W = 0 it might not be negligible.
Ritesh Chaurasia
il 7 Giu 2016
Modificato: Walter Roberson
il 7 Giu 2016
Walter Roberson
il 7 Giu 2016
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.
Categorie
Scopri di più su Image Arithmetic in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!