How can I compute the Area and the Centroid of the following shape?
Show older comments
How can I compute the Area and the Centroid of the following shape?
I have used the following code to construct it:
xA = 0;
xB = 1;
xf = 1
x = linspace(0, xf, xf*1e4 + 1);
a = 9.2; %
c = 0.5; % center of function
Y = sigmf(x, [a c]).*((0 <= (x - xA)) & ((x - xA) < (xB - xA)));
plot(x, Y, 'linewidth', 1.5), grid on, xlim ([0 1.1])
6 Comments
You have the functional equation. So you can use "int" or "integral".
The integral formula for the centroid is given here:
Section:
Locating by integral formula of a bounded region.
M
on 11 Sep 2022
Torsten
on 11 Sep 2022
For functional areas: not that I know of.
But the formulae given in Wikipedia are not that complicated, are they ?
M
on 11 Sep 2022
M
on 11 Sep 2022
Accepted Answer
More Answers (4)
Bruno Luong
on 12 Sep 2022
Edited: Bruno Luong
on 12 Sep 2022
xA = 0;
xB = 1;
a = 9.2;
c = 0.5;
sfun = @(x)sigmf(x, [a c]);
Area = integral(@(x)sfun(x),xA,xB);
xc = integral(@(x)sfun(x).*x,xA,xB)/Area
yc = integral(@(x)sfun(x).^2,xA,xB)/(2*Area)
1 Comment
Bruno Luong
on 4 Nov 2024
See formula in section "Of bounded region" of wikipedia
Hi @M
If your intention is to find the defuzzified output value for membership function mf at the interval in x using the centroid method, then you can try this method:
xA = 0;
xB = 1;
x = xA:0.0001:xB;
mf = sigmf(x, [9.2 0.5]);
plot(x, mf), grid on, xlim([-0.2 1.2]), ylim([0 1.2]), xlabel('\it{x}'), ylabel('\mu(\it{x})')
xc = defuzz(x, mf, 'centroid')
xline(xc, '--', sprintf('%.4f', xc), 'LabelVerticalAlignment', 'middle');
Note that there should be no significant difference between
mf = sigmf(x, [9.2 0.5]).*((0 <= (x - xA)) & ((x - xA) < (xB - xA)));
and
mf = sigmf(x, [9.2 0.5]);
Image Analyst
on 11 Sep 2022
1 vote
4 Comments
M
on 11 Sep 2022
Image Analyst
on 11 Sep 2022
So convert x, Y into one!
Image Analyst
on 12 Sep 2022
p = polyshape(x,Y);
[x,y] = centroid(p)
Kwanele
on 2 Nov 2024
0 votes
% Define the functions
f1 = @(x) 0.5 * (80.94 - 0.25 * exp(2 * x.^2));
f2 = @(x) 8.997 - 0.5 * exp(x.^2);
% Define the limits of integration
a = 0;
b = 1.7;
% Use MATLAB's integral function
numerator = integral(f1, a, b);
denominator = integral(f2, a, b);
% Calculate the centroid
centroid = numerator / denominator;
% Display the results
fprintf('Numerator: %.4f\n', numerator);
fprintf('Denominator: %.4f\n', denominator);
fprintf('Centroid: %.4f\n', centroid);
Categories
Find more on Numerical Integration and Differentiation 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!


