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

数据如下: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,4... 数据如下: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) ,上面后两个数忘了加上了。
展开
 我来答
jackwuzm
2009-03-26 · TA获得超过2512个赞
知道小有建树答主
回答量:1149
采纳率:100%
帮助的人:785万
展开全部
使用多项式拟合函数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
ZESTRON
2024-09-04 广告
表面污染分析包括评估表面上存在的颗粒、残留物或物质。通过利用显微镜、光谱学和色谱法等技术,分析人员可以识别和表征污染物,以确定其成分和来源。这种分析在电子、制药和制造等各个行业中至关重要,以确保产品质量、性能和安全性。了解表面污染有助于实施... 点击进入详情页
本回答由ZESTRON提供
122173382
2009-03-27 · TA获得超过241个赞
知道答主
回答量:222
采纳率:0%
帮助的人:0
展开全部
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 automatically generated on 27-Mar-2009 21:43:52

% Set up figure to receive datasets and fits
f_ = clf;
figure(f_);
set(f_,'Units','Pixels','Position',[326 106 680 484]);
legh_ = []; legt_ = {}; % handles and text for legend
xlim_ = [Inf -Inf]; % limits of x axis
ax_ = axes;
set(ax_,'Units','normalized','OuterPosition',[0 0 1 1]);
set(ax_,'Box','on');
axes(ax_); hold on;

% --- Plot data originally in dataset "y vs. x"
x = x(:);
y = y(:);
h_ = line(x,y,'Parent',ax_,'Color',[0.333333 0 0.666667],...
'LineStyle','none', 'LineWidth',1,...
'Marker','.', 'MarkerSize',12);
xlim_(1) = min(xlim_(1),min(x));
xlim_(2) = max(xlim_(2),max(x));
legh_(end+1) = h_;
legt_{end+1} = 'y vs. x';

% Nudge axis limits beyond data limits
if all(isfinite(xlim_))
xlim_ = xlim_ + [-1 1] * 0.01 * diff(xlim_);
set(ax_,'XLim',xlim_)
else
set(ax_, 'XLim',[0.91000000000000003, 10.09]);
end

% --- Create fit "fit 1"
ok_ = isfinite(x) & isfinite(y);
if ~all( ok_ )
warning( 'GenerateMFile:IgnoringNansAndInfs', ...
'Ignoring NaNs and Infs in data' );
end
ft_ = fittype('poly4');

% Fit this model using new data
cf_ = fit(x(ok_),y(ok_),ft_);

% Or use coefficients from the original fit:
if 0
cv_ = { 1.9494012237762368, -37.46559731934768, 242.74933129370976, -576.15945804197111, 496.91083333334984};
cf_ = cfit(ft_,cv_{:});
end

% Plot this fit
h_ = plot(cf_,'fit',0.95);
legend off; % turn off legend from plot method call
set(h_(1),'Color',[1 0 0],...
'LineStyle','-', 'LineWidth',2,...
'Marker','none', 'MarkerSize',6);
legh_(end+1) = h_(1);
legt_{end+1} = 'fit 1';

% Done plotting data and fits. Now finish up loose ends.
hold off;
leginfo_ = {'Orientation', 'vertical', 'Location', 'NorthEast'};
h_ = legend(ax_,legh_,legt_,leginfo_{:}); % create legend
set(h_,'Interpreter','none');
xlabel(ax_,''); % remove x label
ylabel(ax_,''); % remove y label

结果:
Linear model Poly4:
f(x) = p1*x^4 + p2*x^3 + p3*x^2 + p4*x + p5
Coefficients (with 95% confidence bounds):
p1 = 1.949 (-0.1406, 4.039)
p2 = -37.47 (-83.7, 8.768)
p3 = 242.7 (-103.2, 588.7)
p4 = -576.2 (-1575, 422.8)
p5 = 496.9 (-389.4, 1383)

Goodness of fit:
SSE: 5.445e+004
R-square: 0.9319
Adjusted R-square: 0.8774
RMSE: 104.4
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
愿为弟子
2009-03-25
知道答主
回答量:27
采纳率:0%
帮助的人:0
展开全部
请使用多项式拟合函数polyfit(x,y,n),其中x是你要你和的自变量,y是你要拟合的因变量,n是你要用到的拟合多项式的最高次数,函数返回这个多项式。
详见MATLAB帮助文档:polyfit
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式