声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 6222|回复: 13

[综合讨论] 请教ployfit,ployval 两个命令如何使用

[复制链接]
发表于 2007-9-2 12:02 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
请教大家,这两个命令在MATLAB中是怎么用?
ployfit,ployval谢谢

[ 本帖最后由 eight 于 2007-9-2 21:15 编辑 ]
回复
分享到:

使用道具 举报

发表于 2007-9-2 14:03 | 显示全部楼层
好像写错了吧

[ 本帖最后由 lxq 于 2007-9-2 15:28 编辑 ]
发表于 2007-9-2 14:06 | 显示全部楼层
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.

    [P,S] = 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.   

    [P,S,MU] = 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.
发表于 2007-9-2 15:29 | 显示全部楼层
help polyfit polyval

一个简单的多项式拟合例子
x=[0.5:0.1:2];
y=[0.39664 0.24624 0.13724 0.063503 0.018869 -0.0028101 -0.007685 -0.0019063 0.0083751 0.017009 0.017844 0.0047299 -0.028484 -0.087948 -0.17981 -0.31023];
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)
 楼主| 发表于 2007-9-2 16:45 | 显示全部楼层

回复 #4 lxq 的帖子

谢谢,上面两位老兄!
 楼主| 发表于 2007-9-2 16:49 | 显示全部楼层

回复 #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;
发表于 2007-9-3 10:30 | 显示全部楼层
拟何阶数m
采样频率sf
从你程序上看 都是从文件中读取的
 楼主| 发表于 2007-9-3 10:49 | 显示全部楼层

回复 #7 lxq 的帖子

谢谢!我还是不太明白,我要拟合的阶数是3,采样频率是500,怎么在程序中看出?或者我在运行程序时怎么输入?说明一下我的文件是一组采集得到的数!
发表于 2007-9-3 11:03 | 显示全部楼层
你拟合的阶数从这里看a=polyfit(t,x,m);
还有m=fscanf (fid,'%d', 1);
应该是要求自己输入的吧!
发表于 2007-9-3 11:03 | 显示全部楼层
从程序中不能看出啊
但是可以直接定义的
m=3;
sf=500;
 楼主| 发表于 2007-9-3 11:41 | 显示全部楼层

回复 #10 lxq 的帖子

怎么定义?能教我吗?
不会是直接写上吧?
 楼主| 发表于 2007-9-3 11:51 | 显示全部楼层

回复 #11 jingrenzhi 的帖子

现在有一个问题,我变换了m和sf的值,对同一组数据处理,根本没有变化!
发表于 2008-3-28 11:12 | 显示全部楼层
为什么我的matlab找不到ployfit函数?
能给个帮助吗?
发表于 2008-3-28 11:19 | 显示全部楼层
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-23 13:28 , Processed in 0.071399 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表