Graphics Programs Reference
In-Depth Information
It can be shown that fitting y i directly (which involves the solution of a transcen-
dentalequation) results in f ( x )
614 e 0 . 5442 x . The corresponding standarddeviation
=
3
.
is
σ =
1
.
022, which is very close to the result in Part(2).
EXAMPLE 3.10
Write aprogram that fits apolynomialofarbitrary degree k to the datapoints shown
below. Use the program to determine k that best fits this datainthe least-squares
sense.
x
0
.
04
0
.
93
1
.
95
2
.
90
3
.
83
5
.
00
y
8
.
66
6
.
44
4
.
36
3
.
27
0
.
88
0
.
87
x
5
.
98
7
.
05
8
.
21
9
.
08
10
.
09
y
3
.
31
4
.
63
6
.
19
7
.
40
8
.
85
Solution The following program prompts for k .Executionisterminatedbypressing
“return.”
% Example 3.10 (Polynomial curve fitting)
xData = [-0.04,0.93,1.95,2.90,3.83,5.0,...
5.98,7.05,8.21,9.08,10.09]';
yData = [-8.66,-6.44,-4.36,-3.27,-0.88,0.87,...
3.31,4.63,6.19,7.4,8.85]';
format short e
while 1
k = input('degree of polynomial = ');
if isempty(k) % Loop is terminated
fprintf('Done') % by pressing ''return''
break
end
coeff = polynFit(xData,yData,k+1)
sigma = stdDev(coeff,xData,yData)
fprintf('\n')
end
The results are:
Degree of polynomial = 1
coeff =
1.7286e+000
-7.9453e+000
Search WWH ::




Custom Search