如何利用MATLAB,把关系列表中数据转换成函数关系式3
发布网友
发布时间:2023-09-26 03:46
我来回答
共1个回答
热心网友
时间:2024-12-04 06:20
最简单的多项式拟合
P = POLYFIT(X,Y,N) finds the coefficients of a polynomial P(X) of degree N that fits the data Y best in a least-squares sense. P is a row vector of length N+1 containing the polynomial coefficients in descending powers, P(1)*X^N + P(2)*X^(N-1) +...+ P(N)*X + P(N+1).
三次样条插值
pp = spline(x,Y) returns the piecewise polynomial form of the cubic spline interpolant for later use with ppval and the spline utility unmkpp. x must be a vector. Y can be a scalar, a vector, or an array of any dimension. If Y is an array that is not a vector, the size of Y must have the form [d1,d2,...,dk,n], where n is the length of x. The interpolation is performed for each d1-by-d2-by-...-dk value in Y.
yy = spline(x,Y,xx) is the same as yy = ppval(spline(x,Y),xx), thus providing, in yy, the values of the interpolant at xx. xx can be a scalar, a vector, or a multidimensional array.
bezier曲线
function [X,Y]=bezier(x,y)
%用法:
%bezier(x,y)
% 生成n-1次贝塞尔曲线,其中x和y是n个点的坐标
%h=bezier(x,y)
% 生成n-1次贝塞尔曲线并返回曲线句柄
%[X,Y]=bezier(x,y)
% 返回n-1次贝塞尔曲线的坐标
%例子:
%bezier([5,6,10,12],[0 5 -5 -2])
n=length(x);
t=linspace(0,1);
xx=0;yy=0;
for k=0:n-1
tmp=nchoosek(n-1,k)*t.^k.*(1-t).^(n-1-k);
xx=xx+tmp*x(k+1);
yy=yy+tmp*y(k+1);
end
if nargout==2
X=xx;Y=yy;
end
h=plot(xx,yy);
if nargout==1
X=h;
end
end
参考资料:http://blog.163.com/blank-dic/blog/static/3101862220100185108732/