Matlab 线性拟合 & 非线性拟合
Matlab 线性拟合 & 非线性拟合
使用Matlab进行拟合是图像处理中线条变换的一个重点内容,本文将详解Matlab中的直线拟合和曲线拟合用法。
关键函数:
fittype
Fit type for curve and surface fitting
Syntax
ffun = fittype(libname) ffun = fittype(expr) ffun = fittype({expr1,...,exprn}) ffun = fittype(expr, Name, Value,...) ffun= fittype({expr1,...,exprn}, Name, Value,...)/***********************************线性拟合***********************************/
线性拟合公式:
coeff1 * term1 + coeff2 * term2 + coeff3 * term3 + ...其中,coefficient是系数,term都是x的一次项。
线性拟合Example:
Example1: y=kx+b;
法1:
- x=[1,1.5,2,2.5,3];y=[0.9,1.7,2.2,2.6,3];
- p=polyfit(x,y,1);
- x1=linspace(min(x),max(x));
- y1=polyval(p,x1);
- plot(x,y,'*',x1,y1);
即y=1.0200 *x+ 0.0400
法2:
- x=[1;1.5;2;2.5;3];y=[0.9;1.7;2.2;2.6;3];
- p=fittype('poly1')
- f=fit(x,y,p)
- plot(f,x,y);
- x=[1;1.5;2;2.5;3];y=[0.9;1.7;2.2;2.6;3];
- p=fittype('poly1')
- f=fit(x,y,p)
- plot(f,x,y);
- p =
- Linear model Poly1:
- p(p1,p2,x) = p1*x + p2
- f =
- Linear model Poly1:
- f(x) = p1*x + p2
- Coefficients (with 95% confidence bounds):
- p1 = 1.02 (0.7192, 1.321)
- p2 = 0.04 (-0.5981, 0.6781)
|
评论暂时关闭