SetDirectory["/mnt/27817d28-ee1d-4124-ab41-54755c9ee50d/Dydaktyka/TIK_2020_21/Mathematica"]

DataLineFile=Import["line.dat", "Table"]

DataLine=DataLineFile[[All, {1,2}]]

ErrorLine=DataLineFile[[All, {3}]]

DataLinePlot=ListPlot[DataLine]

Needs["ErrorBarPlots`"]

DataLinePlotErrors=ErrorListPlot[{{{-9,-6.84307},ErrorBar[1]},{{-7.5,-5.34808},ErrorBar[0.2]},{{-2.5,-0.811542},ErrorBar[0.7]},{{-0.5,-1.22456},ErrorBar[0.5]},{{1.5,1.24481},ErrorBar[1.8]},{{3,3.19375},ErrorBar[1.1]},{{5.5,4.8006},ErrorBar[0.3]},{{8.5,7.47098},ErrorBar[1.2]}}]

Show[DataLinePlotErrors,AxesLabel->{HoldForm[X axis],HoldForm[Y axis]}]

lm=LinearModelFit[DataLine, {1,x}, x]

lm["ParameterTable"]

lmFitPlot=Plot[lm["BestFit"],{x,-10,10},PlotStyle->Red]

Show[DataLinePlotErrors, lmFitPlot]

Export["lmFitPlotParameters.dat", {lm["BestFitParameters"],lm["ParameterErrors"]},"Table"]

DataIkarusFile=Import["ikarus.dat", "Table"]

{{20.9`,5.26`,0.5`},{36.9`,7.12`,0.5`},{12.54`,4.01`,0.5`},{12.54`,4.1`,0.5`},{12.54`,3.73`,0.5`},{8.36`,3.63`,0.5`},{24.36`,6.56`,0.5`},{16.72`,4.83`0.5`},{32.72`,6.91`,0.5`}}

DataIkarusPlot=ListPlot[{{20.9, Around[5.26, 0.5]},{36.9, Around[7.12, 0.5]}, {12.54, Around[4.01, 0.5]}, {8.36, Around[3.36, 0.5]}, {24.36, Around[6.56, 0.5]},{16.72, Around[4.83, 0.5]}, {32.72, Around[6.91, 0.5]}}]

DataIkarus=DataIkarusFile[[All, {1,2}]]

nlm=NonlinearModelFit[DataIkarus, a*(x^3)+b*(x^2)+c*x+d, {a,b,c,d}, x]

nlm["ParameterTable"]

nlmFitPlot=Plot[nlm["BestFit"],{x,8,37}, PlotStyle->Red]

Show[DataIkarusPlot, nlmFitPlot]

Export["nlmFitPlotParameters.dat",Transpose[{nlm["BestFitParameters"][[All,2]],nlm["ParameterErrors"]}],"Table"]