exponential fitting to limited data

Here is my data :
y=[2.5648 1.2495 1.1663 1.0652 2.1537 1.3080 1.2624 1.2949]
I want to fit an exponential function to them. attached is the figure that I came up and doesn't make any sense to me.
f = @(b,x) b(1).*exp(b(2).*x)+b(3);
B = fminsearch(@(b) norm(y - f(b,x)), [-2; -1; 1]) ;
figure
plot(x, y, 'ro','MarkerFaceColor','r')
hold on
plot(x, f(B,x), '-b','linewidth', 3)
hold off

Antworten (2)

Star Strider
Star Strider am 8 Okt. 2020

0 Stimmen

It needs to be changed slightly, adding an additional parameter:
x = 35:5:70;
y = [2.5648 1.2495 1.1663 1.0652 2.1537 1.3080 1.2624 1.2949];
f = @(b,x) b(1).*exp(b(2).*(x-b(4)))+b(3);
B = fminsearch(@(b) norm(y - f(b,x)), [1; -1; 1; 35]) ;
figure
plot(x, y, 'ro','MarkerFaceColor','r')
hold on
plot(x, f(B,x), '-b','linewidth', 3)
hold off
Then, it is a bit more understandable, althoug still not an excellent fit.

4 Kommentare

Mos_bad
Mos_bad am 9 Okt. 2020
Is there any way to get a more smooth curve?
Image Analyst
Image Analyst am 9 Okt. 2020
Why do you think any curve will fit this data?
Why are you not telling us the context for this data??? Where did it come from? What does it represent? What do you think the curve SHOULD look like IF you had been able to collect enough data points? An exponential? Two Gaussians or spikes? Why is there an apparent outlier at x=55?
Mos_bad
Mos_bad am 9 Okt. 2020
Long story short, each data point comes from 1000 Monte carlo simulations and based on the logic behind the concept, it should look like as attached. I guesses exponential may be the best function describing the data decaying over time. BTW, thanks for asking fundamental questions, it had me rethought about it.
Star Strider
Star Strider am 9 Okt. 2020
That is about the best that function can do with those data.

Melden Sie sich an, um zu kommentieren.

Walter Roberson
Walter Roberson am 9 Okt. 2020

0 Stimmen

Your proposed function is a quite bad fit for your data.
With your function, the optimal fit drives b(2) to roughly -4 so you are dealing with an exp(-4*(35:5:70)) which gives you values that are non-zero for the first result and effectively zero by comparison for the others results. Then b(1) is driven to about 1e100 to balance out the exp(-4*35) to give a notable value for the first entry and effective zeros for the rest. Your fitting then becomes "non-trivial value for x = 35, zeros for the rest" plus b(3) -- so all of the fitting is going into matching the first datapoint, and the exp() makes the rest of them into noise.
I said above roughly -4 and about 1e100 but you can get slightly better fits by driving b(1) to 1e200 and b(2) about -6.4 which has the effect of lowering the contributions of the other entries even further towards 0.
So.. you get a pulse and a straight line.
Star Strider's idea of subtracting something from x is a decent one.

1 Kommentar

Mos_bad
Mos_bad am 9 Okt. 2020
Thnaks for the clarification. I spent the whole day on this curve fitting and still haven't got the nice one.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 8 Okt. 2020

Kommentiert:

am 9 Okt. 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by