# How do i make an exponential curve graph from a vector?

3 views (last 30 days)
Emil-Sebastian BURAGA on 30 Nov 2023
Edited: John D'Errico on 30 Nov 2023
How do i make a graph that looks like this from the following code
I tried fitnlm or polyval or polyfit but i don't know if i'm not using the right functions or i just don't understand how to use them.
Teta1 = [0 19.727 25.705 28.796 30.154 31.375 31.787 31.961 31.164 32.504 32.285];
Teta2 = [0 11.356 17.764 21.162 22.806 23.712 24.292 24.573 24.765 24.826 24.753];
Teta3 = [0 10.239 15.604 18.588 20.312 21.164 21.579 21.671 21.896 21.820 21.750];
Teta4 = [0 20.346 28.186 32.687 35.272 26.975 37.823 38.785 38.794 39.194 39.240];
Teta5 = [0 11.957 20.023 24.820 27.567 29.355 30.386 31.244 31.458 31.830 31.772];
Teta6 = [0 10.803 17.642 22.031 24.655 26.389 27.414 27.884 28.064 28.299 28.152];

John D'Errico on 30 Nov 2023
Edited: John D'Errico on 30 Nov 2023
You can't have a polynomial that will fit that curve shape. They simply do not have that characteristic form. So using polyfit (and polyval) is therefore a waste of time.
t = (0:5:50)';
Teta1 = [0 19.727 25.705 28.796 30.154 31.375 31.787 31.961 31.164 32.504 32.285];
plot(t,Teta1,'o')
We see one of your curves above.As a first guess, a negative expoential model tht rises to a constant asymptote seems a good start.
mdl = fittype('a-b*exp(-t/c)','indep','t')
mdl =
General model: mdl(a,b,c,t) = a-b*exp(-t/c)
fittedmdl = fit(t,Teta1',mdl,'start',[30 30 10])
fittedmdl =
General model: fittedmdl(t) = a-b*exp(-t/c) Coefficients (with 95% confidence bounds): a = 31.76 (31.12, 32.39) b = 31.5 (29.85, 33.15) c = 5.688 (4.991, 6.385)
plot(fittedmdl,'b-')
hold on
plot(t,Teta1,'ro')
hold off
And we see at least a reasonable fit. Do the same for each of your curves.
Is that the correct choice of model? Well, probably not perfect. I would note that it is not constrained to pass exactly through zero at t==0. mdl2 does that.
mdl2 = fittype('a*(1-exp(-t/b))','indep','t')
mdl2 =
General model: mdl2(a,b,t) = a*(1-exp(-t/b))
fittedmdl2 = fit(t,Teta1',mdl2,'start',[30 10])
fittedmdl2 =
General model: fittedmdl2(t) = a*(1-exp(-t/b)) Coefficients (with 95% confidence bounds): a = 31.75 (31.15, 32.34) b = 5.643 (5.044, 6.241)
plot(fittedmdl2,'b-')
hold on
plot(t,Teta1,'ro')
The fit is similar in quality, but now it passes exactly through 0 at t==0. My guess is that would be your goal.

### Categories

Find more on Interpolation in Help Center and File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!