Why are centroid values different when computing using same equation

2 views (last 30 days)
Hello,
I am trying to calculate a centroid of an annulus sector. First method is to st a range of radius and compute Centroid1. Second method, I use a loop to compute the Centroid2 using the same equation and plot the result in the graph. Why are the results different? Can someone please explain this?
Thanks in advance,
Sohail
%
clc
clear all
close all
%
Ro = [.5:.1:1.5]
Ri = Ro(1,1);
%
theta_r = 30; % 1/2 Angle in degrees
theta = theta_r * pi / 180; % converting angle to radians
%
Centroid1 = 2*Ro*sin(theta)/(3*theta)*(1-(Ro-Ri)/Ro+1/(2-(Ro-Ri)/Ro))
%
for i=1:11
Centroid2(i) = 2*Ro(i)*sin(theta)/(3*theta)*(1-(Ro(i)-Ri)/Ro(i)+1/(2-(Ro(i)-Ri)/Ro(i)))
end
%
figure()
plot(Ro,Centroid1,'-ro', Ro,Centroid2,'-bo')
title('Why are Centroid Values Different Using Same Equation')
hleg1 = legend('Centroid_1','Centroid_2');
set(hleg1, 'Location', 'Northwest')
xlabel('Radius,(in)')
ylabel('rBar, (in)')

Accepted Answer

Image Analyst
Image Analyst on 14 Oct 2012
Edited: Image Analyst on 14 Oct 2012
You used matrix multiply "*" and matrix inverse ("/"), instead of element-by-element multiply and divide with dots ("./" and .*")
Corrected line of code:
Centroid1 = 2*Ro.*sin(theta)/(3*theta).*(1-(Ro-Ri)./Ro+1./(2-(Ro-Ri)./Ro))

More Answers (2)

Matt J
Matt J on 14 Oct 2012
Because when computing Centroid1, you're using matrix multiplication and division instead of element-wise multiplication and division .* and ./

Sohail
Sohail on 14 Oct 2012
Thanks Matt and Image Analyst for the explanation

Tags

Products

Community Treasure Hunt

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

Start Hunting!