492 Chapter 15 MATLAB
Note that if you substitute the solutionx 1 2,x 2 5, andx 3 4 into each equation, you
find that they satisfy them. That is: 2(2) 5 4 13, 3(2) 2(5)4(4) 32, and
5(2) 5 3(4)17.
15.6 Curve Fitting with MATLAB
In Section 14.8, we discussed the concept of curve fitting. MATLAB offers a variety of curve-
fitting options. We will use Example 14.11 to show how you can also use MATLAB to obtain
an equation that closely fits a set of data points. For Example 14.11 (Revisited), we will use the
command POLYFIT(x, y, n),which determines the coefficients (c 0 ,c 1 ,c 2 , ...,cn) of a
polynomial of ordernthat best fits the data according to:
Example 14. 11 Find the equation that best fits the following set of data points in Table 15.13.
(Revisited) In Section 14.8, plots of data points revealed that the relationship betweenyandxis qua-
dratic (second order polynomial). To obtain the coefficients of the second order polynomial
that best fits the given data, we will type the following sequence of commands. The MATLAB
Command Window for Example 14.11 (Revisited) is shown in Figure 15.27.
>>format compact
>> x=0:0.5:3
>> y = [2 0.75 0 -0.25 0 0.75 2]
>> Coefficients = polyfit(x,y,2)
yc 0 x
n
c 1 x
n 1
c 2 x
n 2
c 3 x
n 3
p cn
■Figure 15.27 The Command Window for Example 14.11 (Revisited).
TABLE 15.13 A Set
of Data Points for
Example 14.11
(Revisited)
XY
0.00 2.00
0.50 0.75
1.00 0.00
1.50 0.25
2.00 0.00
2.50 0.75
3.00 2.00
Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
圀圀圀⸀夀䄀娀䐀䄀一倀刀䔀匀匀⸀䌀伀䴀圀圀圀⸀夀䄀娀䐀䄀一倀刀䔀匀匀⸀䌀伀䴀