I have 2D-surface functions z(x,y) that I want to sample efficiently. Does matlab include any such addaptive mesh-refinement functions and, if so, how to use it?
Backgrund: I want to find sample points on my functions, so that I later can intepolate (using e.g. linear 'scatteredInterpolant') between those sampled points and by this effectively recover my "full" surface function. I will probably need around 1e6 sample points on each surface -- in order to precisely enough capture the full shape of my 2D surfaces z(x,y) -- but still these points must be mainly concentrated in those regions where z have peaks or edges.
Let me give a simple example (my functions typically also have narrow edges, and higher peaks):
z = @(x,y) 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2)- 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) - 1/3*exp(-(x+1).^2 - y.^2);
Now, I want to adaptaively sample x, y points such that it allows to capture the full behaviour of z.
The only function I could find that does something like this was 'fsurf':
h = fsurf(z, [-5 5 -5 5],'MeshDensity',10,'Visible','off');
I can then access fsurf's sampled points via:
x=h.XData; y=h.YData; z = h.ZData;
However, I want to control the adaptive refinments. fsurf gives no such options (excpet the initial MeshDensity). I accidentally noticed that I can also set a parameter called h.AdaptiveMeshDensity to larger values (e.g. to 9) after fsurf is executed (if I keep fplot's 'empty' window open!). This setting seems to allow to futher refine the sampling in the most relevant regions. Let me illustrate it by this code:
So I do obtain sampling points adaptively in this way, but:
- I can not find any documentation about the setting`AdaptiveMeshDensity', nor is this atribute listed when I run get(h), but still this setting influences the adaptive sampling in fsurf?
- I don't want fsurf to open a figure, but I don't understand how to prevent it, if using fsurf?
- I imagine that there exists a more fundamental matlab function/operation (which fsurf might even be using) to adaptively find good mesh/sampling points. However, I could not find any such adaptive-mesh-refinement routine(s) within matlab?
Thanks for any useful help and inputs!
(p.s. I noticed there is a function generateMesh, but unclear if this can be of any use here)