Excel formula for Euclidean distance - excel

A former co-worker of mine uses this formula to do some cluster analysis:
{=SQRT(SUM(($C3:$F3-$C$11:$F$11)^2))} .
He doesn't know why it works.
It's meant to find the distance between some points. When I run the equation without the {} it gives me one answer. When I run it with it, I get another.
Distance is normally A^2+B^2=C^2. I'm guessing this is doing it for a series of points in the row. Is this basically doing the each point in each of these rows?
I just want to make sure we're not using something stupid.

It is an array formula that takes the squared differences between the corresponding cells, sums those values and takes the square root of the sum. So yes, it is a valid Euclidean distance in R4. Array formulas require hitting CTRL + SHIFT + ENTER at the same time. Otherwise it will return a value for the corresponding row/column.
That formula is equivalent to:
=SQRT(SUM((C3-C11)^2, (D3-D11)^2, (E3-E11)^2, (F3-F11)^2)
And there is a built-in function SUMXMY2 which does the same job:
=SQRT(SUMXMY2(C3:F3,C11:F11))

Euclidean Norm of a vector of size 'n' = SQRT(SUMSQ(A1:An))
The SUMSQ function is useful to calculate the Euclidean norm in Excel

=SQRT(($I$2-I7)^2+($J$2-J7)^2+($K$2-K7)^2+($L$2-L7)^2+($M$2-M7)^2+($N$2-N7)^2+($O$2-O7)^2)
This is my formula to calculate difference between two different rows of numbers

Related

Is there an EXCEL function to choose the closest points below a certain line?

Suppose that we have a scattered series of data X,Y randomly spaced (in the pic they are ordered, but this doesn't matter) and a line which shows the maximum limit we are considering for a sub-application.
Is there a combination of functions to choose the closest points below the orange line? I've tried with a MAXIFS + LOOKUP, but didn't solve anything.
The formula of your line is: y=1.17*x, so you create a helper column, containing a formula like:
=IF(1.17*A3-B3>0;1.17*A3-B3;100000)
This means: calculate the difference between the line and the point if that difference is positive. In case it's negative (which means that the point is above the line), then show a value which is that large that it won't be taken into account while calculating the minimum.
You drag this formula all over the column.
You calculate the minimum of that column (one of the easy ways to do this, is using the autofilter).

Finding Distance From List Of Coordnates

looking to see if someone can suggest a site or excel method to find the distance of multiple long,lat coordinates from a one point
example: I have a starting point and 7 other coordinates, is there a way to find how far away (in KM/MI) each point is from the starting point?
Starting loction : 33.17261,-117.14571
list of coordinates
32.75827,-117.17577
32.76079,-117.18589
32.76444,-117.20174
32.59815,-117.01685
32.66387,-117.05577
32.59811,-117.01681
32.66381,-117.05571
lets assume the column they are stored in is column A starting in row 2 (assuming you have a header row). The first thing you are going to want to do is split them into their own columns so you can work with the numbers. There are a couple of ways to do this. The simplest is using the built in feature Text-to-Columns located on the Data ribbon.
Have the whole column selected when you start the process and on the first page, select Delimited.
On the second step choose "," as a delimeter and then press finish. You do not need the third step.
once that is done your data should now be sitting in two columns.
I will place the point you are referring to in C2 and D2, you can use text to columns for this part too or just type it in.
So base on information on another site (assuming its correct), take the earth as a sphere with radius, 6371 km. Place this value in E2.
Next convert your list into X and Y values using the following equations:
F2
=$E$2*COS(RADIANS($B2))*COS(RADIANS($A2))
G2
=$E$2*SIN(RADIANS($B2))*SIN(RADIANS($A2))
note that the degrees were converted to radians for use in excels trig functions
Repeat the process for you starting point coordinates and place the formulas in H2 and I2.
H2
=$E$2*COS(RADIANS($D2))*COS(RADIANS($C2))
I2
=$E$2*SIN(RADIANS($D2))*SIN(RADIANS($C2))
Finally in J2 use the following formula:
=SQRT((F2-$H$2)^2+(G2-$I$2)^2)
Copy the formulas in F2, G2, and J2 down as for as your source list goes. The values in J represent the distance between the X Y points. It does not the curvature of the earth though. Apparently there are many different models to predict this. You need one that works for your area if you want something more refined.
For geodesic grade accuracy (fraction of a mm) you can use my Excel add-in available on GitHub: https://github.com/tdjastrzebski/Vincenty-Excel, in particular VincentyInvDistance() function. The solution implements Vincenty's formulae,
Otherwise use Haversine formula but it does not provide geodesic grade results.
The topic is not that trivial, see Geodesics on an ellipsoid for more details.

Excel SLOPE function returning incorrect values

I seem to have stumbled upon a bug where the SLOPE function returns values when it shouldn't. Specifically, consider the following case (where X = 2.69896131835952):
If the X values are always the same, SLOPE is supposed to return #DIV/0!. But in the first case it returns 0, and more worryingly in the second case it returns some completely bogus number.
If we compare to other values, we can see this isn't normal behaviour:
This problem isn't fixed by using ISNUMBER to make sure to filter out empty results or similar. It can even happen to numbers with only a few decimal places (these numbers are exactly as shown):
In fact, this isn't a very rare phenomenon at all - if one uses RAND to pick a single random value for X, and several random values for Y then it only takes a few tries before one finds a dataset which SLOPE hiccups on.
My questions are as follows:
What's causing this behaviour?
For which values of X does this happen for?
The above was only in the case where the X value is the same for every point. Obviously this is easy to test for in advance, but is SLOPE trustworthy in the case where the X values are different? (I can't use LINEST because my data has gaps.)
The slope function does not always work with calculated values.
If you are having problems with slope function giving zero values, copy and paste the data used by the slope function as values first. The slope function does not always work with a column of calculated values.
I was trying to calculate the slope and determine how it changes with time and got only zero values. One of the columns I was using was a moving average of 10 pressure values in another column and the cells had the green triangle “error message” Formula Omits Adjacent Values. The calculations for this column were correct, this was just a suggestion that I was not using all the cells in the column for the calculation. I copied and pasted the column of moving averages into another column as Values and the slope function gave the correct values when I used the new column of values.
I had the same issue but it was resolved when i fixed an unrelated circular reference issue. My circular reference issue prevented any new functions referencing calculated values (rather than static values) from calculating properly.

Excel - 3D cartesian points - euclidean distance for a large group of points

I have a large set of XYZ Cartesian points in Excel (some 40k actually) and was looking for a formula or macro to compare every point to every other point to get the distances between them.
The math to get the distance value between two 3D points is:
Distance=SQRT((X2 – X1)^2 + (Y2 – Y1)^2 + (Z2 – Z1)^2)
X1=the X value of the 1st point
X2=the X value of the 2nd point
Y1=the Y value of the 1st point
Y2=the Y value of the 2nd point
etc
Here is an example starting with 10 points:
http://i.imgur.com/U3lchMk.jpg
Would anyone know of a way to build this into Excel so that I can just copy the formula across the page to the horizontal limit? Or would you recommend a better way than using Excel?
As a secondary goal, I want to group the points into clusters that can connect by a distance lower than 2. But if I can accomplish the first goal, I can worry about the second later.
Actually, I was able to come up with the solution with a bit more research: i.imgur.com/9JL5Qni.jpg =SQRT(((INDIRECT("A"&$D2))-(INDIRECT("A"&E$1)))^2+((INDIRECT("B"&$D2))-(INDIRECT‌​("B"&E$1)))^2+((INDIRECT("C"&$D2))-(INDIRECT("C"&E$1)))^2)

Excel average every 0.5 meters, irregular distances between data points

I have a data set that has height values every so often, like topography data in a straight line with GPS coordinates. I used the GPS coordinates and trigonometry to make a cumulative distance column. However, the distance between points varies. Sometimes its 10 cm sometimes its 13, sometimes its 40.
I would like to take the average height every 0.5 meters, but sometimes the distance column doesnt even land on a multiple of 0.5! This would mean my output column would be significantly shorter than my raw data column.
I think my main problem is I do not know what this process is called in order to Google it. Another problem is that the distances are irregular as mentioned above. Things I think may have something to do with it:
averageif?
binning? I do not want a histrogram though, just the data.
Thanks for the help and if you do not know the answer but at least know what I should be writing in the search bars that would be helpful as well. Thanks!
Perhaps this will work for you. I made up a series of distance vs height measurements and determined that a third order polynomial curve fit pretty well. (A different curve might best fit your real data, so you would have to alter the formula accordingly). I then used that formula to derive a set of new heights for the desired ditances at, in my example five unit differences.
The formula under Extrapolated heights is an ARRAY formula entered into all the cells at once. You select D2:D12, enter the formula in D2 and, hold down CTRL-SHIFT while hitting ENTER. If you did this correctly, you will have the same formula in each cell surrounded by curly braces {...}
Then you can decide how you want to "Average" the heights.

Resources