用MATLAB进行数据插值
例 >> [x,y]=meshgrid(-3:.6:3,-2:.4:2); >> z=(x.^2-2*x).*exp… (-x.^2-y.^2-x.*y); >> surf(x,y,z), 选较密的插值点,用默认的线性插值算法进行插值 >> [x1,y1]=meshgrid(-3:.2:3,-2:.2:2); >> z0=interp2(x,y,z,x1,y1); >> surf(x1,y1,z0) 立方和样条插值: >> z1=interp2(x,y,z,x1,y1,'cubic'); >> z2=interp2(x,y,z,x1,y1,'spline'); >> surf(x1,y1,z1),axis([-3,3,-2,2,-0.7,1.5]) >> figure;surf(x1,y1,z2),axis([-3,3,-2,2,-0.7,1.5]) 算法误差比较 >> z=(x1.^2-2*x1).*exp(-x1.^2-y1.^2-x1.*y1); >> surf(x1,y1,abs(z-z1)) >> figure;surf(x1,y1,abs(z-z2)) >> figure;surf(x1,y1,abs(z-z0)) 山区地形地貌图 已知某处山区地形选点测量坐标数据为: x=0? 0.5? 1? 1.5? 2? 2.5? 3? 3.5? 4? 4.5? 5 y=0? 0.5? 1? 1.5? 2? 2.5? 3? 3.5? 4? 4.5? 5? 5.5? 6 海拔高度数据为: z=89 90 87 85 92 91 96 93 90 87 82 ?? 92 96 98 99 95 91 89 86 84 82 84 ?? 96 98 95 92 90 88 85 84 83 81 85 ?? 80 81 82 89 95 96 93 92 89 86 86 ?? 82 85 87 98 99 96 97 88 85 82 83 ?? 82 85 89 94 95 93 92 91 86 84 88 ?? 88 92 93 94 95 89 87 86 83 81 92 ?? 92 96 97 98 96 93 95 84 82 81 84 ?? 85 85 81 82 80 80 81 85 90 93 95 ?? 84 86 81 98 99 98 97 96 95 84 87 ?? 80 81 85 82 83 84 87 90 95 86 88 ?? 80 82 81 84 85 86 83 82 81 80 82 ?? 87 88 89 98 99 97 96 98 94 92 87 山区地形地貌图 程序 原始地貌图程序: x=0:.5:5; y=0:.5:6; [xx,yy]=meshgrid(x,y); z=[89 90 87 85 92 91 96 93 90 87 82 92 96 98 99 95 91 89 86 84 82 84 96 98 95 92 90 88 85 84 83 81 85 80 81 82 89 95 96 93 92 89 86 86 82 85 87 98 99 96 97 88 85 82 83 82 85 89 94 95 93 92 91 86 84 88 88 92 93 94 95 89 87 86 83 81 92 92 96 97 98 96 93 95 84 82 81 84 85 85 81 82 80 80 81 85 90 93 95 84 86 81 98 99 98 97 96 95 84 87 80 81 85 82 83 84 87 90 95 86 88 80 82 81 84 85 86 83 82 81 80 82 87 88 89 98 99 97 96 98 94 92 87]; mesh(xx,yy,z) 山区地形地貌图 结果 >> x=-3+6*rand(200,1);y=-2+4*rand(200,1); >> z=(x.^2-2*x).*exp(-x.^2-y.^2-x.*y); >> [x1,y1]=meshgrid(-3:.2:3,-2:.2:2); >> z1=griddata(x,y,z,x1,y1,'cubic'); >> surf(x1,y1,z1),axis([-3,3,-2,2,-0.7,1.5]) >> z2=griddata(x,y,z,x1,y1,'v4'); >> figure;surf(x1,y1,z2),axis([-3,3,-2,2,-0.7,1.5]) 误差分析 >> z0=(x1.