# Plotting data and fitting to a function

I have three sets of data. I would like to plot them in the same graph. Then plot the following fittings to the data. Any help is appreciated!

• f(v) = (v^2)*exp(-mv^2/2 kb T)
• f(v) = (v^3)*exp(-mv^2/2 kb T)

data1:

data = Import[
"/Users/julissavelasquez/Box/1_Harrison Lab/03_Formic \
Acid/Wodtke_2021_Fig4C/Data_Total_Integrated_distribution.xlsx"];

hyperthermal =
Import["/Users/julissavelasquez/Box/1_Harrison Lab/03_Formic \
Acid/Wodtke_2021_Fig4C/Data_Hyperthermal_distribution.xlsx"];

Plot[data, {x, 0, 2}]


Hyperthermal data:

• Welcome to the Mathematica Stack Exchange. Could you please include your data in a copy-paste-able form? Also include any Mathematica code that you have tried out so far as this is a stack site about the technical computing software called Mathematica and the associated Wolfram Language.
– Syed
Commented Feb 28, 2022 at 13:46
• @Syed I believe my data was too much to add in as code. I included a Google Sheets link with the data there. Commented Feb 28, 2022 at 14:12
– Syed
Commented Feb 28, 2022 at 14:22
• @Syed Sorry about that. Please try again. Commented Feb 28, 2022 at 14:24
• The energy in your data is the same everywhere. Then explain better what you want to fit and wich column you want to plot against which column. Commented Feb 28, 2022 at 14:48

data = First[Import["~/Downloads/Data.xlsx", "SkipLines" -> 2]][[1 ;; -2]];

total = data[[All, 1 ;; 2]]
hyper = data[[All, 3 ;; 4]]
thermal = data[[All, 5 ;; 6]]

ListLinePlot[{total, hyper, thermal},
PlotLabels -> {"Total", "Hyper", "Thermal"},
PlotTheme -> "Detailed",
ImageSize -> 600]


The fit is not good the model probably needs adjusting or I have misinterpreted it.

totalFit = NonlinearModelFit[total, (v^2)*Exp[-m v^2/(2 k bt)], {m, k, bt}, v]

Show[ListPlot[total], Plot[totalFit[x], {x, 0, 1.2}], Frame -> True]

Clear["Global*"]

"SkipLines" -> 2][[1]];


Eliminate any missing data

total = data[[All, 1 ;; 2]] /. {"", ""} :> Nothing;


In your model, m/2 kb T acts as a single constant. The split of any derived value into these separate factors is arbitrary. You also need an overall scale factor. Use the model a*(v^n)*Exp[-c v^2] with n being either 2 or 3.

(totalFit2 =
NonlinearModelFit[total, a*(v^2)*Exp[-c v^2], {a, c}, v]) // Normal

(* 11.1953 E^(-4.6119 v^2) v^2 *)

(totalFit3 =
NonlinearModelFit[total, a*(v^3)*Exp[-c v^2], {a, c}, v]) // Normal

(* 37.2111 E^(-6.30875 v^2) v^3 *)

Legended[
Show[
ListLinePlot[total, PlotStyle -> ColorData[97][3]],
Plot[{totalFit2[x], totalFit3[x]}, {x, 0, 1.2}],
Frame -> True],
Placed[
LineLegend[ColorData[97] /@ Range[3], {v^2, v^3, "data"}],
{0.8, 0.7}]]
`