Assignment
Software: MATLAB
Description:
Please use MATLAB to write a program to run polynomial fitting to extract the equation
of the three raw data files.
Equation form: Y = A0 + a1X + a2X2 + a3X3 + a4X4 +…+ anXn
Note that n is the maximum order, this shall be adjustable. (Please mark in the script
of MATLAB)
Note that A0 must equal to the Y value provided in the raw data where X = 0.
For example, for the file “raw_data1.xlsx”, A0 = XXXXXXXXXX.
After the extraction of the polynomial equation, please plot the fitted curve with the
scattered points provided in the .xlsx file. The example is shown below in Fig. 1.
Fig. 1. Example plotting the scattered and fitted data together.
Next, please generate an .xlsx file outputting the raw data with the range of x – [-5,2],
and include Y value in the file.
Please use the extracted polynomial equation to plot the derivative and second
derivative equations of it. The range of x is also set to be from -5 to 2.
Y’ = a1 + 2a2X1 + 3a3X2 + 4a4X3 +…+ nanXn-1
Y’ = 2a2 + 6a3X + 12a4X2 +…+ n(n-1)anXn-2
In this work, three plots, one .xlsx and three equations must be generated to fulfill the
equirements.
Figures:
1. Plot showing the fitted curve with scattered data together
2. Plot the first derivative of the fitted curve at x range from -5 to 2
3. Plot the second derivative of the fitted curve at x range from -5 to 2
.xlsx file to be generated:
The raw data of the fitted curve, at x range from -5 to 2, with a step of 0.1
Equations:
1. Fitted polynomial equation with the provided raw data
2. First derivative of the fitted polynomial equation
3. Second derivative of the fitted polynomial equation
工作表1
X Y
-5 9.58E-06
-4.965 1.71E-05
-4.93 3.07E-05
-4.895 5.52E-05
-4.86 9.95E-05
-4.825 1.79E-04
-4.79 3.22E-04
-4.755 5.75E-04
-4.72 0.00102
-4.685 0.00177
-4.65 0.003
-4.615 0.00491
-4.58 0.00772
-4.545 0.01158
-4.51 0.01661
-4.475 0.0228
-4.44 0.03011
-4.405 0.03843
-4.37 0.04767
-4.335 0.05772
-4.3 0.06848
-4.265 0.07987
-4.23 0.09181
-4.195 0.10423
-4.16 0.11708
-4.125 0.13031
-4.09 0.14389
-4.055 0.15776
-4.02 0.17191
-3.985 0.1863
-3.95 0.20091
-3.915 0.21571
-3.88 0.2307
-3.845 0.24584
-3.81 0.26113
-3.775 0.27655
-3.74 0.29208
-3.705 0.30772
-3.67 0.32346
-3.635 0.33928
-3.6 0.35518
-3.565 0.37115
-3.53 0.38718
-3.495 0.40326
-3.46 0.41939
-3.425 0.43556
-3.39 0.45176
-3.355 0.468
-3.32 0.48425
-3.285 0.50053
-3.25 0.51683
-3.215 0.53315
-3.18 0.54948
-3.145 0.56582
-3.11 0.58219
-3.075 0.59858
-3.04 0.61501
-3.005 0.63149
-2.97 0.64801
-2.935 0.6646
-2.9 0.68123
-2.865 0.69792
-2.83 0.71464
-2.795 0.73139
-2.76 0.74816
-2.725 0.76493
-2.69 0.78171
-2.655 0.79848
-2.62 0.81524
-2.585 0.83198
-2.55 0.84871
-2.515 0.86542
-2.48 0.8821
-2.445 0.89877
-2.41 0.9154
-2.375 0.93201
-2.34 0.94858
-2.305 0.96513
-2.27 0.98164
-2.235 0.99812
-2.2 1.01456
-2.165 1.03096
-2.13 1.04732
-2.095 1.06365
-2.06 1.07993
-2.025 1.09616
-1.99 1.11236
-1.955 1.12851
-1.92 1.14461
-1.885 1.16066
-1.85 1.17667
-1.815 1.19262
-1.78 1.20853
-1.745 1.22438
-1.71 1.24017
-1.675 1.2559
-1.64 1.27158
-1.605 1.28719
-1.57 1.30273
-1.535 1.31821
-1.5 1.33361
-1.465 1.34895
-1.43 1.36421
-1.395 1.3794
-1.36 1.39451
-1.325 1.40955
-1.29 1.42451
-1.255 1.4394
-1.22 1.45421
-1.185 1.46894
-1.15 1.48359
-1.115 1.49817
-1.08 1.51266
-1.045 1.52708
-1.01 1.54141
-0.975 1.55566
-0.94 1.56983
-0.905 1.5839
-0.87 1.5979
-0.835 1.6118
-0.8 1.62562
-0.765 1.63935
-0.73 1.65299
-0.695 1.66655
-0.66 1.68001
-0.625 1.69337
-0.59 1.70665
-0.555 1.71982
-0.52 1.73291
-0.485 1.74589
-0.45 1.75877
-0.415 1.77155
-0.38 1.78423
-0.345 1.7968
-0.31 1.80927
-0.275 1.82163
-0.24 1.83388
-0.205 1.84602
-0.17 1.85805
-0.135 1.86997
-0.1 1.88178
-0.065 1.89347
-0.03 1.90505
0.005 1.91652
0.04 1.92786
0.075 1.93909
0.11 1.9502
0.145 1.96118
0.18 1.97202
0.215 1.98274
0.25 1.9933
0.285 2.0037
0.32 2.01392
0.355 2.02392
0.39 2.03365
0.425 2.04302
0.46 2.05188
0.495 2.06018
0.53 2.06808
0.565 2.07578
0.6 2.08326
0.635 2.09047
0.67 2.09743
0.705 2.10414
0.74 2.11063
0.775 2.1169
0.81 2.12296
0.845 2.12881
0.88 2.13446
0.915 2.13991
0.95 2.14515
0.985 2.15021
1.02 2.15507
1.055 2.15975
1.09 2.16426
1.125 2.16859
1.16 2.17277
1.195 2.17679
1.23 2.18066
1.265 2.18441
1.3 2.18804
1.335 2.19155
1.37 2.19494
1.405 2.19821
1.44 2.20139
1.475 2.20446
1.51 2.20745
1.545 2.21033
1.58 2.21313
1.615 2.21584
1.65 2.21848
1.685 2.22104
1.72 2.22355
1.755 2.22599
1.79 2.22837
1.825 2.23069
1.86 2.23295
1.895 2.23515
1.93 2.23729
1.965 2.23938
2 2.24141
工作表1
X Y
-5 1.39E-12
-4.965 2.24E-12
-4.93 3.63E-12
-4.895 5.91E-12
-4.86 9.66E-12
-4.825 1.58E-11
-4.79 2.59E-11
-4.755 4.23E-11
-4.72 6.86E-11
-4.685 1.10E-10
-4.65 1.75E-10
-4.615 2.77E-10
-4.58 4.41E-10
-4.545 7.13E-10
-4.51 1.17E-09
-4.5 1.36E-09
-4.465 2.28E-09
-4.43 3.89E-09
-4.395 6.71E-09
-4.36 1.17E-08
-4.325 2.04E-08
-4.29 3.60E-08
-4.255 6.40E-08
-4.22 1.14E-07
-4.185 2.06E-07
-4.15 3.74E-07
-4.115 6.83E-07
-4.08 1.26E-06
-4.045 2.35E-06
-4.01 4.41E-06
-4 5.29E-06
-3.965 1.00E-05
-3.93 1.92E-05
-3.895 3.71E-05
-3.86 7.19E-05
-3.825 1.40E-04
-3.79 2.73E-04
-3.755 5.31E-04
-3.72 0.00102
-3.685 0.00193
-3.65 0.00352
-3.615 0.00613
-3.58 0.01006
-3.545 0.01551
-3.51 0.02252
-3.5 0.0248
-3.465 0.03368
-3.43 0.04384
-3.395 0.05512
-3.36 0.06736
-3.325 0.08044
-3.29 0.09422
-3.255 0.10863
-3.22 0.12358
-3.185 0.13899
-3.15 0.15482
-3.115 0.17102
-3.08 0.18753
-3.045 0.20433
-3.01 0.22138
-3 0.2263
-2.965 0.24363
-2.93 0.26116
-2.895 0.27885
-2.86 0.2967
-2.825 0.31469
-2.79 0.33279
-2.755 0.351
-2.72 0.36929
-2.685 0.38767
-2.65 0.40612
-2.615 0.42463
-2.58 0.44319
-2.545 0.46179
-2.51 0.48042
-2.5 0.48575
-2.465 0.50442
-2.43 0.52311
-2.395 0.54182
-2.36 0.56055
-2.325 0.57931
-2.29 0.59811
-2.255 0.61695
-2.22 0.63587
-2.185 0.65485
-2.15 0.67392
-2.115 0.69305
-2.08 0.71224
-2.045 0.73147
-2.01 0.75071
-2 0.75622
-1.965 0.77547
-1.93 0.79471
-1.895 0.81394
-1.86 0.83315
-1.825 0.85232
-1.79 0.87147
-1.755 0.89057
-1.72 0.90964
-1.685 0.92867
-1.65 0.94765
-1.615 0.96658
-1.58 0.98547
-1.545 1.0043
-1.51 1.02307
-1.5 1.02843
-1.465 1.04713
-1.43 1.06577
-1.395 1.08436
-1.36 1.10287
-1.325 1.12133
-1.29 1.13971
-1.255 1.15802
-1.22 1.17626
-1.185 1.19443
-1.15 1.21251
-1.115 1.23051
-1.08 1.24843
-1.045 1.26626
-1.01 1.28401
-1 1.28906
-0.965 1.30669
-0.93 1.32423
-0.895 1.34168
-0.86 1.35903
-0.825 1.37628
-0.79 1.39343
-0.755 1.41047
-0.72 1.42742
-0.685 1.44425
-0.65 1.46098
-0.615 1.4776
-0.58 1.49411
-0.545 1.5105
-0.51 1.52679
-0.5 1.53142
-0.465 1.54756
-0.43 1.56359
-0.395 1.57951
-0.36 1.59531
-0.325 1.611
-0.29 1.62656
-0.255 1.64201
-0.22 1.65733
-0.185 1.67252
-0.15 1.68759
-0.115 1.70253
-0.08 1.71734
-0.045 1.73202
-0.01 1.74656
2.00E-12 1.75069
0.035 1.76505
0.07 1.77928
0.105 1.79336
0.14 1.8073
0.175 1.8211
0.21 1.83475
0.245 1.84826
0.28 1.86161
0.315 1.87482
0.35 1.88787
0.385 1.90078
0.42 1.91353
0.455 1.92612
0.49 1.93856
0.525 1.95084
0.56 1.96296
0.595 1.9749
0.63 1.98666
0.665 1.99822
0.7 2.00956
0.735 2.02065
0.77 2.0314
0.805 2.04172
0.84 2.05143
0.875 2.06042
0.91 2.06894
0.945 2.07721
0.98 2.08519
1.015 2.09284
1.05 2.10019
1.085 2.10725
1.12 2.11405
1.155 2.12059
1.19 2.12688
1.225 2.13293
1.26 2.13874
1.295 2.14431
1.33 2.14967
1.365 2.1548
1.4 2.15972
1.435 2.16443
1.47 2.16896
1.505 2.1733
1.54 2.17747
1.575 2.18148
1.61 2.18536
1.645 2.18909
1.68 2.1927
1.715 2.19617
1.75 2.19952
1.785 2.20277
1.82 2.20591
1.855 2.20894
1.89 2.21188
1.925 2.21472
1.96 2.21747
1.995 2.22013
2 2.22051
工作表1
X Y
-5 1.10E-05
-4.9913 1.27E-05
-4.9563 2.26E-05
-4.9213 4.03E-05
XXXXXXXXXX 6.67E-05
XXXXXXXXXX 8.93E-05
XXXXXXXXXX 1.60E-04
XXXXXXXXXX 2.86E-04
XXXXXXXXXX 4.10E-04
XXXXXXXXXX 5.04E-04
XXXXXXXXXX 6.46E-04
-4.745 7.44E-04
-4.71 1.30E-03
-4.675 2.23E-03
-4.64 3.72E-03
-4.605 5.98E-03
-4.57 9.22E-03
-4.535 1.36E-02
-4.5 1.91E-02
-4.49 2.09E-02
-4.455 2.80E-02
-4.42 3.61E-02
-4.385 4.53E-02
-4.35 5.53E-02
-4.315 6.61E-02
-4.28 7.76E-02
-4.245 8.96E-02
-4.21 1.02E-01
-4.175 1.15E-01
-4.14 1.29E-01
-4.105 1.43E-01
-4.07 1.57E-01
-4.035 1.72E-01
-4 1.87E-01
-3.99 1.91E-01
-3.955 2.06E-01
-3.92 2.21E-01
-3.885 2.37E-01
-3.85 0.25273
-3.815 0.26866
-3.78 0.28475
-3.745 0.30098
-3.71 0.31733
-3.675 0.33379
-3.64 0.35036
-3.605 0.36702
-3.57 0.38378
-3.535 0.40061
-3.5 0.41752
-3.49 0.42236
-3.455 0.43935
-3.42 0.4564
-3.385 0.4735
-3.35 0.49065
-3.315 0.50784
-3.28 0.52508
-3.245 0.54234
-3.21 0.55964
-3.175 0.57697
-3.14 0.59432
-3.105 0.61169
-3.07 0.62908
-3.035 0.64648
-3 0.6639
-2.99 0.66887
-2.955 0.6863
-2.92 0.70373
-2.885 0.72117
-2.85 0.7386
-2.815 0.75604
-2.78 0.77347
-2.745 0.7909
-2.71 0.80832
-2.675 0.82573
-2.64 0.84314
-2.605 0.86052
-2.57 0.8779
-2.535 0.89526
-2.5 0.9126
-2.49 0.91755
-2.455 0.93487
-2.42 0.95216
-2.385 0.96944
-2.35 0.98668
-2.315 1.00391
-2.28 1.0211
-2.245 1.03827
-2.21 1.05541
-2.175 1.07251
-2.14 1.08958
-2.105 1.10662
-2.07 1.12362
-2.035 1.14059
-2 1.15752
-1.99 1.16235
-1.955 1.17922
-1.92 1.19606
-1.885 1.21286
-1.85 1.22962
-1.815 1.24633
-1.78 1.263
-1.745 1.27964
-1.71 1.29623
-1.675 1.31278
-1.64 1.32929
-1.605 1.34577
-1.57 1.3622
-1.535 1.3786
-1.5 1.39497
-1.49 1.39964
-1.455 1.41596
-1.42 1.43224
-1.385 1.44849
-1.35 1.4647
-1.315 1.48087
-1.28 1.49701
-1.245 1.5131
-1.21 1.52915
-1.175 1.54516
-1.14 1.56112
-1.105 1.57703
-1.07 1.5929
-1.035 1.60872
-1 1.62448
-0.99 1.62897
-0.955 1.64467
-0.92 1.6603
-0.885 1.67588
-0.85 1.69139
-0.815 1.70683
-0.78 1.72221
-0.745 1.73752
-0.71 1.75275
-0.675 1.7679
-0.64 1