求教用matlab 实现最小二乘法拟合曲线的问题

来源:百度知道 编辑:UC知道 时间:2024/05/24 16:49:20
数据如下:x=(1,2,3,4,5,6,7,8,9,10)
y=( 96.31, 135.44, 79.5, 56.54, 256.21, 350.68, 105.62, 185.03, 493.08, 1031.17, 860.06, 746.78)
表达式为:Y = a x4+b x3+c x2+d x+e
求:a,b,c,d,e,以及 可靠度 ,请高手赐教,怎么用matlab 实现,本人菜鸟,请说详细点
谢谢各位,但能不能详细说一下怎么确定拟合曲线的精确度?
另:修改x=(1,2,3,4,5,6,7,8,9,10,11,12) ,上面后两个数忘了加上了。

使用多项式拟合函数polyfit(x,y,n),其中x是你要你和的自变量,y是你要拟合的因变量,n是你要用到的拟合多项式的最高次数,函数返回这个多项式。
具体你的问题:
x=[1,2,3,4,5,6,7,8,9,10,11,12]
y=[ 96.31, 135.44, 79.5, 56.54, 256.21, 350.68, 105.62, 185.03, 493.08, 1031.17, 860.06, 746.78]
z=polyfit(x,y,4)
ans =

-0.9026 22.3624 -171.6814 489.5975 -287.8153

y比x多出了两位,我删除了后两位;
代码如下:
function poly4(x,y)
%POLY4 Create plot of datasets and fits
% POLY4(X,Y)
% Creates a plot, similar to the plot in the main curve fitting
% window, using the data that you provide as input. You can
% apply this function to the same data you used with cftool
% or with different data. You may want to edit the function to
% customize the code and this help message.
%
% Number of datasets: 1
% Number of fits: 1

% Data from dataset "y vs. x":
% X = x:
% Y = y:
% Unweighted
%
% This function was automatical