Hello
I want to know why we are using the line
sumX2=sumX2+(listOfPoints(1,i)-Xc(1,:))^2;
Why 2 times sumX2, and what is the purpose of using 2 times, and can anyone let me know?
What are the changes in the result ?
sumX2=0; sumY2 =0; sumZ2=0; sumXY=0; sumYZ=0; sumXZ=0;
for i=1:N
sumX2 = sumX2 + (listOfPoints(1,i)-Xc(1,:))^2;
sumY2 = sumY2 + (listOfPoints(2,i)-Xc(2,:))^2;
sumZ2 = sumZ2 + (listOfPoints(3,i)-Xc(3,:))^2;
sumXY = sumXY + (listOfPoints(1,i)-Xc(1,:))*(listOfPoints(2,i)-Xc(2,:));
sumYZ = sumYZ + (listOfPoints(2,i)-Xc(2,:))*(listOfPoints(3,i)-Xc(3,:));
sumXZ = sumXZ + (listOfPoints(1,i)-Xc(1,:))*(listOfPoints(3,i)-Xc(3,:));
end

 Akzeptierte Antwort

KALYAN ACHARJYA
KALYAN ACHARJYA am 3 Dez. 2019
Bearbeitet: KALYAN ACHARJYA am 3 Dez. 2019

1 Stimme

"why 2 times sumX2 and what is the purpose of using 2times and can anyone do let me know?"
sumX2=sumX2+...
Here sumX2 updated during entire iteration
Let say example
sumX2=1;
for i=1:4;
sumX2=sumX2+i;
end
#
In first Iteration, ehen i=1
sumX2=sumX2+i=1+1=2
In 2nd Iteration, ehen i=2, sumX2=2
sumX2=sumX2+i=2+2=4
...so on..
In each ireration sumX2 used the last updated values, for current sumX2 calculation
Hope it helps!

5 Kommentare

vimal kumar chawda
vimal kumar chawda am 3 Dez. 2019
Bearbeitet: vimal kumar chawda am 4 Dez. 2019
Xc(1,:) = (1/N)* sum(listOfPoints(1,:));
Xc(2,:) = (1/N)* sum(listOfPoints(2,:));
Xc(3,:) = (1/N)* sum(listOfPoints(3,:));
Hello Sit
What does this line means as earlier we are not dealing with varying value in column? Now we are doing it. What does it means Xc(1,:) ?
I think we are saving each value after by each iteration. Hence we have to make define it according to number of cycle. Am I right..? We are saving it in vector or array form. like x(1,:)
Xc = mean(listOfPoints, 2);
vimal kumar chawda
vimal kumar chawda am 5 Dez. 2019
But i am getting only one value in this loop as respective row.
Hence i got the concept and understand the meaning.
thank you
I am happy with answer and request to close this problem my side.
KALYAN ACHARJYA
KALYAN ACHARJYA am 5 Dez. 2019
Great!
Keep Learning Vimal
But i am getting only one value in this loop as respective row.
The expression (1/N)* sum(listOfPoints(1,:)) would sum the row vector listOfPoints(1,:) resulting in a scalar, and then would divide the scalar by N, resulting in a scalar. You then assign the result to Xc(1,:) which would assign the same scalar to all columns that exist in the first row of Xc. If, for example, Xc already existed with 17 columns, then all 17 columns of the first row will be assigned the exact same mean value.
The code I suggested,
Xc = mean(listOfPoints, 2);
is a little different in that it will result in Xc being exactly one column wide, no matter how big the existing Xc was. If you really need Xc to keep the same number of columns and have each column be exactly the same within each row, then there are a number of different was to achieve that, including,
Xc = mean(listOfPoints, 2) * ones(1, size(Xc,2));

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by