有如下原始数据x,y,它对应的曲线图形为:
-9552
|
-2036.81
|
-9328
|
-2025.62
|
-9168
|
-2014.43
|
-9024
|
-2003.25
|
-8928
|
-1992.06
|
-8800
|
-1980.87
|
-8688
|
-1969.68
|
-8592
|
-1958.49
|
-8496
|
-1947.3
|
-8416
|
-1936.11
|
-8336
|
-1924.93
|
-8240
|
-1913.74
|
-8112
|
-1902.55
|
-8016
|
-1891.36
|
-7920
|
-1880.17
|
-7824
|
-1868.98
|
-7744
|
-1857.8
|
-7648
|
-1846.61
|
-7552
|
-1835.42
|
-7472
|
-1824.23
|
-7392
|
-1813.04
|
-7328
|
-1801.85
|
-7248
|
-1790.66
|
-7136
|
-1779.48
|
-7072
|
-1768.29
|
-7008
|
-1757.1
|
-6944
|
-1745.91
|
-6896
|
-1734.72
|
-6848
|
-1723.53
|
-6752
|
-1712.34
|
-6688
|
-1701.16
|
-6592
|
-1689.97
|
-6512
|
-1678.78
|
-6400
|
-1667.59
|
-6288
|
-1656.4
|
-6192
|
-1645.21
|
-6096
|
-1634.02
|
-6016
|
-1622.84
|
-5920
|
-1611.65
|
-5840
|
-1600.46
|
-5744
|
-1589.27
|
-5664
|
-1578.08
|
-5568
|
-1566.89
|
-5504
|
-1555.7
|
-5440
|
-1544.52
|
-5360
|
-1533.33
|
-5280
|
-1522.14
|
-5168
|
-1510.95
|
-5088
|
-1499.76
|
-5024
|
-1488.57
|
-4960
|
-1477.39
|
-4896
|
-1466.2
|
-4848
|
-1455.01
|
-4800
|
-1443.82
|
-4720
|
-1432.63
|
-4656
|
-1421.44
|
-4592
|
-1410.25
|
-4512
|
-1399.07
|
-4448
|
-1387.88
|
-4400
|
-1376.69
|
-4336
|
-1365.5
|
-4304
|
-1354.31
|
-4272
|
-1343.12
|
-4208
|
-1331.93
|
-4144
|
-1320.75
|
-4096
|
-1309.56
|
-4048
|
-1298.37
|
-3984
|
-1287.18
|
-3952
|
-1275.99
|
-3888
|
-1264.8
|
-3824
|
-1253.61
|
-3776
|
-1242.43
|
-3712
|
-1231.24
|
-3680
|
-1220.05
|
-3632
|
-1208.86
|
-3584
|
-1197.67
|
-3504
|
-1186.48
|
-3456
|
-1175.3
|
-3408
|
-1164.11
|
-3360
|
-1152.92
|
-3328
|
-1141.73
|
-3296
|
-1130.54
|
-3264
|
-1119.35
|
-3200
|
-1108.16
|
-3152
|
-1096.98
|
-3120
|
-1085.79
|
-3072
|
-1074.6
|
-3024
|
-1063.41
|
-2992
|
-1052.22
|
-2928
|
-1041.03
|
-2880
|
-1029.84
|
-2832
|
-1018.66
|
-2816
|
-1007.47
|
-2768
|
-996.279
|
-2720
|
-985.09
|
-2688
|
-973.902
|
-2656
|
-962.713
|
-2624
|
-951.525
|
-2576
|
-940.336
|
-2544
|
-929.148
|
-2512
|
-917.959
|
-2480
|
-906.77
|
-2432
|
-895.582
|
-2416
|
-884.393
|
-2368
|
-873.205
|
-2336
|
-862.016
|
-2320
|
-850.828
|
-2272
|
-839.639
|
-2224
|
-828.451
|
-2192
|
-817.262
|
-2160
|
-806.074
|
-2144
|
-794.885
|
-2112
|
-783.697
|
-2080
|
-772.508
|
-2032
|
-761.32
|
-2000
|
-750.131
|
-1984
|
-738.943
|
-1952
|
-727.754
|
-1936
|
-716.566
|
-1904
|
-705.377
|
-1888
|
-694.189
|
-1856
|
-683
|
-1824
|
-671.811
|
-1792
|
-660.623
|
-1760
|
-649.434
|
-1744
|
-638.246
|
-1712
|
-627.057
|
-1696
|
-615.869
|
-1680
|
-604.68
|
-1648
|
-593.492
|
-1616
|
-582.303
|
-1584
|
-571.115
|
-1568
|
-559.926
|
-1552
|
-548.738
|
-1536
|
-537.549
|
-1504
|
-526.361
|
-1488
|
-515.172
|
-1472
|
-503.984
|
-1456
|
-492.795
|
-1440
|
-481.607
|
-1408
|
-470.418
|
-1392
|
-459.23
|
-1376
|
-448.041
|
-1344
|
-436.852
|
-1312
|
-425.664
|
-1296
|
-414.475
|
-1296
|
-403.287
|
-1248
|
-392.098
|
-1232
|
-380.91
|
-1216
|
-369.721
|
-1216
|
-358.533
|
-1184
|
-347.344
|
-1168
|
-336.156
|
-1136
|
-324.967
|
-1120
|
-313.779
|
-1104
|
-302.59
|
-1088
|
-291.402
|
-1072
|
-280.213
|
-1040
|
-269.025
|
-1024
|
-257.836
|
-1008
|
-246.648
|
-992
|
-235.459
|
-976
|
-224.27
|
-944
|
-213.082
|
-944
|
-201.893
|
-912
|
-190.705
|
-896
|
-179.516
|
-880
|
-168.328
|
-880
|
-157.139
|
-848
|
-145.951
|
-848
|
-134.762
|
-832
|
-123.574
|
-800
|
-112.385
|
-768
|
-101.197
|
-752
|
-90.0082
|
-752
|
-78.8197
|
-736
|
-67.6311
|
-704
|
-56.4426
|
-688
|
-45.2541
|
-656
|
-34.0656
|
-656
|
-22.877
|
-624
|
-11.6885
|
-608
|
-0.5
|
-608
|
10.68852
|
-576
|
21.87705
|
-560
|
33.06557
|
-544
|
44.2541
|
-528
|
55.44262
|
-528
|
66.63115
|
-496
|
77.81967
|
-464
|
89.0082
|
-448
|
100.1967
|
-432
|
111.3852
|
-416
|
122.5738
|
-400
|
133.7623
|
-384
|
144.9508
|
-352
|
156.1393
|
-336
|
167.3279
|
-320
|
178.5164
|
-304
|
189.7049
|
-272
|
200.8934
|
-256
|
212.082
|
-240
|
223.2705
|
-208
|
234.459
|
-208
|
245.6475
|
-192
|
256.8361
|
-160
|
268.0246
|
-128
|
279.2131
|
-112
|
290.4016
|
-96
|
301.5902
|
-80
|
312.7787
|
-48
|
323.9672
|
-32
|
335.1557
|
0
|
346.3443
|
32
|
357.5328
|
48
|
368.7213
|
80
|
379.9098
|
112
|
391.0984
|
128
|
402.2869
|
144
|
413.4754
|
176
|
424.6639
|
192
|
435.8525
|
208
|
447.041
|
240
|
458.2295
|
272
|
469.418
|
288
|
480.6066
|
320
|
491.7951
|
336
|
502.9836
|
368
|
514.1721
|
400
|
525.3607
|
416
|
536.5492
|
448
|
547.7377
|
480
|
558.9262
|
512
|
570.1148
|
544
|
581.3033
|
576
|
592.4918
|
608
|
603.6803
|
640
|
614.8689
|
656
|
626.0574
|
688
|
637.2459
|
720
|
648.4344
|
752
|
659.623
|
784
|
670.8115
|
816
|
682
|
848
|
693.1885
|
880
|
704.377
|
912
|
715.5656
|
944
|
726.7541
|
976
|
737.9426
|
1008
|
749.1311
|
1056
|
760.3197
|
1088
|
771.5082
|
1104
|
782.6967
|
1152
|
793.8852
|
1184
|
805.0738
|
1216
|
816.2623
|
1248
|
827.4508
|
1280
|
838.6393
|
1312
|
849.8279
|
1344
|
861.0164
|
1392
|
872.2049
|
1424
|
883.3934
|
1472
|
894.582
|
1504
|
905.7705
|
1552
|
916.959
|
1584
|
928.1475
|
1632
|
939.3361
|
1680
|
950.5246
|
1728
|
961.7131
|
1776
|
972.9016
|
1824
|
984.0902
|
1856
|
995.2787
|
1904
|
1006.467
|
1952
|
1017.656
|
2000
|
1028.844
|
2048
|
1040.033
|
2096
|
1051.221
|
2128
|
1062.41
|
2176
|
1073.598
|
2224
|
1084.787
|
2288
|
1095.975
|
2320
|
1107.164
|
2384
|
1118.352
|
2432
|
1129.541
|
2480
|
1140.73
|
2544
|
1151.918
|
2576
|
1163.107
|
2640
|
1174.295
|
2704
|
1185.484
|
2752
|
1196.672
|
2800
|
1207.861
|
2864
|
1219.049
|
2912
|
1230.238
|
2960
|
1241.426
|
3008
|
1252.615
|
3072
|
1263.803
|
3136
|
1274.992
|
3200
|
1286.18
|
3264
|
1297.369
|
3328
|
1308.557
|
3392
|
1319.746
|
3440
|
1330.934
|
3520
|
1342.123
|
3584
|
1353.311
|
3648
|
1364.5
|
3712
|
1375.689
|
3776
|
1386.877
|
3856
|
1398.066
|
3920
|
1409.254
|
3984
|
1420.443
|
4032
|
1431.631
|
4128
|
1442.82
|
4192
|
1454.008
|
4272
|
1465.197
|
4320
|
1476.385
|
4400
|
1487.574
|
4464
|
1498.762
|
4544
|
1509.951
|
4608
|
1521.139
|
4704
|
1532.328
|
4752
|
1543.516
|
4832
|
1554.705
|
4896
|
1565.893
|
4960
|
1577.082
|
5040
|
1588.27
|
5120
|
1599.459
|
5184
|
1610.648
|
5264
|
1621.836
|
5328
|
1633.025
|
5392
|
1644.213
|
5472
|
1655.402
|
5520
|
1666.59
|
5616
|
1677.779
|
5696
|
1688.967
|
5776
|
1700.156
|
5840
|
1711.344
|
5904
|
1722.533
|
6000
|
1733.721
|
6064
|
1744.91
|
6144
|
1756.098
|
6208
|
1767.287
|
6272
|
1778.475
|
6352
|
1789.664
|
6400
|
1800.852
|
6480
|
1812.041
|
6528
|
1823.23
|
6592
|
1834.418
|
6672
|
1845.607
|
6736
|
1856.795
|
6800
|
1867.984
|
6864
|
1879.172
|
6928
|
1890.361
|
6992
|
1901.549
|
7040
|
1912.738
|
7104
|
1923.926
|
7152
|
1935.115
|
7184
|
1946.303
|
7248
|
1957.492
|
7280
|
1968.68
|
7328
|
1979.869
|
7376
|
1991.057
|
7408
|
2002.246
|
7456
|
2013.434
|
7488
|
2024.623
|
7536
|
2035.811
|
7568
|
2047
|
如果想得到该曲线的函数表达式(多项式拟合的表达式),在Excel 自带图表工具中可以能过为曲线加趋势线方式实现:
选择多项式,调整阶数让拟合后在结果与原始曲线尽量重合,并勾选显示公式:
EXCEL趋势曲线多项式最高的阶数是6阶,但是实际效果与原始数据相差还是较大,看到是我们数据太复杂,EXCEL也无能为力了,这时也只能请出强大的matlab来解决,把上述原始数据保存于EXCEL中,并强excel文件(.xls/xlsx)保存于matlab工作目录下,然后运行如下代码(可以把下面代码保存为.m文件,然后运行):
% 清屏,清除变量
clear,clc,close all
% 从excel中得到数据
x = xlsread('test.xlsx');
% 数据转置
x = x';
% 画出原始数据
plot(x(1,:),x(2,:),'r');
% 多项式拟合,如果拟合效果不好,可以得高多项式的阶数,也就是下面最后一个参数,多项式越高,计算量就越大,
% P是多项式的表达式
[p,s]=polyfit(x(1,:),x(2,:),15); % 15是多项式阶数
% 用上面拟合出的多项式计算对应的结果及与原始数据的偏差
[y_fit,DELTA]=polyval(p,x(1,:),s);
% 画出拟合后的结果
hold on
plot(x(1,:),y_fit,'b');
% 给曲线加标注
legend('原始曲线','拟合后曲线');
% 显示多项式各阶系数
p
4阶多项式拟合效果:
6阶多项式拟合效果:
10阶多项式拟合效果:
15阶多项式拟合效果:
20阶多项式拟合效果:
微信关注图中张十三的博客公众号,学习更多技术干货:
|
请发表评论