How can I calaulate the 3D Manhattan distance on excel.
I know the 2D formula but I have absolutely no idea about the Manhattan distance formula for 3D
for example, now I have 2 points:
c1 = (6.25, 4.75, 5.25)
p1 = (8, 8, 1)
I have calculate it on the online Manhattan distance calculater, the anwers is 9.25
But I really want to know the formula
Thanks~
Related
Suppose an Excel file has vectorized 2-by-2 symmetric matrices line by line as follows:
line
A: element11
B: element22
C: element12=element21
D: DETERMINANT
1
2
3
0
6
2
5
7
0
35
3
11
13
0
143
…
…
…
…
…
Thus, the first value of DETERMINANT column can be computed from a matrix {2 0,0 3}, the second value can be from a matrix {5 0,0 7}, and so on. Instead of reshaping the A1:C1 values, the D1 value can be directly computed via =MDETERM(IF(A1:B1=TRANSPOSE(A1:B1),A1:B1,C1)) because IF can actually reshape the A1:C1 values to the diagonal matrix of interest.
The point is that, in Excel, matrix functions such as MDETERM directly require matrices, while the matrices in the data are stored row by row after vectorization. Unfortunately, the IF solution above can only reshape 2-by-2 symmetric matrices and handle neither asymmetric matrices nor matrices with more than two off-diagonal elements. Do we have any other solutions more general than the illustrated IF approach to unvectorize matrices?
In addition, I am also interested in vectorizing matrices in Excel as well; for example, the matrix in A1:C1 can be reshaped, inverted, and then restored in the D1:G1 area. Thanks for your help!
I think you might have meant
=IF(COLUMN(A1:B1)=TRANSPOSE(COLUMN(A1:B1)),A1:B1,C1)
But you can certainly expand on this idea. Suppose you have the diagonal elements of a symmetric 4X4 matrix in A1:D1 and the off-diagonal elements in E1:J1.
Then you could use
=IF(ROW(A1:D4)=COLUMN(A1:D4),INDEX(A1:J1,ROW(A1:D4)),
IF(ROW(A1:D4)<COLUMN(A1:D4),INDEX(E1:J1,(ROW(A1:D4)-1)*4+COLUMN(A1:D4)-ROW(A1:D4)*(ROW(A1:D4)+1)/2),
INDEX(E1:J1,(COLUMN(A1:D4)-1)*4+ROW(A1:D4)-COLUMN(A1:D4)*(COLUMN(A1:D4)+1)/2)))
A bit more general with Excel 365 Let function:
=LET(N,4,mat,A1:INDEX(A1:Z26,N,N),
IF(ROW(mat)=COLUMN(mat),
INDEX(1:1,ROW(mat)),
IF(ROW(mat)<COLUMN(mat),
INDEX(1:1,(ROW(mat)-1)*N+COLUMN(mat)-ROW(mat)*(ROW(mat)+1)/2+N),
INDEX(1:1,(COLUMN(mat)-1)*N+ROW(mat)-COLUMN(mat)*(COLUMN(mat)+1)/2+N))))
I don't know if this question makes sense, but is there a formulaic way to calculate the height of a chord from a circle's edge in one of the circles from 3 tangent circles?
I have included a diagram to provide detail. Circles C1, C2 and C3 are connected at tangents and have equal radii (in this case 1 mm, but that is only for depiction). Triangle ABC is formed by connecting the centers of these circles. Line LM meets sides AB and AC and is tangential to Circle C1. Line PQ cuts through Circle C1 and triangle ABC and is tangential to both circles C2 and C3.
Diagram for question
What is the formula for the distance (x) between lines LM and PQ?
Given that the radii are equal (say, r), the total height of these 3 circles (line RS shown in diagram, which is my objective to calculate) is 4 times the radius minus the distance (x) between lines LM and PQ. In other words,
|RS| = {(4*r) - x}
variable x needs to be converted into a formula based exclusively on radius r so as to solve this equation.
It has been a while since I revisited my high school geometry lessons, so I hope this can be solved.
Distance A-LM is equal to r (circle center - tangent)
Distance BC-PQ is equal to r
If we add these distances and subtract distance PQ-LM (x), we'll get height of equilateral triangle ABC (with edge 2*r)
r + r - x = height of ABC = 2 * r * sqrt(3)/ 2
x = r * (2 - sqrt(3))
I have four groups with individual proportions: p1, p2, p3, p4. Taking a random sample from this, the sum of the four values should equal 20 for each generation.
I have seen how to create four random values that sum to a number, but how do I factor in that they have these initial probabilities of being chosen?
*******Maybe I should elaborate on the question. There are four groups of candy being chosen to create a package of 20. The proportions are 20%, 25%, 30%, and 25% of the candies on an assembly line. Candies are selected randomly from this process and placed in the packages of 20 pieces. I am to simulate the process of creating 1000 of these packages. All 1000 generations should add up to 20.****
Just wondering if we are talking about something like the below?
Perc =RAND() =B2*C2 =D2/SUM($D$2:$D$5) =E2*20
P1 5% 0.168440417 0.008422021 0.026888651 0.537773022
P2 15% 0.23130968 0.034696452 0.110773983 2.215479657
P3 25% 0.424406873 0.106101718 0.338746737 6.774934746
P4 55% 0.2981786 0.16399823 0.523590629 10.47181258
Where the formulas are pasted in row 2, and copied down?
After seeing the edits to your question, I'm thinking maybe the below would be better?
F3:Y1003 has the formula: =RANDBETWEEN(1,20)
A3 has the formula: =COUNTIFS($F5:$Y5,">=1",$F5:$Y5,"<=4") (equivalent of 20%)
B3 has the formula: =COUNTIFS($F5:$Y5,">=5",$F5:$Y5,"<=9") (equivalent of 25%)
C3 has the formula: =COUNTIFS($F5:$Y5,">=10",$F5:$Y5,"<=15") (equivalent of 30%)
D3 has the formula: =COUNTIFS($F5:$Y5,">=16",$F5:$Y5,"<=20") (equivalent of 25%)
Then copy A3:D3 down to A1003:D1003.
Suppose 5 samples of hue are taken using a simple HSV model for color, having values 355, 5, 5, 5, 5, all a hue of red and "next" to each other as far as perception is concerned. But the simple average is 75 which is far away from 0 or 360, close to a yellow-green.
What is a better way to calculate this mean and associated std?
The simple solution is to convert those angles to a set of vectors, from polar coordinates into cartesian coordinates.
Since you are working with colors, think of this as a conversion into the (a*,b*) plane. Then take the mean of those coordinates, and then revert back into polar form again. Done in matlab,
theta = [355,5,5,5,5];
x = cosd(theta); % cosine in terms of degrees
y = sind(theta); % sine with a degree argument
Now, take the mean of x and y, compute the angle, then
convert back from radians to degrees.
meanangle = atan2(mean(y),mean(x))*180/pi
meanangle =
3.0049
Of course, this solution is valid only for the mean angle. As you can see, it yields a consistent result with the mean of the angles directly, where I recognize that 355 degrees really wraps to -5 degrees.
mean([-5 5 5 5 5])
ans =
3
To compute the standard deviation, it is simplest to do it as
std([-5 5 5 5 5])
ans =
4.4721
Yes, that requires me to do the wrap explicitly.
I think the method proposed by user85109 is a good way to compute the mean, but not the standard deviation:
imagine to have three angles: 180, 180, 181
the mean would be correctly computed, as a number aproximately equal to 180
but from [180,180,-179] you would compute a high variance when in fact it is near zero
At first glance, I would compute separately the means and variances for the half positive angles , [0 to 180] and fot the negative ones [0,-180] and later I would compute the combined variance
https://www.emathzone.com/tutorials/basic-statistics/combined-variance.html
taking into account that the global mean and the difference between it and the local means has to be computed in both directions: clockwise and counterclockwise, and the the correct one has to be chosen.
How can I calculate the latitude-longitude of a place, when the latitude-longitude information of its 3 nearby places, and the distances to the place are given?
E.g, A,B and C are three places with latitude-longitude (x1,y1), (x2,y2) and (x3,y3). Let D be at distance k1, k2 and k3-km from A, B and C respectively. How can one determine the latitude-longitude of D.
In case, all these points, A,B,C and D are on a plane, then this can be calculated, by determining the point of intersection of the three circles, from A, B and C with radius k1, k2 and k3, respectively. However, how to determine the position, when the points are on a sphere and not on a circle?
Starting with a plane, here is an alternative method to your suggested 3 circles:
Since you know the coordinates of A,B and C, you can calculate the length of AB,AC and BC.
Lets mark by X the point point we want to find.
we know that AX=k1, BX=k2 and CX=k3
Now draw the 3 triangles: ABX, ACX, EDX. We know the length of all their edges, therefore we can calculate the angles.
Knowing all coordinates, lengths and angles we can calculate the coordinates of X.
For a sphere- almost the same idea can be used. However:
Coordinates should be in Lat/Lon radians
Distances should be calculated using great circle distance formula. See Aviation Formulary.
Total angles in a triangle is not 180 - It is between 180 and 540.
Knowing the edges lenghts, angles can be calculated using the spherical law of cosines
Now, coordinates of X can be calculated.
It takes some time to get used to working with spherical trigonometry, however this is the right tool for such problems.
I'll assume k1, k2, k3 are distances on the sphere.
You may be able to solve this most precisely by using a special case of the Vincenty formula. With your three sets of values for x, y, and k, you can set up a system of equations to solve for the latitude and longitude of the fourth point. Solving this system would probably be extremely tricky due to its complexity, but there may be computational tools that could perform such a solve.