问有xyz数据后如何拟合出z=f(x,y)的函数关系

如题所述

第1个回答  2008-06-18
二维数据拟合
试试这个
function p = polyfit2d(x,y,z,n,m)
% P= POLYFIT2D(x,y,z,n,m) finds the coefficients of a
% polynomial function of 2 variables formed from the
% data in vectors x and y of degrees n and m, respectively,
% that fit the data in vector z in a least-squares sense.
%
% The regression problem is formulated in matrix format as:
%
% z = A*P So that if the polynomial is cubic in
% x and linear in y, the problem becomes:
%
% z = [y.*x.^3 y.*x.^2 y.*x y x.^3 x.^2 x ones(length(x),1)]*
% [p31 p21 p11 p01 p30 p20 p10 p00]'
%
% Note that the various xy products are column vectors of length(x).
%
% The coefficents of the output p
% matrix are arranged as shown:
%
% p31 p30
% p21 p20
% p11 p10
% p01 p00
%
% The indices on the elements of p correspond to the
% order of x and y associated with that element.
%
% For a solution to exist, the number of ordered
% triples [x,y,z] must equal or exceed (n+1)*(m+1).
% Note that m or n may be zero.
%
% To evaluate the resulting polynominal function,
% use POLYVAL2D.

% Perry W. Stout June 29, 1995
% 4829 Rockland Way
% Fair Oaks, CA 95628
% (916) 966-0236
% Based on the Matlab function polyfit.

if any((size(x) ~= size(y)) | (size(z) ~= size(y)))
error('X, Y,and Z vectors must be the same size')
end

x = x(:); y = y(:); z= z(:); % Switches vectors to columns--matrices, too

if length(x) < (n+1)*(m+1)
error('Number of points must equal or exceed order of polynomial function.')
end

n = n + 1;
m = m + 1; % Increments n and m to equal row, col numbers of p.

a = zeros(max(size(x)),n*m);

% Construct the extended Vandermonde matrix, containing all xy products.

for i1= 1:m
for j1=1:n
a(:,j1+(i1-1)*n) = (x.^(n-j1)).*(y.^(m-i1));
end
end
p1 = (a\z);
% Reform p as a matrix.

p=[];
for i1=1:m
p=[p, p1((n*(i1-1)+1):(n*i1))];
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function z = polyval2d(c,x,y)
% z = POLYVAL2D(V,sx,sy) Two dimensional polynomial evaluation.
%
% If V is a matrix whose elements are the coefficients of a
% polynomial function of 2 variables, then POLYVAL2D(V,sx,sy)
% is the value of the polynomial evaluated at [sx,sy]. Row
% numbers in V correspond to powers of x, while column numbers
% in V correspond to powers of y. If sx and sy are matrices or
% vectors,the polynomial function is evaluated at all points
% in [sx, sy].
%
% If V is one dimensional, POLYVAL2D returns the same result as
% POLYVAL.
%
% Use POLYFIT2D to generate appropriate polynomial matrices from
% f(x,y) data using a least squares method.

% Perry W. Stout June 28, 1995
% 4829 Rockland Way
% Fair Oaks, CA 95628
% (916) 966-0236
% Based on the Matlab function POLYVAL.

% Polynomial evaluation c(x,y) is implemented using Horner's slick
% method. Note use of the filter function to speed evaluation when
% the ordered pair [sx,sy] is single valued.

if nargin==2
y=ones(x); end

if any(size(x) ~= size(y))
error('x and y must have the same dimensions.')
end

[m,n] = size(x);
[rown,coln]= size(c);

if (m+n) == 2
% Use the built-in filter function when [sx,sy] is single valued
% to implement Hoerner's method.

z= 0;
for i1= 1:coln
ccol= c(:,coln+1-i1);
w = filter(1,[1 -x],ccol);
w = w(rown)*(y^(i1-1));
z= z+w;
end
return
end % Of the scalar computation

% Do general case where X and Y are arrays
z = zeros(m,n);
for i1=1:coln
ccol= c(:,coln+1-i1);
w= zeros(m,n);
for j1=1:rown
w = x.*w + ccol(j1) * ones(m,n);
end
z= z+w.*(y.^(i1-1));
end本回答被网友采纳

问有xyz数据后如何拟合出z=f(x,y)的函数关系
[m,n] = size(x);

三组数据怎么用MATLAB怎么生成曲面图
1、根据x、y、z数据,拟合方程z=f(x,y)2、生成X-Y平面上的网格数据,根据拟合方程,计算X-Y平面上各网格点的z轴高度 3、绘制曲面图。

有xyz数据后如何通过曲面拟合获得曲面方程?
有个算法公式,就通过MATLAB计算下就可以了!你还是先找曲面拟和的算法才是正路!到时候有了在MATLAB上实现的问题的话,在来”知道”好了!

如何用MATLAB求一些三维的三点拟合出来的函数?
至于做出拟合函数z=f(x,y)可以输入sftool启动曲面拟合工具箱,输入xyz数据 选用合适的函数拟合 9月

各位大神,请问已知xyz数据,matlab如何拟合xyz方程?最好能给出程序和曲...
使用interp2函数,如图:x,y,z数据可替换,是我所上传附件的书中的内容

有xyz数据后如何通过曲面拟合获得曲面方程
用regress函数吧。REGRESS(y,X),其中,y就是你的Z,X就是你的X和Y。REGRESS Multiple linear regression using least squares.b = returns the vector of regression coefficients, b,in the linear model y = Xb, (X is an nxp matrix, y is the nx1 vector of observations).

matlab如何将离散点拟合成曲面
1. 将离散点数据存储在一个矩阵中,例如XYZ分别表示离散点的横坐标纵坐标和高度。2. 使用fit函数进行拟合,例如使用三次多项式拟合,可以使用以下代码 f = fit([X,Y],Z,poly33);其中,poly33表示三次多项式拟合。3. 可以使用plot函数绘制拟合曲面,例如使用以下代码 plot(f,[X,Y],Z);其中,[...

微积分入门(基础知识及应用)
将$x=y=z$代入$V=xyz$中,得到$x=y=z=\\sqrt[3]{\\frac{V}{3}}$。因此,当长方体盒子的长、宽、高相等时,盒子的表面积最小。曲线拟合 曲线拟合是微积分中的另一个重要应用场景,它主要研究如何通过一些已知数据点来拟合一条曲线。曲线拟合可以通过求解函数的导数或积分来解决。例如,我们...

matlab怎么将点云数据用最小二乘方法拟合出平面
d(abc,XYZ)=|cos(a)*X+sin(a)*cos(b)*Y+sin(a)*sin(b)*Z+c| 现在有已知点序列X,Y,Z,求参数 a b c 先构造一个函数fun(p) 输入参数为p,其中p(1)=a,p(2)=b,p(3)=c 使用 lsqnonlin求得p,使得sum((fun(p))^2)最小 fun=@(p) cos(p(1))*X+sin(p(1))*cos(...

空间坐标转换问题,懂一点空间几何的人都来帮帮我吧?
式中调x,y和x\\'、y\\'分别为新旧(或;旧新)网重合点的坐标,a、b、、k为变换参数,显然要解算出a、b、、k,必须至少有两个重合点,列出四个方程。即可进行通常的参数平差,解求a、x、b、c、d各参数值。将之代人(3)式,可得各拟合点的残差(改正数)代人(2)式,可得待换点的坐标...

相似回答
大家正在搜