Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
类似吸收光谱的吸收峰
ClearAll["Global`*"];
dataNoOutlier = {{0.100790000000000,
133.050000000000}, {0.102310000000000,
129.050000000000}, {0.103850000000000,
125.500000000000}, {0.105410000000000,
122.530000000000}, {0.107000000000000,
121.100000000000}, {0.115290000000000,
105.700000000000}, {0.117020000000000,
99.9060000000000}, {0.118780000000000,
95.8610000000000}, {0.120570000000000,
92.4610000000000}, {0.122380000000000,
89.3910000000000}, {0.124220000000000,
86.5270000000000}, {0.126090000000000,
83.8090000000000}, {0.127990000000000,
81.2120000000000}, {0.129910000000000,
78.7170000000000}, {0.131870000000000,
76.3090000000000}, {0.133850000000000,
73.9810000000000}, {0.135860000000000,
71.7280000000000}, {0.137910000000000,
69.5510000000000}, {0.139980000000000,
67.4330000000000}, {0.142090000000000,
65.3750000000000}, {0.144220000000000,
63.4060000000000}, {0.146390000000000,
61.5230000000000}, {0.148600000000000,
59.7210000000000}, {0.150830000000000,
57.9950000000000}, {0.153100000000000,
56.3570000000000}, {0.155400000000000,
54.8510000000000}, {0.157740000000000,
53.6630000000000}, {0.167450000000000,
47.7930000000000}, {0.169970000000000,
46.0160000000000}, {0.172520000000000,
44.5390000000000}, {0.175120000000000,
43.1740000000000}, {0.177750000000000,
41.8740000000000}, {0.180420000000000,
40.6230000000000}, {0.183140000000000,
39.4200000000000}, {0.185890000000000,
38.2900000000000}, {0.188690000000000,
37.4120000000000}, {0.191530000000000,
36.3630000000000}, {0.194410000000000,
34.9350000000000}, {0.197330000000000,
33.7750000000000}, {0.200300000000000,
32.7020000000000}, {0.203310000000000,
31.6730000000000}, {0.206370000000000,
30.6830000000000}, {0.209470000000000,
29.7090000000000}, {0.212620000000000,
28.7550000000000}, {0.215820000000000,
27.8320000000000}, {0.219070000000000,
26.9400000000000}, {0.222360000000000,
26.0750000000000}, {0.225710000000000,
25.2370000000000}, {0.229100000000000,
24.4240000000000}, {0.232550000000000,
23.6430000000000}};(*去除异常点的数据*)
dataWithOutlier = {{0.100790000000000,
133.050000000000}, {0.102310000000000,
129.050000000000}, {0.103850000000000,
125.500000000000}, {0.105410000000000,
122.530000000000}, {0.107000000000000,
121.100000000000}, {0.108610000000000,
127.530000000000}, {0.110240000000000,
199.390000000000}, {0.111900000000000,
204.970000000000}, {0.113580000000000,
119.440000000000}, {0.115290000000000,
105.700000000000}, {0.117020000000000,
99.9060000000000}, {0.118780000000000,
95.8610000000000}, {0.120570000000000,
92.4610000000000}, {0.122380000000000,
89.3910000000000}, {0.124220000000000,
86.5270000000000}, {0.126090000000000,
83.8090000000000}, {0.127990000000000,
81.2120000000000}, {0.129910000000000,
78.7170000000000}, {0.131870000000000,
76.3090000000000}, {0.133850000000000,
73.9810000000000}, {0.135860000000000,
71.7280000000000}, {0.137910000000000,
69.5510000000000}, {0.139980000000000,
67.4330000000000}, {0.142090000000000,
65.3750000000000}, {0.144220000000000,
63.4060000000000}, {0.146390000000000,
61.5230000000000}, {0.148600000000000,
59.7210000000000}, {0.150830000000000,
57.9950000000000}, {0.153100000000000,
56.3570000000000}, {0.155400000000000,
54.8510000000000}, {0.157740000000000,
53.6630000000000}, {0.160110000000000,
54.6140000000000}, {0.162520000000000,
63.3660000000000}, {0.164970000000000,
51.4550000000000}, {0.167450000000000,
47.7930000000000}, {0.169970000000000,
46.0160000000000}, {0.172520000000000,
44.5390000000000}, {0.175120000000000,
43.1740000000000}, {0.177750000000000,
41.8740000000000}, {0.180420000000000,
40.6230000000000}, {0.183140000000000,
39.4200000000000}, {0.185890000000000,
38.2900000000000}, {0.188690000000000,
37.4120000000000}, {0.191530000000000,
36.3630000000000}, {0.194410000000000,
34.9350000000000}, {0.197330000000000,
33.7750000000000}, {0.200300000000000,
32.7020000000000}, {0.203310000000000,
31.6730000000000}, {0.206370000000000,
30.6830000000000}, {0.209470000000000,
29.7090000000000}, {0.212620000000000,
28.7550000000000}, {0.215820000000000,
27.8320000000000}, {0.219070000000000,
26.9400000000000}, {0.222360000000000,
26.0750000000000}, {0.225710000000000,
25.2370000000000}, {0.229100000000000,
24.4240000000000}, {0.232550000000000,
23.6430000000000}};(*含异常点的数据*)
outlier = {{0.108610000000000,
127.530000000000}, {0.110240000000000,
199.390000000000}, {0.111900000000000,
204.970000000000}, {0.113580000000000,
119.440000000000}, {0.115290000000000,
105.700000000000}, {0.117020000000000,
99.9060000000000}, {0.160110000000000,
54.6140000000000}, {0.162520000000000,
63.3660000000000}, {0.157740000000000,
53.6630000000000}, {0.164970000000000,
51.4550000000000}}(*异常点*)(*{x,0.10861,0.16497}*)
outlierTheFirstPeak = {{0.108610000000000,
127.530000000000}, {0.110240000000000,
199.390000000000}, {0.111900000000000,
204.970000000000}, {0.113580000000000,
119.440000000000}, {0.115290000000000,
105.700000000000}, {0.117020000000000, 99.9060000000000}};
outlierTheSecondPeak = {{0.160110000000000,
54.6140000000000}, {0.162520000000000,
63.3660000000000}, {0.157740000000000,
53.6630000000000}, {0.164970000000000, 51.4550000000000}};
mainModel = a Exp[b*x] + c;
dfit = FindFit[dataNoOutlier, mainModel, {a, b, c}, x,
MaxIterations -> 1000000];
Show[ListPlot[dataWithOutlier],
Plot[mainModel /. dfit, {x, 0.10079, 0.23255}, PlotRange -> All,
PlotStyle -> Red]];
yValueOfTheFirstPeak =
outlierTheFirstPeak[[All,
2]] - (mainModel /.
dfit /. {x -> outlierTheFirstPeak[[All, 1]]});
yValueOfTheSecondPeak =
outlierTheSecondPeak[[All,
2]] - (mainModel /. dfit /. {x -> outlierTheSecondPeak[[All, 1]]});
firstPeak =
FindFit[{outlierTheFirstPeak[[All, 1]], yValueOfTheFirstPeak} //
Transpose, d Exp[-e (x - 0.111)^2], {d, e}, x];
Show[ListPlot[{outlierTheFirstPeak[[All, 1]], yValueOfTheFirstPeak} //
Transpose, PlotStyle -> Red],
Plot[d Exp[-e (x - 0.111)^2] /. firstPeak, {x, 0.10861`, 0.11702`}],
PlotRange -> All]
secondPeak =
FindFit[{outlierTheSecondPeak[[All, 1]], yValueOfTheSecondPeak} //
Transpose, h Exp[-g (x - 0.1625)^2], {h, g}, x];
Show[ListPlot[{outlierTheSecondPeak[[All, 1]],
yValueOfTheSecondPeak} // Transpose, PlotStyle -> Red,
PlotRange -> All],
Plot[h Exp[-g (x - 0.1625)^2] /. secondPeak, {x, .15, 0.17}]]
overallFitFunction := (mainModel /.
dfit) + (d Exp[-e (x - 0.111)^2] /.
firstPeak) + (h Exp[-g (x - 0.1625)^2] /. secondPeak);
Show[ListPlot[dataWithOutlier, PlotRange -> All],
Plot[overallFitFunction, {x, 0.09, 0.23}, PlotStyle -> Red,
PlotRange -> All]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.