Matlab曲线拟合函数

最简单的多项式拟合

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值