15.11.2014 Views

MATLAB Mathematics - SERC - Index of

MATLAB Mathematics - SERC - Index of

MATLAB Mathematics - SERC - Index of

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Interpolation<br />

The next step is to use interpolation to compute function values over a grid. Use<br />

meshgrid to create the grid, and griddatan to do the interpolation:<br />

delta = 0.05;<br />

d = -1:delta:1;<br />

[x0,y0,z0] = meshgrid(d,d,d);<br />

X0 = [x0(:), y0(:), z0(:)];<br />

v0 = griddatan(X,v,X0);<br />

v0 = reshape(v0, size(x0));<br />

Then use isosurface and related functions to visualize the surface that<br />

consists <strong>of</strong> the (x,y,z) values for which the function takes a constant value. You<br />

could pick any value, but the example uses the value 0.6. Since the function is<br />

the squared distance from the origin, the surface at a constant value is a<br />

sphere:<br />

p = patch(isosurface(x0,y0,z0,v0,0.6));<br />

isonormals(x0,y0,z0,v0,p);<br />

set(p,'FaceColor','red','EdgeColor','none');<br />

view(3);<br />

camlight;<br />

lighting phong<br />

axis equal<br />

title('Interpolated sphere from scattered data')<br />

Note A smaller delta produces a smoother sphere, but increases the<br />

compute time.<br />

2-35

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!