I ran this code on MatLab:
function main
fimplicit (@(x,y)f(x,y),[2 5])
end
function fun = f(x,y)
nc=1.45; %cladding
nf=1.5;
ns=1.4; %substrate
h=5; %width of waveguide
kappa=sqrt(x^2*nf^2-y.^2);
gammas=sqrt(y^2-x^2*ns^2);
gammac=sqrt(y^2-x^2*nc^2);
z=sin(h.*kappa);
%TE mode
fun=z.*(kappa.^2-gammas.*gammac)-cos(h.*kappa).*(gammac+gammas).*kappa;
endUpon zooming in near (2.5,3.5):
Zooming out and then zooming in at same spot
Now how do I know which of these three is correct and is there any way to get rid of such erroneous plots?
Similarly in Desmos
1 Answer
Matlab fimplicit is an excellent function to have an idea of a how a function given implicit in terms of its variables behave. However, if your function is not "good", it may hide or reveal some details, depending on the range you are plotting. Following the Matlab documentation,
Tips
- When you zoom in on the chart, fimplicit recalculates the data, which can reveal hidden details.
Matlab function will numerically evaluate the function in order to find the pairs (x,y) to plot, and will automatically choose a few points, so small details may disappear when the axis limits are too big (small number of points to plot the curves). You can try to increase the MeshDensity property, to add more points to your curves to check which one is correct:
fimplicit(f,'MeshDensity',500) % 151 is the default. Increase this number to add more evaluation points per direction