Generate the exponential equation with given table of values
Show older comments
Iam new to the matlab.Iam learning this for my project sake.
Generate the exponential equation with given (x,y) pairs(around 10 pairs).
y = 1-exp(-b.x)
thank you in advance
10 Comments
darova
on 1 Apr 2021
Where is the equation?
darova
on 3 Apr 2021
Looks pretty simple. DO you have any problems?
ajith m
on 4 Apr 2021
DGM
on 4 Apr 2021
Sorry about the misunderstanding. Is this a practical modeling task, or is this classwork-level stuff? The requirements tend to differ.
ajith m
on 5 Apr 2021
Alex Sha
on 5 Apr 2021
Hi, the fitting function below is good enough, with simple exppression:
y = p1+p2*x+p3/ln(x)
Root of Mean Square Error (RMSE): 3.28910238013225
Sum of Squared Residual: 227.182083806824
Correlation Coef. (R): 0.999081359523416
R-Square: 0.998163562947156
Parameter Best Estimate
---------- -------------
p1 839.058520362562
p2 -0.0177908169055552
p3 -220.872803253474

DGM
on 5 Apr 2021
Oh. I didn't see that you'd said it was practical modeling. Yeah. Just use Alex's fit.
ajith m
on 5 Apr 2021
Answers (1)
DGM
on 4 Apr 2021
Let's try this again. For the moment, I'm going to assume this is classwork. If this is a more practical data modeling problem, there are surely more robust methods that someone can recommend. If you have cftool() you could try that.
Assuming that we're reasonably assured that our points adhere to the prescribed model, all we need to do are find its parameters. Without any suggestion as to the preferred method, a crude homework-esque way to solve it would be something like this:
We have our equation with three unknowns.
We could assume some value for
, but we can just solve for them all
% nevermind that i imported the array striped like this
a=[926.15031 790.63353 691.94421 793.58274 498.2735 793.58274 309.66558 793.58274 192.45007 793.58274 128.7446 790.63353 92.70982 790.63353 59.77833 787.68433 39.9903 779.08247 26.75258 767.28564 19.20568 764.33643 14.34892 755.4888 10.33275 740.98853 7.71979 729.1917 5.54204 708.79301 4.14056 685.19934 3.32993 658.90224 2.76994 629.65593 2.57326 606.30803 2.30412 576.81595 2.22764 553.46805];
x=fliplr(a(1:2:end));
y=fliplr(a(2:2:end));
sp=[1 14 20]; % pick which points we want to sample
syms y0 yf tau
e1=y(sp(1)) == yf - y0*exp(-1/tau * x(sp(1)));
e2=y(sp(2)) == yf - y0*exp(-1/tau * x(sp(2)));
e3=y(sp(3)) == yf - y0*exp(-1/tau * x(sp(3)));
S = solve([e1 e2 e3],[y0 yf tau]);
% convert syms to numeric
y0est=double(S.y0)
yfest=double(S.yf)
tauest=double(S.tau)
% plot the estimated curve versus the data
y2=yfest-y0est*exp(-1/tauest*x);
plot(x,y,'ko');hold on;
plot(x,y2,'m')
The fit isn't great, but it's probably sufficient for the assignment. Fitting this way depends heavily on the points chosen.

6 Comments
ajith m
on 5 Apr 2021
DGM
on 5 Apr 2021
Just run the above code. It already dumps the estimates for y0, yf, and tau to console.
ajith m
on 7 Apr 2021
DGM
on 7 Apr 2021
Alex already gave you p1,p2,p3. If you want to know how he got them, you can use cftool() or fit() if you have the Curve Fitting Toolbox.
a=[926.15031 790.63353 691.94421 793.58274 498.2735 793.58274 309.66558 793.58274 192.45007 793.58274 128.7446 790.63353 92.70982 790.63353 59.77833 787.68433 39.9903 779.08247 26.75258 767.28564 19.20568 764.33643 14.34892 755.4888 10.33275 740.98853 7.71979 729.1917 5.54204 708.79301 4.14056 685.19934 3.32993 658.90224 2.76994 629.65593 2.57326 606.30803 2.30412 576.81595 2.22764 553.46805];
x=fliplr(a(1:2:end));
y=fliplr(a(2:2:end));
plot(x,y,'o')
thisfit=fit(x',y','a+b*x-c/log(x)');
a=thisfit.a
b=thisfit.b
c=thisfit.c
y2=a + b*x - c./log(x);
hold on; plot(x,y2)
This gives the same parameters Alex gave.
a =
839.0585
b =
-0.0178
c =
-220.8728

ajith m
on 8 Apr 2021
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!