How to find the equation of the data available of a graph?

I want the equation for this data. Please, help me.
X Y
0 0
50 1.202051
100 2.412308
150 3.643077
200 4.721709
250 5.34849
300 5.946781
350 6.331396
400 6.488091
450 6.488091
500 6.302906
550 5.975271
600 5.419715
650 4.693219
700 3.753048
750 2.727407
800 1.359886
850 0
900 0
950 0.790085
1000 2.869858
1050 4.650484
1100 5.975271
1150 6.872707
1200 7.456752
1250 7.527977
1300 7.357037
1350 6.687521
1400 5.619145
1450 4.251624
1500 2.556467
1550 0.32
1600 0

 Réponse acceptée

Alex Sha
Alex Sha le 15 Jan 2024
Déplacé(e) : Dyuman Joshi le 15 Jan 2024
Try the fitting function below:
Sum Squared Error (SSE): 1.05153845767184
Root of Mean Square Error (RMSE): 0.178507147609365
Correlation Coef. (R): 0.997415641383701
R-Square: 0.994837961676859
Parameter Best Estimate
--------- -------------
y0 -6.72273370419413
a1 13.5085640890228
b1 -7.32681575662562E-6
c1 1271.21138671474
a2 13.3029931198928
b2 -3.90619136753063E-6
c2 410.442920391101
a3 -3.56863630006966
b3 -6.4673256414225E-5
c3 896.221576681554

8 commentaires

Sir, how you did this sir.
Thank you so much sir.
Please let me know sir.
I have to do for some other data.
Same thing i need for this data too.
Can you please sir?
0 0
50 0.043011
100 0.172043
150 0.344086
200 0.430108
250 0.602151
300 0.774194
350 1.419355
400 3.698925
450 5.032258
500 5.935484
550 7.44086
600 9.548387
650 9.376344
700 10.02151
750 13.07527
800 15.48387
850 18
900 18
950 17.24731
1000 15.74194
1050 13.07527
1100 10.02151
1150 9.075269
1200 5.247312
1250 5.677419
1300 4.344086
1350 1.763441
1400 1.032258
1450 1.247312
1500 1.204301
1550 0.129032
1600 0
Using same type of function with 2 summation:
Sum Squared Error (SSE): 8.12638165282519
Root of Mean Square Error (RMSE): 0.496239850757223
Correlation Coef. (R): 0.996550635797028
R-Square: 0.993113169707461
Parameter Best Estimate
--------- -------------
y0 0.0386934097192918
a1 -4.90229146543642
b1 -9.85583543709033E-5
c1 710.22270883186
a2 18.4922068633488
b2 -8.75133653053069E-6
c2 853.425669456025
Dear @Alex Sha please help once,
I need the equation for the given data of a graph.
0 0
93.07876 0.224404
186.1575 0.476858
262.5298 0.729313
303.1026 0.869565
310.2625 1.290323
319.8091 1.598878
329.3556 1.486676
341.2888 1.318373
353.222 1.542777
362.7685 1.851332
372.315 2.103787
377.0883 2.412342
381.8616 2.664797
386.6348 2.889201
391.4081 3.169705
396.1814 3.45021
400.9547 3.702665
408.1146 3.98317
410.5012 4.235624
415.2745 4.460028
420.0477 4.712482
424.821 4.964937
446.3007 5.021038
467.7804 5.105189
477.327 5.329593
484.4869 5.553997
494.0334 5.778401
501.1933 5.946704
508.3532 6.143058
515.5131 6.367461
522.673 6.563815
529.8329 6.788219
536.9928 7.040673
544.1527 7.265077
548.926 7.517532
556.0859 7.798036
565.6325 8.078541
572.7924 8.387097
579.9523 8.695652
589.4988 9.004208
594.2721 9.284712
601.432 9.565217
606.2053 9.817672
613.3652 10.07013
625.2983 9.901823
637.2315 9.677419
649.1647 9.509116
663.4845 9.340813
675.4177 9.11641
684.9642 9.340813
692.1241 9.565217
696.8974 9.817672
704.0573 10.07013
706.4439 10.18233
718.3771 10.26648
720.7637 10.49088
723.1504 10.63114
725.537 10.79944
727.9236 10.96774
730.3103 11.1641
732.6969 11.41655
735.0835 11.64095
737.4702 11.86536
739.8568 12.08976
742.2434 12.37027
744.6301 12.62272
747.0167 12.84712
751.79 13.09958
756.5632 13.29593
761.3365 13.54839
766.1098 13.77279
770.8831 13.99719
775.6563 14.2216
780.4296 14.446
785.2029 14.69846
789.9761 14.89481
792.3628 15.11921
797.136 15.28752
801.9093 15.45582
806.6826 15.68022
811.4558 15.84853
813.8425 16.10098
818.6158 16.32539
828.1623 16.63394
830.5489 16.91445
835.3222 17.13885
840.0955 17.36325
844.8687 17.64376
852.0286 17.89621
875.895 17.89621
890.2148 17.89621
902.148 17.89621
918.8544 17.89621
926.0143 17.89621
933.1742 17.75596
940.3341 17.58766
947.494 17.3913
952.2673 17.223
954.6539 17.0547
964.2005 16.91445
971.3604 16.69004
978.5203 16.46564
985.6802 16.24123
995.2267 15.98878
1002.387 15.79243
1009.547 15.53997
1016.706 15.31557
1028.64 15.03506
1033.413 14.78261
1035.8 14.5582
1038.186 14.36185
1040.573 14.1655
1042.959 13.94109
1045.346 13.74474
1047.733 13.52034
1050.119 13.32398
1052.506 13.09958
1054.893 12.90323
1059.666 12.65077
1062.053 12.39832
1064.439 12.14586
1069.212 11.80926
1071.599 11.5568
1076.372 11.3324
1078.759 11.07994
1083.532 10.85554
1090.692 10.63114
1097.852 10.32258
1107.399 10.07013
1109.785 9.873773
1112.172 9.649369
1114.558 9.453015
1116.945 9.284712
1114.558 9.088359
1116.945 8.920056
1116.945 9.11641
1119.332 9.284712
1121.718 9.453015
1121.718 9.621318
1121.718 9.789621
1124.105 10.01403
1124.105 10.21038
1126.492 10.40673
1133.652 10.40673
1136.038 10.23843
1138.425 10.09818
1145.585 9.929874
1145.585 9.70547
1147.971 9.509116
1147.971 9.284712
1147.971 9.14446
1152.745 8.948107
1155.131 8.723703
1157.518 8.499299
1162.291 8.274895
1167.064 7.99439
1171.838 7.798036
1171.838 7.573633
1171.838 7.293128
1176.611 7.040673
1178.998 6.788219
1181.384 6.591865
1183.771 6.367461
1186.158 6.171108
1188.544 5.974755
1190.931 5.778401
1195.704 5.525947
1198.091 5.357644
1200.477 5.217391
1200.477 5.077139
1202.864 5.13324
1202.864 5.301543
1205.251 5.441795
1202.864 5.553997
1202.864 5.778401
1202.864 6.030856
1202.864 6.227209
1205.251 6.395512
1205.251 6.591865
1205.251 6.84432
1205.251 7.040673
1207.637 7.237027
1207.637 7.489481
1210.024 7.657784
1210.024 7.826087
1214.797 7.826087
1214.797 7.713885
1214.797 7.573633
1217.184 7.461431
1217.184 7.293128
1221.957 7.096774
1221.957 6.816269
1226.73 6.619916
1229.117 6.367461
1231.504 6.143058
1243.437 6.058906
1245.823 5.890603
1248.21 5.638149
1252.983 5.385694
1252.983 5.189341
1255.37 4.908836
1260.143 4.684432
1260.143 4.460028
1264.916 4.235624
1267.303 4.01122
1272.076 3.814867
1276.85 3.955119
1281.623 4.123422
1286.396 4.235624
1291.169 4.347826
1295.943 4.431978
1303.103 4.291725
1305.489 4.123422
1307.876 3.955119
1310.263 3.786816
1315.036 3.562412
1315.036 3.281907
1315.036 3.057504
1319.809 2.8331
1317.422 2.524544
1319.809 2.215989
1322.196 1.991585
1322.196 1.71108
1324.582 1.514727
1324.582 1.234222
1324.582 1.009818
1329.356 1.093969
1334.129 1.262272
1338.902 1.430575
1343.675 1.654979
1348.449 1.823282
1353.222 1.963534
1357.995 2.103787
1362.768 2.215989
1367.542 2.328191
1372.315 2.131837
1372.315 1.935484
1379.475 1.767181
1381.862 1.598878
1384.248 1.430575
1386.635 1.262272
1389.021 1.093969
1403.341 1.12202
1420.048 1.206171
1439.141 1.290323
1460.621 1.374474
1477.327 1.430575
1486.874 1.430575
498.807 1.234222
1510.74 1.037868
1520.286 0.785414
1529.833 0.56101
1539.379 0.392707
1548.926 0.252454
553.699 0.112202
1558.473 0
@Chaudhary P Patel you can apply same fitting function
Sum Squared Error (SSE): 109.196363453284
Root of Mean Square Error (RMSE): 0.651834774884085
Correlation Coef. (R): 0.991467477201577
R-Square: 0.98300775834846
Parameter Best Estimate
--------- -------------
y0 0.126165426019029
a1 -5.10401112354788
b1 -9.36470433400607E-5
c1 713.248136062984
a2 18.4595039945249
b2 -8.75650613548316E-6
c2 853.754093930767
If taking the function with 5 summation:
Sum Squared Error (SSE): 85.3275892982831
Root of Mean Square Error (RMSE): 0.576206530803999
Correlation Coef. (R): 0.993338824890983
R-Square: 0.986722021035799
Parameter Best Estimate
--------- -------------
y0 0.44233797341317
a1 4.78923160117768
b1 -0.000214498984637241
c1 601.987008811784
a2 4.50942837050938
b2 -8.96303272566855E-5
c2 468.329064006521
a3 16.0497523511668
b3 -2.13374537429094E-5
c3 869.549296381211
a4 -1.45824972842053
b4 -0.00125802705653459
c4 1092.69710354211
a5 5.63741027409879
b5 -2.29031756420012E-5
c5 1114.99999999995
@Alex Sha how are you perofrming this?
Can you brief me, Please?
I also want to learn it.
Hi, once known the data and the fitting function, it is easy to do fitting job in Matlab, for example, by using "lsqcurvefit" command, the only problem is that the initial start-values are hard to be guessed and provided properly, wihch will lead to not converge of fitting.
Rather than Matlab, the results I provided previously are obtained by another package named "1stOpt",this package apply global optimization algorithm, thus guessing of initial start-values is no longer required. The code looks very simple like below:
Constant n=5; //No. of summation
Function y=y0+Sum(n,a,b,c)(a*exp(b*(x-c)^2));
Data;
0 0
93.07876 0.224404
186.1575 0.476858
262.5298 0.729313
303.1026 0.869565
310.2625 1.290323
....

Connectez-vous pour commenter.

Plus de réponses (2)

I'm sorry, but high order polynomials (as suggested by @akshatsood) are always a bad idea. You will run into numerical problems working in double precision. And as well, people tend to think that if a degree 9 polynomial gave an ok fit, then we can get a better fit from a degree 10, or 12 or 15 degree polynomial. In the end, they end up running into the realm of overfitting their data.
And worst of all, the @Chaudhary P Patel talks about using that equation for prediction in a different interval.
Trying to extrapolate data using a high degree polynomial is just insanity. In fact, trying to extrapolate any model that fits data like that, where you have no rational method for having chosen the model is as crazy. The same applies to the sum of exponentials model produced by @Alex Sha. Just because the model predicts well for the existing data is no reason it will predict anything meaningful for data outside of the support of the data.
In the end, there is no magical way to know the true model that produced any set of data. What is needed is an understanding of the physics of what produced the data. If you do understand the physics, then you can SOMETIMES use that knowledge to suggest a model form, and then you can then use that model form to infer estimates of the parameters that might have existed.
This is why splines exist, and why people use splines as heavily as they do. For example:
xy1 = [0 0
50 1.202051
100 2.412308
150 3.643077
200 4.721709
250 5.34849
300 5.946781
350 6.331396
400 6.488091
450 6.488091
500 6.302906
550 5.975271
600 5.419715
650 4.693219
700 3.753048
750 2.727407
800 1.359886
850 0
900 0
950 0.790085
1000 2.869858
1050 4.650484
1100 5.975271
1150 6.872707
1200 7.456752
1250 7.527977
1300 7.357037
1350 6.687521
1400 5.619145
1450 4.251624
1500 2.556467
1550 0.32
1600 0 ];
spl1 = spline(xy1(:,1),xy1(:,2));
fnplt(spl1,'b')
hold on
plot(xy1(:,1),xy1(:,2),'ro')
Even here though, note that at the right end of that curve, the spline predicts a quick turnaround. Is that true? Perhaps. There is clearly some curvature in the data at that end. But lacking any information to the right, it is IMPOSSIBLE to guess what will really happen there. And since it looks like there is also probably some noise in the data, we need to guess if that is just noise, or if it is real. Most of the time, I would guess some of the bumps in your curve are noise. But maybe they are real signal. We cannot know. (I recall one of my clients who positively knew that if there was a small jiggle in a curve, they ABSOLUTELY needed to know about it, and needed to see it reproduced. But that is not always the case.)
A problem of course is there is no simple function you can write down for the spline I just produced above. But the sum of exponentials model given by @Alex Sha, or the high degree polynomial from @akshatsood are nearly as bad. They will both be terribly sensitive to even small perturbations in the coefficients in those models. And extrapolative predictions of those curves will be just as sensitive.
Again, I'm sorry. But there is no simple way to know the true equation of such a set of data. There is not even a sophisticated, complex way to know that.

1 commentaire

@John D'Errico, How would using spline be comparable/different to using 'SmoothingSpline' method of fit?
Other than the fact that the former is a in-built function, whereas the latter requires the Curve fitting toolbox.
% Given data
XY = [ 0 0
50 1.202051
100 2.412308
150 3.643077
200 4.721709
250 5.34849
300 5.946781
350 6.331396
400 6.488091
450 6.488091
500 6.302906
550 5.975271
600 5.419715
650 4.693219
700 3.753048
750 2.727407
800 1.359886
850 0
900 0
950 0.790085
1000 2.869858
1050 4.650484
1100 5.975271
1150 6.872707
1200 7.456752
1250 7.527977
1300 7.357037
1350 6.687521
1400 5.619145
1450 4.251624
1500 2.556467
1550 0.32
1600 0];
X = XY(:,1);
Y = XY(:,2);
% Fit a spline curve
spline_fit = fit(X, Y, 'smoothingspline');
% Generate a finer grid of X values for plotting
X_fit = linspace(min(X), max(X), 100);
% Evaluate the spline at the finer grid of X values
Y_fit = feval(spline_fit, X_fit);
% Plot the original data and the fitted curve
plot(X, Y, 'o', X_fit, Y_fit);
xlabel('X');
ylabel('Y');
legend('Data', 'Fitted Curve');

Connectez-vous pour commenter.

akshatsood
akshatsood le 15 Jan 2024
Modifié(e) : akshatsood le 15 Jan 2024
I understand you have a dataset containing X and Y values and you seek a method to deduce a mathematical equation that best represents the relationship between these two variables. Below, I put forward two approaches that would serve as a starting point in achieving the desired equation.
Approach 1 : leveraging the "polyfit" function
To visualize a relationship between X and Y values with an assumption that it can be a polynomial, you can leverage the "polyfit" function to determine the coefficients of the best-fit polynomial. In this approach, you need to experiment with the the degree of the polynomial that would render the optimal relationship between the variables.
Approach 2 : using Curve Fitting Toolbox
In case you have the Curve Fitting Toolbox app, you can get access to a more interactive approach to experiment with various types of fits including linear, polynomial, exponential, etc. and decide upon the optimal choice that associates the variables X and Y.
I hope this helps.

3 commentaires

Sir, can you please provide me the better solution for the curve?
It will be grate help for me.
Thanks.
Have a look at the following code snippet which demonstrates applying a fit to the data provided by you. The equation for the fit and the corresponding coefficients can be found in the variable "y_fit".
% original data (X and Y)
x = [0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800,
850, 900, 950, 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500,
1550, 1600];
y_org = [0, 1.202051, 2.412308, 3.643077, 4.721709, 5.34849, 5.946781, 6.331396,
6.488091, 6.488091, 6.302906, 5.975271, 5.419715, 4.693219, 3.753048, 2.727407,
1.359886, 0, 0, 0.790085, 2.869858, 4.650484, 5.975271, 6.872707, 7.456752,
7.527977, 7.357037, 6.687521, 5.619145, 4.251624, 2.556467, 0.32, 0];
% applying fit using a polynomial of degree 8
y_fit = fit(x(:), y_org(:), 'poly8');
Warning: Equation is badly conditioned. Remove repeated data points or try centering and scaling.
% visualize original data and fit data
plot(y_fit, x, y_org);
I would recommed experimenting with different fit types to arrive at an optimal fit as per your requirements
Chaudhary P Patel
Chaudhary P Patel le 15 Jan 2024
Déplacé(e) : Dyuman Joshi le 15 Jan 2024
sir, more than poly9 it is not going.
sir, but i am not getting equation for it.
my main objective is to to get the value with different interval which is possible when i have the equation of the curve.
@Dyuman Joshi @akshatsood sir please help me.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with Curve Fitting Toolbox dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by