?? 18-曲線擬合和多項式擬合-3.m__.htm
字號:
<html><head><title>MATLAB.rar 18-曲線擬合和多項式擬合-3.m</title>
<LINK href="/inc/read_style.css" type=text/css rel=stylesheet></head>
<body>
<p><a href=http://www.pudn.com>www.pudn.com</a> > <a href="http://www.pudn.com/downloads111/sourcecode/graph/detail461284.html">MATLAB.rar</a> > 18-曲線擬合和多項式擬合-3.m</p><!-- saved from http://www.pudn.com -->
<script src="/inc/gg_read1.js"></script><BR>
<pre name="code" class="m">
% 最小二乘法多項式擬合
% ******** 螺旋副效率y與螺紋導(dǎo)程角x的關(guān)系 ********
% (1)-----選擇擬合多項式擬合的階數(shù)
x=[10 20 30 40 50 60 70];
y=[0.63 0.76 0.80 0.82 0.82 0.80 0.70];
n = 7; x1 = x(1); xn = x(n);
% n個數(shù)據(jù)可以擬合(n-1)階多項式,高階多項式多次求導(dǎo),數(shù)值特性變差
% polytool()是交互式函數(shù),在圖形上方[Degree]框中輸入階數(shù),右擊左下角的[Export]輸出圖形
polytool(x,y,1)
% 觀察多項式擬合的圖形,選擇置信區(qū)間最小的多項式階數(shù)
% (2)-----計算多項式的各項系數(shù)和擬合值
m=input(' 輸入多項式擬合的階數(shù) m = ');
[p,S]=polyfit(x,y,m);
disp ' 輸出多項式的各項系數(shù)'
fprintf (1,' a = %3.16f \n',p)
disp ' 輸出多項式的有關(guān)信息 S'
disp (S)
[yh,delta]=polyconf(p,x,S);
disp ' 觀測數(shù)據(jù) 擬合數(shù)據(jù)'
disp ' x y yh'
for i = 1 : n
xy = [x(i) y(i) yh(i)];
disp (xy)
end
% (3)-----繪制觀測數(shù)據(jù)離散點圖和多項式曲線
plot(x,y,'r.')
title('\bf 實驗數(shù)據(jù)離散點圖 / 多項式曲線 \it y = a0+a1x+a2x^2+a3x^3+...')
grid
hold on;
xi=[x1:0.1:xn];
yi=polyval(p,xi);
plot(xi,yi,'k-')
% (4)-----擬合效果和精度檢驗
Q=sum((y-yh).^2);
SGM = sqrt(Q / (n - 2));
RR = sum((yh-mean(y)).^2)/sum((y-mean(y)).^2);
fprintf (1,' 剩余平方和 Q = %3.6f \n',Q)
fprintf (1,' 標準誤差 Sigma = %3.6f \n',SGM)
fprintf (1,' 相關(guān)指數(shù) RR = %3.6f \n',RR)
x0=input(' 輸入插值點 x0 = ');
y0=polyval(p,x0);
fprintf (1,' 輸出插值點擬合函數(shù)值 y0 = %3.4f \n',y0)
</pre>
<script src="/inc/gg_read2.js"></script><BR>
<script src="http://s117.cnzz.com/stat.php?id=1236358&web_id=1236358&show=pic" language="JavaScript" charset="gb2312"></script>
</body></html>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -