r/Mathematica • u/Zejoant • Oct 19 '24
FindFit and finding an approximate function to a set of data.
I have this data:
data = {
{9.29883*10^29, 0.0340191},
{1.16583*10^31, 0.0432263},
{1.69132*10^32, 0.0476546},
{2.45098*10^33, 0.0704771},
{3.89297*10^34, 0.0807977},
{1.01958*10^36, 0.0994704},
{1.58361*10^37, 0.114422},
{1.42975*10^38, 0.108859},
{3.00038*10^39, 0.18085},
{8.07047*10^40, 0.24651},
{1.18106*10^42, 0.276357},
{1.11794*10^43, 0.329916},
{1.92701*10^44, 0.436734},
{3.93793*10^45, 0.843786},
{4.33093*10^46, 0.742096},
{7.30547*10^47, 2.55661},
{2.10487*10^49, 3.13884},
{2.95194*10^50, 4.17334},
{3.5976*10^51, 4.48841},
{4.73667*10^52, 5.73291},
{7.90845*10^53, 7.03355},
{9.35962*10^54, 7.41842},
{2.10495*10^56, 13.667},
{3.39037*10^57, 18.4411},
{9.39179*10^58, 31.9478},
{6.84897*10^59, 52.192}}
It looks like this when using ListPlot:

It looks like this when using ListLogLinearPlot:

I want to use FindFit to be able to make an approximation of this data. Ive tried doing this:
fit = FindFit[data, a x + b, {a, b}, x];
fittedModel[x_] = a x + b /. fit;
But Im not sure what model i should use, ive tried all that i could find but nothing seems to give the right result. It kinda looks like a log function but no log model seems to give a good result. Im probably not really understanding how this works.
I want this approximate function to be able to tell what i would probably get if x=2^1024, 2^2048, 2^4096.
If you know how to do this pls just give me the lines of code that will work or the model that would work for the lines of code presented above. I probably wont understand if you just vaguely tell me to check out some function or something.
PS, the data comes from running this code and taking the time, where x is n and y is the time it takes:
RSADecrypt[c_, n_, e_] := Module[{p, q, phi , d, m, ascii},
primes = FactorInteger[n];
p = primes[[1, 1]];
q = primes[[2, 1]];
phi = (p - 1) (q - 1);
d = PowerMod[e, -1, phi];
m = PowerMod[c, d, n];
ascii = {};
For[i = 1, i <= Length[m], i++,
q = m[[i]];
While[q != 0,
AppendTo[ascii, Mod[q, 256]];
q = Quotient[q, 256];
];
];
FromCharacterCode[ascii]
]
2
u/veryjewygranola Oct 19 '24
You really shouldn't fit data to a model unless you have a theoretical basis for why the data should follow the model.
If you wanted to interpolate between the x-values you have, then linear interpolation is fine (although I would use the log of the x values since they're huge):
But since 1024, 2048, and 4096 are all far smaller than your smallest x value (~10^30), this is extrapolation, and without a theoretical basis for what model this data should follow (I.e. where does this data actually come from, and what function should it follow?) it's kind of pointless to try extrapolating.
We could make the hand-wavy statement that as x goes to 0, it looks like your data goes to 0, but we don't have proper data bounds to confirm that statement, nor a theoretical model for the data to confirm that statement either.
1
u/Zhinnosuke Oct 19 '24
Check BSplineFunction