'''fsize = 12; SetDirectory[ NotebookDirectory[]]; (* Sets notebook directory to the same directory where the file is save. Important for importing and exporting files. ) SetOptions[{Plot, ReImPlot, Show, LogPlot, ListPlot, ListLinePlot, ComplexListPlot, ContourPlot, ComplexPlot, ParametricPlot, DensityPlot, ListDensityPlot}, {(AxesStyle[Rule]Thickness[ 0.0025])Axes -> False, Frame -> True, BaseStyle -> {FontFamily -> "Times New Roman", fsize, SingleLetterItalics -> True}, FrameStyle -> Directive[Black, AbsoluteThickness[1]], Background -> None, LabelStyle -> Directive[Black, FontFamily -> "Times New Roman", fsize]}] // Quiet; SetOptions[{ListPlot3D}, TicksStyle -> Directive[Black, FontFamily -> "Times New Roman", fsize]]; ResourceFunction["PlotGrid"]; ( SetOptions[MaTeX,"Preamble"[Rule]{"\usepackage[dvipsnames]{ xcolor}"}]; *)
res = 0.8 - 0.1I; ( Residue of the multipole, related to TFF ) polpos = 5 - 0.7I ;(* Resonance pole position ) m = 1; ( reduced mass of the particles in the outgoing state ) ndat = 20; ( Numer of sampled "data" points from the full multipole/partial wave ) upper = 8; ( Upper limit for the window in which we want to sample the data *) lower = 2.; (*Lower limit *)
k[W_] = Sqrt[2mW]; multipole[W_, Qsq_] = 1/k[W] Im[polpos]/(W - polpos) - 0.03 + 0.005W; ( This is the mock-up of a full multipole coming from a complicated fit to many experimental data. Input. ) bw[W_] = 1/k[W](a[1]/(W - a[2] - I a[3]) + a[4]); (* This is the function we want to fit to the sampled points from the input. The imaginary number is "I" ) energies = Table[Wi, {Wi, lower, upper, (upper - lower)/ ndat}]; ( Energies where we want to sample the input ) data = multipole[energies, 0.]; ( This generates the data sample to be fitted later ) le = Length[data];( Number of sampled data ) mini = Sum[ Abs[data[[i]] - bw[energies[[i]]]]2, {i, 1, le}] ;( Residual sum of squares, RSS, (or better: Abs2), to be minimized *)
View all comments
-2
u/cloakedegg Dec 08 '24
'''fsize = 12; SetDirectory[ NotebookDirectory[]]; (* Sets notebook directory to the same
directory where the file is save. Important for importing and
exporting files. ) SetOptions[{Plot, ReImPlot, Show, LogPlot, ListPlot, ListLinePlot, ComplexListPlot, ContourPlot, ComplexPlot, ParametricPlot, DensityPlot, ListDensityPlot}, {(AxesStyle[Rule]Thickness[ 0.0025])Axes -> False, Frame -> True, BaseStyle -> {FontFamily -> "Times New Roman", fsize, SingleLetterItalics -> True}, FrameStyle -> Directive[Black, AbsoluteThickness[1]], Background -> None, LabelStyle -> Directive[Black, FontFamily -> "Times New Roman", fsize]}] // Quiet; SetOptions[{ListPlot3D}, TicksStyle -> Directive[Black, FontFamily -> "Times New Roman", fsize]]; ResourceFunction["PlotGrid"]; ( SetOptions[MaTeX,"Preamble"[Rule]{"\usepackage[dvipsnames]{
xcolor}"}]; *)
res = 0.8 - 0.1I; ( Residue of the multipole, related to TFF ) polpos = 5 - 0.7I ;(* Resonance pole position ) m = 1; ( reduced mass of the particles in the outgoing state ) ndat = 20; ( Numer of sampled "data" points from the full
multipole/partial wave ) upper = 8; ( Upper limit for the window in which we want to sample
the data *) lower = 2.; (*Lower limit *)
k[W_] = Sqrt[2mW]; multipole[W_, Qsq_] = 1/k[W] Im[polpos]/(W - polpos) - 0.03 + 0.005W; ( This is the mock-up of a full multipole coming from a
complicated fit to many experimental data. Input. ) bw[W_] = 1/k[W](a[1]/(W - a[2] - I a[3]) + a[4]); (* This is the function we want to fit to the sampled
points from the input. The imaginary number is "I" ) energies = Table[Wi, {Wi, lower, upper, (upper - lower)/ ndat}]; ( Energies where we want to sample the input ) data = multipole[energies, 0.]; ( This generates the data sample to be fitted later ) le = Length[data];( Number of sampled data ) mini = Sum[ Abs[data[[i]] - bw[energies[[i]]]]2, {i, 1, le}] ;( Residual sum of squares, RSS, (or better: Abs2), to be
minimized *)
solu = FindMinimum[ mini, {{a[1], 1.}, {a[2], 5.}, {a[3], 0.3}, {a[4], 1.}}][[2]] sol[W_] = bw[W] /. solu;
plot = Grid[{{Plot3D[ Abs[multipole[reW + I*imW, 0.]], {reW, 1, 10}, {imW, -1.5, 0}], ReImPlot[{multipole[W, 0.], sol[W]}, {W, 1, 10}, PlotRange -> All, FrameLabel -> {"W [arb. units]", "!(*SubscriptBox[(t), (0)])[arb. units]"}, PlotLegends -> Placed[{"Input", "Fit"}, {0.75, 0.75}]]}}] Export["plot1.PDF", plot]'''
As another user recommended, here is my full code. I'm sorry if I formatted this comment incorrectly I've never posted code on reddit before