2.5

2.5 | 6 ratings Rate this file 14 Downloads (last 30 days) File Size: 3.7 KB File ID: #8970

3D Data Interpolation

by Per Sundqvist

 

09 Nov 2005 (Updated 12 Nov 2008)

3D interpolation using modified 4-point vector Newton interpolation

| Watch this File

File Information
Description

Syntax: ui=NewtFit(x,y,z,u,xi,yi,zi)

3D interpolation. It may be used where griddata3 fails to find a triangularization of the datagrid (x,y,z). The function uses a modified 4 point Newton interpolation formula for vector arguments in 3D instread of scalars used in 1D. The interpolation is performed for the 4 nearest neighbors for each point in the (xi,yi,zi).

u=u(x,y,z) is the data from which ui(xi,yi,zi) is interpolated x,y,z,u are vectors of same size and xi,yi,zi are also vectors. The fit is exact (u=ui) for points (xi,yi,zi) that coinside with data points (x,y,z). Note: NewtFit also delivers result for points outside the domain (i.e., extrapolation), but results may be inaccurate then.

%Example: Prepare data in random non-uniform grid
  xyz=rand(10003,3);
  x=xyz(:,1);y=xyz(:,2);z=xyz(:,3);
  u=x.^3+sin(pi*y).^2.*z.^2;
  
  %Gridpoints to fit:
  xyz=rand(8007,3);
  xi=xyz(:,1);yi=xyz(:,2);zi=xyz(:,3);
 
  %Interpolate
  ui=NewtFit(x,y,z,u,xi,yi,zi);
 
  %compare and plot
  uui=xi.^3+sin(pi*yi).^2.*zi.^2;%exact
  plot(uui,ui,'.');pause(4)
  hist(uui-ui,60);
  standard_deviation=std(uui-ui)

MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
10 Nov 2005 Reaz Karim

Good, but with a bug. Undefined function or variable n when p == 0!. you could update after correcting. Also, deviation becomes high in some cases I tested.

12 Dec 2006 Vishwas Iyengar

i tried to run this, but it is giving me weird numbers. i have two 3d grids, which are different in dimensions. so i ran the file with the first grid being (x,y,z) and u being my variable which needs to be interpolated onto another grid (x1,y1,z1). but it is not working. i wonder why? any comments?

17 Apr 2007 Kent Davey

The program crashes if you reduce the size of the matrices using your own example. Would you please fix this?

xyz=rand(100,3);
x=xyz(:,1);y=xyz(:,2);z=xyz(:,3);
u=x.^3+sin(pi*y).^2.*z.^2;

%Gridpoints to fit:
xyz=rand(80,3);
xi=xyz(:,1);yi=xyz(:,2);zi=xyz(:,3);

%Interpolate
ui=NewtFit(x,y,z,u,xi,yi,zi);

%compare and plot
uui=xi.^3+sin(pi*yi).^2.*zi.^2;%exact
plot(uui,ui,'.')

17 Apr 2007 Kent Davey

There are two lines right at the end of the code that need to be changed to

            (y*ones(1,Nv)-ones(Nd,1)*yi).^2+...
            (z*ones(1,Nv)-ones(Nd,1)*zi).^2;

29 Nov 2007 turki mehdi  
13 Feb 2008 Jami lynn

Not correct.

Please login to add a comment or rating.
Updates
12 Nov 2008

Bug fixed. Have some ideas to improve it a bit more, but it will come later...

Tag Activity for this File
Tag Applied By Date/Time
approximation Per Sundqvist 22 Oct 2008 08:05:40
interpolation Per Sundqvist 22 Oct 2008 08:05:40
3d interpolation Per Sundqvist 22 Oct 2008 08:05:40
newton Per Sundqvist 22 Oct 2008 08:05:40
mathematics Per Sundqvist 22 Oct 2008 08:05:40
nonuniform Per Sundqvist 22 Oct 2008 08:05:40
mathematics Cristina McIntire 13 Nov 2008 14:18:20
3d interpolation Mauricio Perillo 10 Apr 2011 18:29:24

Contact us at files@mathworks.com