I have defined two functions to fit $\dfrac{a}{\sqrt{x^2-b^2}}$ and $\dfrac{a}{\sqrt{b^2-x^2}}$.
fitSingularity[listFit_] :=
Module[{res, startVal1, model, a, b, fit},
startVal1 = listFit[[1]][[1]]; Print[startVal1];
res = Sqrt[(listFit[[6]][[1]]^2 - startVal1^2)]*listFit[[6]][[2]];
model = a/Sqrt[(x^2 - b^2)];
fit = FindFit[listFit[[2 ;; -1]],
model, {{a, res}, {b, startVal1}}, x];
a = a /. fit;
b = b /. fit;
{a, b}
];
fitSingularity2[listFit_] := Module[{res, startVal1, model, a, b, fit},
startVal1 = listFit[[-1]][[1]]; Print[N[startVal1]];
res = Sqrt[(startVal1^2 - listFit[[6]][[1]]^2)]*listFit[[6]][[2]];
Print[N[res]];
model = a/Sqrt[(b^2 - x^2)];
fit = FindFit[listFit[[2 ;; -1]],
model, {{a, res}, {b, startVal1}}, x];
a = a /. fit;
b = b /. fit;
{a, b}
];
To realize the fits I create a list. In the first case with the following code everything is working nicely
g[x_] := a/Sqrt[x^2 - b^2]
a = 1; b = 2;
list1 = Table[{x, g[x]}, {x, 1.999, 4, 0.1}];
Show[Plot[g[x], {x, 2, 4}], ListPlot[list1, PlotStyle -> Green]]
fitSingularity[list1]
But in the second case I obtain an error and I do not know why (it should not be so different than for the first case)
f[x_] := a/Sqrt[b^2 - x^2]
a = 1; b = 2;
list2 = Table[{x, f[x]}, {x, 0, 1.999, 0.01}];
Show[Plot[f[x], {x, 0, 2}], ListPlot[list2, PlotStyle -> Green]]
fitSingularity2[list2]
I would like to mention that I implement this to be sure I can fit the function well, but I need to use this fit in a much more complicated case (inside a numerical function that is supposed to have a singularity of the form $\dfrac{a}{\sqrt{x^2-b^2}}$ or $\dfrac{a}{\sqrt{b^2-x^2}}$)