请教ployfit,ployval 两个命令如何使用
请教大家,这两个命令在MATLAB中是怎么用?ployfit,ployval谢谢
[ 本帖最后由 eight 于 2007-9-2 21:15 编辑 ] 好像写错了吧
[ 本帖最后由 lxq 于 2007-9-2 15:28 编辑 ] POLYFIT Fit polynomial to data.
POLYFIT(X,Y,N) finds the coefficients of a polynomial P(X) of
degree N that fits the data, P(X(I))~=Y(I), in a least-squares sense.
= POLYFIT(X,Y,N) returns the polynomial coefficients P and a
structure S for use with POLYVAL to obtain error estimates on predictions.
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).
If the errors in the data, Y, are independent normal with constant
variance, POLYVAL will produce error bounds which contain at least 50% of
the predictions.
The structure S contains the Cholesky factor of the Vandermonde
matrix (R), the degrees of freedom (df), and the norm of the
residuals (normr) as fields.
= POLYFIT(X,Y,N) finds the coefficients of a polynomial
in XHAT = (X-MU(1))/MU(2) where MU(1) = mean(X) and MU(2) = std(X).
This centering and scaling transformation improves the numerical
properties of both the polynomial and the fitting algorithm. help polyfit polyval
一个简单的多项式拟合例子
x=;
y=;
b=polyfit(x,y,3)%%三次拟合
x1=0.46:.01:2.04;
f=polyval(b,x1);
plot(x,y,'ko',x1,f,'markerfacecolor','k','linewidth',2)
回复 #4 lxq 的帖子
谢谢,上面两位老兄!回复 #4 lxq 的帖子
我这里有段程序,请大家帮我看看!拟合多项式阶数是多少?采样频率是多少?从程序中能看出吗?要是看不出,该怎么加上?谢谢!clear
clc
close all hidden
fni=input('wenjian:','s');
fid=fopen (fni,'r');
sf=fscanf (fid,'%f',1);
m=fscanf (fid,'%d', 1);
fno=fscanf (fid,'%s',1);
x=fscanf(fid,'%f',inf);
status=fclose (fid);
n=length(x);
t=(0:1/sf:(n-1)/sf)';
a=polyfit(t,x,m);
y=x-polyval(a,t);
subplot(2,1,1);
plot(t,x);
grid on;
subplot(2,1,2);
plot(t,y);
grid on; 拟何阶数m
采样频率sf
从你程序上看 都是从文件中读取的
回复 #7 lxq 的帖子
谢谢!我还是不太明白,我要拟合的阶数是3,采样频率是500,怎么在程序中看出?或者我在运行程序时怎么输入?说明一下我的文件是一组采集得到的数! 你拟合的阶数从这里看a=polyfit(t,x,m);还有m=fscanf (fid,'%d', 1);
应该是要求自己输入的吧! 从程序中不能看出啊
但是可以直接定义的
m=3;
sf=500;
回复 #10 lxq 的帖子
怎么定义?能教我吗?不会是直接写上吧?
回复 #11 jingrenzhi 的帖子
现在有一个问题,我变换了m和sf的值,对同一组数据处理,根本没有变化! 为什么我的matlab找不到ployfit函数?能给个帮助吗? 原帖由 兆佳芷宁 于 2008-3-28 11:12 发表 http://www.chinavib.com/forum/images/common/back.gif
为什么我的matlab找不到ployfit函数?
能给个帮助吗? 看清楚人家的英语拼写
页:
[1]