Generate the exponential equation with given table of values

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

thanks sir
,I have edited.I thought it is not required.
Looks pretty simple. DO you have any problems?
sir actually my ques is not about plotting,but to generate mathematical equation
I have only the (x,y) pairs as follows
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
Sorry about the misunderstanding. Is this a practical modeling task, or is this classwork-level stuff? The requirements tend to differ.
yes sir it is practical modeling task.
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
Oh. I didn't see that you'd said it was practical modeling. Yeah. Just use Alex's fit.
Alex,could you please share your code and tell me where you have compiled the code.

Sign in to comment.

Answers (1)

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

sir the equation looks fine.can you please output the values of y0,y1,t.
Just run the above code. It already dumps the estimates for y0, yf, and tau to console.
Hi DGM could you help to get this code ?
y = p1+p2*x+p3/ln(x)
and tell me where you have compiled this code ..
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
these are pair values where we have to find p1,p2,p3.
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
Thanks DGM for your support.Iam grateful to you for your help.
One last question DGM,How can I know that this type of equation will fit to my data in matlab? Is there any procedure to get general equation on matlab? As Alex suggested.

Sign in to comment.

Categories

Asked:

on 1 Apr 2021

Edited:

on 8 Apr 2021

Community Treasure Hunt

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

Start Hunting!