# Fit Gaussian Function [duplicate]

I want to fit the Gaussian Function for the following data. How should I do it?

x={1000., 1006., 1012., 1018., 1024., 1030., 1036., 1042., 1048., 1054., \
1060., 1066., 1072., 1078., 1084., 1090., 1096., 1102., 1108., 1114., \
1120., 1126., 1132., 1138., 1144., 1150., 1156., 1162., 1168., 1174., \
1180., 1186., 1192., 1198., 1204., 1210., 1216., 1222., 1228., 1234., \
1240., 1246., 1252., 1258., 1264., 1270., 1276., 1282., 1288., 1294., \
1300., 1306., 1312., 1318., 1324., 1330., 1336., 1342., 1348., 1354., \
1360., 1366., 1372., 1378., 1384., 1390., 1396., 1402., 1408., 1414., \
1420., 1426., 1432., 1438., 1444., 1450., 1456., 1462., 1468., 1474., \
1480., 1486., 1492., 1498., 1504., 1510., 1516., 1522., 1528., 1534., \
1540., 1546., 1552., 1558., 1564., 1570., 1576., 1582., 1588., 1594., \
1600., 1606., 1612., 1618., 1624., 1630., 1636., 1642., 1648., 1654., \
1660., 1666., 1672., 1678., 1684., 1690., 1696., 1702.};

y={-0.000380366, 0.0000407403, 0.000418581, 0.000304345, 0.000352654, \
0.000783798, -0.000186571, 0.000298195, 0.000371236, 0.000342887, \
0.000816699, 0.000990867, 0.001874, 0.00205223, 0.00244626, 0.003064, \
0.00318061, 0.00364765, 0.00435385, 0.00496345, 0.00603876, \
0.00666037, 0.00719425, 0.00866786, 0.00919913, 0.0105237, 0.0113344, \
0.0202876, 0.0223899, 0.0257928, 0.027938, 0.0315634, 0.0351888, \
0.0398218, 0.0444764, 0.049403, 0.0545489, 0.0616718, 0.0681623, \
0.0758158, 0.0843551, 0.0924852, 0.103369, 0.113532, 0.125847, \
0.137736, 0.151215, 0.165321, 0.180954, 0.19694, 0.21535, 0.233772, \
0.252941, 0.272774, 0.29175, 0.313005, 0.335505, 0.355652, 0.37437, \
0.390858, 0.408765, 0.425316, 0.451271, 0.470542, 0.488677, 0.492997, \
0.515049, 0.525605, 0.542021, 0.553706, 0.56424, 0.572244, 0.578313, \
0.581318, 0.581163, 0.578212, 0.578359, 0.574223, 0.567869, 0.557928, \
0.547087, 0.536067, 0.526951, 0.513881, 0.502051, 0.485491, 0.471461, \
0.45331, 0.436724, 0.423719, 0.405601, 0.38823, 0.37273, 0.355018, \
0.338698, 0.323699, 0.30779, 0.291229, 0.277558, 0.262647, 0.247922, \
0.235271, 0.223318, 0.210333, 0.197343, 0.186487, 0.174935, 0.165664, \
0.155376, 0.144488, 0.13323, 0.121143, 0.109417, 0.101554, 0.0944399, \
0.0892536, 0.0894286, 0.0883779};


## marked as duplicate by anderstood, Henrik Schumacher, José Antonio Díaz Navas, m_goldberg, J. M. will be back soon♦Oct 15 '18 at 19:23

• What have you tried so far? – user6014 Oct 15 '18 at 1:24
• Something like: NonlinearModelFit[Data,Model,{param1,Param2...},variable] You should look at the documentation for NonlinearModelFit[...] – Q.P. Oct 15 '18 at 1:26
• Your x and y should be lists, i.e., enclosed in list brackets x = { ... }; y = { ... }; You can shorten the definition of x to x == Range[1000., 1702., 6] – Bob Hanlon Oct 15 '18 at 1:35

data = Transpose[{x, y}];

Clear[a, b, c, m]

nlm = NonlinearModelFit[
data, {a*Exp[-(t - m)^2/(2 b^2)] + c, a > 0, b > 0, 0 < c < 1,
1432 < m < 1456}, {a, b, c, m}, t];

nlm[t]

(* 0.00166378 + 0.569323 E^(-0.0000394541 (-1453.53 + t)^2) *)

Plot[nlm[t], {t, x[[1]], x[[-1]]},
Frame -> True, Axes -> False,
Epilog -> {Red, AbsolutePointSize[2], Point[data]}]


• Thank you very much – Tharaka Oct 15 '18 at 3:29