Volume and Area under a fit curve

6 views (last 30 days)
Hello!
I'm getting a problem to calculate the Area and Volume (solid of revolution) from a curve. I've generated this curve using the Curve Fitting App from my data. This data consist in two vectors with 75 elements, one from measures of x, and another to measures of y, both related (like x(1) is related to y(1)).
The problem is: When i integrate the fittedmodel i don't get the expected result to the integer, the result is very far from the expected. Below is my data and the results:
%xi and yi is the data to generate the curve
xi = [8 11 14 17 20 ...
23 26 29 32 35 ...
38 41 44 47 50 ...
53 56 59 62 65 ...
68 71 74 77 80 ...
83 86 89 92 95 ...
98 101 104 107 ...
110 113 116 119 ...
122 125 128 131 ...
134 137 140 143 ...
146 149 152 155 ...
158 161 164 167 ...
170 173 176 179 ...
182 185 188 191 ...
194 197 200 203 ...
206 209 212 215 ...
218 221 224 227 230]';
yi = [48 48.75 48.85 48.85 48.95 48.9 ...
48.875 48.725 48.7 48.65 ...
48.425 48.40 48.15 48.05 ...
48 47.8 47.625 47.35 47.05 ...
46.85 46.5 46.25 46.1 45.65 ...
45.2 44.825 44.5 44.15 ...
43.7 43.2 43 42.55 42 ...
41.4 41 40.4 39.825 39.4 ...
38.975 37.625 36.9 36.05 ...
35.515 34.935 34.01 33.06 ...
32.49 31.425 30.74 29.905 ...
29.335 28.435 27.865 27.59 ...
27.2 26.73 26.475 26.33 ...
26.07 25.985 25.95 25.97 ...
26.125 26.26 26.5 26.9 27.19 ...
27.685 28.07 28.705 29.46 ...
30.035 30.96 31.425 31.5]';
This is the Curve Fitting App results:
The results from Curve Fitting Tool:
Linear model Poly9:
f(x) = p1*x^9 + p2*x^8 + p3*x^7 + p4*x^6 +
p5*x^5 + p6*x^4 + p7*x^3 + p8*x^2 + p9*x + p10
where x is normalized by mean 119 and std 65.38
Coefficients (with 95% confidence bounds):
p1 = 0.1351 (0.01098, 0.2593)
p2 = 0.1677 (0.06146, 0.2739)
p3 = -0.9629 (-1.743, -0.1826)
p4 = -1.728 (-2.319, -1.138)
p5 = 2.014 (0.3559, 3.672)
p6 = 6.094 (5.048, 7.139)
p7 = 2.268 (0.9082, 3.628)
p8 = -6.89 (-7.526, -6.254)
p9 = -14.36 (-14.71, -14)
p10 = 39.11 (39.01, 39.2)
Goodness of fit:
SSE: 1.826
R-square: 0.9997
Adjusted R-square: 0.9996
RMSE: 0.1676
The expected Volume is: 1e+06 aprox.
Things that I've tried:
1:
Yfun = @(p) interp1(xi, yi, p);
vol = 2*pi*integral(@(r) Yfun(r).^2, 8, 230);
figure(2)
fplot(Yfun,[0 240]);
The result: vol =
2.117974233163996e+06
-----------------------------------------------------------------------------
2: After using the Curve Fitting App to generate the curve, and saved the data of fit in the Workspace as "fit":
plot(fit);
%i don't know how to integrate the fit, I've tried this:
inte = integrate(fit,[xi],8); %this returns a vector of values of the integral in each point, but i need the area inside the curve, and not the vector of values.
disp(inte);
The Results:
1.0e+04 *
-5.298410022994969
-5.207195743886399
-5.115538164258902
-5.023588889525035
-4.931468089706592
-4.839271915381278
-4.747078332694966
-4.654951650401904
-4.562945978684072
-4.471107828746543
-4.379478033805406
-4.288093145994929
-4.196986439838003
-4.106188631165216
-4.015728400649765
-3.925632793364640
-3.835927549881680
-3.746637410336017
-3.657786420490639
-3.569398258071206
-3.481496588417348
-3.394105450730244
-3.307249669804079
-3.220955283027533
-3.135249968547648
-3.050163457718799
-2.965727913230844
-2.881978253539507
-2.798952404325326
-2.716691458601843
-2.635239728695733
-2.554644675548018
-2.474956703553063
-2.396228812377401
-2.318516100800259
-2.241875121508695
-2.166363089879153
-2.092036954000738
-2.018952337460231
-1.947162370631597
-1.876716430310121
-1.807658811419972
-1.740027358120832
-1.673852084860661
-1.609153820684662
-1.545942912331533
-1.484218023244017
-1.423965066508125
-1.365156309831062
-1.307749689888364
-1.251688371632910
-1.196900585378846
-1.143299770568881
-1.090785050020480
-1.039242052041939
-0.988544090029842
-0.938553699921691
-0.889124525098248
-0.840103525926018
-0.791333477018046
-0.742655699387482
-0.693912956889896
-0.644952426613754
-0.595628631100551
-0.545806196373474
-0.495362273642866
-0.444188434154865
-0.392191815873104
-0.339295267448934
-0.285436199160039
-0.230563812097151
-0.174634335770652
-0.117603860409718
-0.059418303453184
0
--------------------------------------------------------------
The second test is far better in precision, but i don't get the result that i wanted, the integral under the curve (area) to calculate the volume (solid of revolution).
Can someone help me or give me a light to what to do?
If yes, please describe using a code example, cause i'm new using Matlab.
Thanks!
  1 Comment
Alan Lanceloth Silva
Alan Lanceloth Silva on 11 Jul 2018
Also, I've read some articles in the community like: https://www.mathworks.com/matlabcentral/answers/358695-how-to-find-volume-under-fitted-data https://www.mathworks.com/matlabcentral/answers/63618-volume-integration-under-surface-fitting And the documentation about the curve fitting, but i didn't find any answer to my problem. In the most cases, exist a function, but in my case i have only the data and to get a function i need to interpolate (like i did in the curve fitting app).

Sign in to comment.

Accepted Answer

Torsten
Torsten on 11 Jul 2018
Edited: Torsten on 11 Jul 2018
Yfun = @(x)pi*p(x).^2;
volume = integral(Yfun,8,230)
where p is the object returned from "fit".
Best wishes
Torsten.
  3 Comments
Torsten
Torsten on 12 Jul 2018
Then set
Yfun = @(x)pi*p(x).^2;
volume = integral(Yfun,8,230,'ArrayValued',true)
Best wishes
Torsten.
Alan Lanceloth Silva
Alan Lanceloth Silva on 13 Jul 2018
Torsten, you're the best!
It's worked like i expected, and the results are close to the reality. Thank you a hundred times!
Best regards, Alan Lanceloth.

Sign in to comment.

More Answers (0)

Categories

Find more on Linear and Nonlinear Regression in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!