简体   繁体   中英

Nonlinear fitting function using matlab

I need to fit the curve that you can see in the image, that comes out from a lot of Monte Carlo simulations. I've also uploaded the data to fit in a txt file . 图形

I've tryied to fit the curve with a function of the type :

ax exp(b (x^k))

with k<1 . The results are similar to the experimental points but still far from the fitting function I need.

I've thought to split in different equations the whole range, but I haven't reached a solution yet. Ie a straight line for the fist part and an exponential for the third. But what about the peak?

Any ideas?

I guess your problem is not only to smooth your curve... If it is, nothing is better than a well-chosen polynomial as pointed by @divanov. So, I have nothing to say about that.

However, as I understood your data describes an empirical distribution (you told us that it came from monte carlo simulations) and if you realy want to find a function that describes your data, you might consider to estimate a well-known distribution with a heavy tail.

There are some of them already cooked in matlab toolbox. I suggest you try for instance Weibull distribution , but you might eventually try other kinds.

Polynomial fitting of 8th degree:

close all; clear all;

fid = fopen('output_red.txt','r');
Z = textscan(fid, '%f %f %f %f %f');
fclose(fid);

X = log(Z{1});
Y = log(Z{2});

p = polyfit(X, Y, 8);
Y2 = polyval(p, X);

plot(exp(X), exp(Y));
hold on
plot(exp(X), exp(Y2), 'r')
legend('Original data','Fitted curve')

print('-dpng','fitted.png')

p contains polynomial coefficients 1.2737e-05 -9.1262e-04 2.7838e-02 -4.7160e-01 4.8482e+00 -3.0958e+01 1.1990e+02 -2.5649e+02 2.3480e+02 . Using higher degrees of polynomial will result in better precision.

结果

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM