Hi Mathematica Community!
I am very new to Mathematica and I am trying to apply a function which composed of many different functions to 50 lists of dimension {855 rows,3 columns}. I just need some guide on this and I should be able to do the rest. Thanks for spending your time. Appreciated ^_^
* In Line (1), I imported my data in a csv file (a sample is attached to this post) to be used in "NonlinearModelFit" *
syndata = Import["/nsm/home/junhuiye/Documents/Jun/CombinedThermalMelt_h2A.\ csv"]; - (1)
* In Line (2), I generated gaussian white noise to be added to syndata which has a dimension of {50,855,3} => 50 of (855 rows x 3 columns) matrix*
trial = Table[{0, 0, #} & /@ RandomVariate[NormalDistribution[0, i], 855], {i, 0.01, 0.5, 0.01}]; - (2)
* In Line (3), I make 50 copies of syndata to create a {50,855,3} list to add to trial *
syndatasum = Table[syndata, 50]; -(3)
* In Line (4), I created noisy data by adding gaussian white noise to my data=> this will give me 50 lists of 855 rows x 3 columns *
noisydata = trial + syndatasum; -(4)
This part is where I am struggling with. I am trying to apply function f1 to noisydata, but the tricking part is I want to apply f1 to each of the 50 lists of (855 rows x 3 columns) then run to obtain a set of parameters. For instance, Applying f1 to first list of (855 rows x 3 columns) => obtain the fitted parameters and repeat for the next 49 lists of (855x3) matrix and get a set of fitted parameters for each of the list. In the end, I want to combined all these fitted parameters and make it into a table matrix of size ( 50 rows x 11 columns). I don't want to run all 50 lists at the same time because the "NonlinearModelFit" does not allow me to do that. My question is should I pull out Line (5) from the function f1? Is there any other way to approach this problem? Thanks again for your time.
f1:= {
fullData1 =noisydata; - (5)
thetaF[a_, b_, c_, temp_, den_] := a + b*temp + c*den; - (6)
thetaU[d_, e_, f_, g_, temp_, den_] := d + e*temp + f*temp^2 + g*den; - (7)
dG[dH_, dCP_, m_, Tm_, temp_, den_] := dH*(1 - temp/Tm) - dCP*((Tm - temp) + temp*Log[temp/Tm]) + (-m)*den; - (8)
ellip[a_, b_, c_, d_, e_, f_, g_, dH_, dCP_, m_, Tm_, temp_, den_] := (thetaF[a, b, c, temp, den] + thetaU[d, e, f, g, temp, den]* Exp[-dG[dH, dCP, m, Tm, temp, den]/(0.00198*temp)])/(1 + Exp[-dG[dH, dCP, m, Tm, temp, den]/(0.00198*temp)]) - (9)
fullFit = NonlinearModelFit[fullData1, ellip[a, b, c, d, e, f, g, dH, dCP, m, Tm, temp, den], {{a, -49591.2}, {b, 115.462}, {c, -1488.46}, {d, 116936}, {e, -845.923}, {f, 1.37815}, {g, 1800}, {dH, 95}, {dCP, 0.94}, {m, 2}, {Tm, 400}}, {temp, den}] - (10)
fullFit["AdjustedRSquared"] - (11)
fullFit["ParameterTable"] - (12)
fitA = a /. fullFit["BestFitParameters"]; - (13)
fitB = b /. fullFit["BestFitParameters"]; - (14)
fitC = c /. fullFit["BestFitParameters"]; - (15)
fitD = d /. fullFit["BestFitParameters"]; - (16)
fitE = e /. fullFit["BestFitParameters"]; - (17)
fitF = f /. fullFit["BestFitParameters"]; - (18)
fitG = g /. fullFit["BestFitParameters"]; - (19)
fitTm = Tm /. fullFit["BestFitParameters"]; -(20)
TmC = fitTm - 273.15 -(21)
minx = Min[fullData1[[All, {1}]]]; - (22)
maxx = Max[fullData1[[All, {1}]]]; -(23)
miny = Min[fullData1[[All, {2}]]]; - (24)
maxy = Max[fullData1[[All, {2}]]]; - (25)
minz = Min[fullData1[[All, {3}]]]; - (26)
maxz = Max[fullData1[[All, {3}]]]; - (27)
Show[ListPointPlot3D[fullData1], Plot3D[fullFit[x, y], {x, minx, maxx}, {y, miny, maxy}, PlotRange -> {{minx, maxx}, {miny, maxy}, {minz, maxz}}, PlotStyle -> Opacity[0.8], ColorFunction -> (ColorData["TemperatureMap"][#3] &)], MeshStyle -> Gray, PlotRange -> {{minx, maxx}, {miny, maxy},{minz, maxz}}] - (28)
Show[ListPointPlot3D[fullData1],Plot3D[thetaF[fitA, fitB, fitC, x, y], {x, minx, maxx}, {y, miny, maxy}, PlotRange -> {{minx, maxx}, {miny, maxy}, {minz, maxz}}, PlotStyle -> Opacity[0.2]], Plot3D[thetaU[fitD, fitE, fitF, fitG, x, y], {x, minx, maxx}, {y, miny, maxy}, PlotRange -> {{minx, maxx}, {miny, maxy}, {minz, maxz}}, PlotStyle -> Opacity[0.5]], PlotRange -> {{minx, maxx}, {miny, maxy}, {minz, maxz}}] - (29)
}
Attachments: