How to use the SUMX2MY2 function
What is the SUMX2MY2 function?
The SUMX2MY2 function calculates the sum of the difference of squares of corresponding values in two arrays.
Table of Contents
1. Introduction
What is the square?
In mathematics, the square of a number is the result of multiplying the number by itself. Squaring a number is denoted by x2. For example, 52 means 5 * 5 = 25.
Squaring a number results in a positive result as negative signs are removed in multiplication. (-5)2 = 25 Squares grow very rapidly. Already x2 reaches large values quickly as x increases, higher powers grow even faster.
The square root is the inverse operation of squaring. √25 = 5, since squaring 5 gives 25. Squaring is used in geometry to calculate area of squares, side length squared = area. Squaring is also used when calculating the area of a circle.
For example, A = π r²
A is the area.
r is the radius.
π is pi.
The graph of y = x2 is a parabola, symmetric about the origin.
Squares appear frequently in equations in physics, math, statistics, and other fields.
What is the difference of squares?
The difference of squares is an algebraic identity that relates the difference between two squared terms to the product of the sum and difference of those terms.
a² - b² = (a + b)(a - b)
Where a and b are numbers.
(a + b)(a - b) equals a² - ab +ba + b² which is a² - b²
For example:
x² - 16 = (x + 4)(x - 4)
The difference of squares formula is useful for factoring expressions and simplifying equations involving squared terms. It reveals the hidden factors in the difference of squares.
What is the sum of the difference of squares?
SUMX2MY2 function calculates the sum of x² minus y². The arrays x an y must be equal in size.
SUMX2MY2(array1, array2) = ∑(x² - y²)
2. Syntax
SUMX2MY2(array_x, array_y)
array_x | Required. The first array or range of values. |
array_y | Required. The second array or range of values. |
3. Example 1
This example demonstrates how to use the SUMX2MY2 function. The above image shows the input values in B3:B5 and C3:C5 respectively.
Formula in cell F3:
The result is displayed in cell F3 and it is 12. Lets calculate this value manually:
The first array array_x i 4, 3, and 4, the second array contains 2, 3, and 4.
The sum of the difference of squares
4² - 2² = 16 - 4 = 12
3² - 3² = 0
4² - 4² = 0
The sum is 12 + 0 + 0 equals 12.
4. Example 2
Calculate the length of leg 2 in a right triangle with hypotenuse equal to 10 units and leg 1 equal to 6 units?
What we know:
- A right triangle allows us to use the Pythagorean theorem:
a = √(c2 - b2) or b = √(c2 - a2) - Leg 1 (b) = 6
- Leg 2 (a) = unknown
Formula in cell C6:
The formula returns 8 in cell C6. Here is what it does in greater detail:
- Square the values in cells C4 and C3, then calculate the difference. SUMX2MY2(C4,C3)
- Calculate the square root of the difference. SQRT(SUMX2MY2(C4,C3))
Lets calculate the result manually.
Square the hypotenuse: 102 = 100
Square leg 1: 62 = 36
Calculate the difference between the hypotenuse and leg 1:
100 - 36 = 64
Calculate the square root of the difference: √64 = 8 units. Leg 2 is 8 units.
5. Example 3
An object accelerates from 2 m/s to 8 m/s over a distance of 10 meters. What is its acceleration?
Equation is: v2 = u2 + 2as
- v = final velocity (2 m/s)
- u = initial velocity (8 m/s)
- s = distance (10 meters)
- a = acceleration (unknown)
The equation becomes: a= (v2 - u2) / (2 * s)
Formula in cell C22:
Cell C22 returns 3 m/s2 which represents the acceleration from the initial speed 2 m/s to its final speed of 8 m/s across 10 meters.
6. Example 4
A large square (x) has a side length of 10 units, and a smaller square (y) has a side length of 8 units. Another large square (x) has a side length of 4 units, and a smaller square (z) has a side length of 3 units. What is the total area of x minus y and w minus z?
What we know:
- Square x side: 10 units
- Square y side: 8 units
- Square w side: 4 units
- Square z side: 3 units
Formula in cell C22:
The formula in cell C22 returns 43 square units which is equal to the total area of x - y and w - z. The image above contains a chart that displays
- x as a dark red square
- y as a smaller orange square inside the dark red square x
- w as a grey square
- z as a smaller blue square inside the grey square w
How is 43 square units calculated?
- Square x side: 10 units equals 100 square units
- Square y side: 8 units equals 64 square units
- Square w side: 4 units equals 16 square units
- Square z side: 3 units equals 9 square units
Total area = x - y + w - z
100 - 64 + 16 - 9 = 43 square units.
7. Example 5
This example demonstrates how you can use the SUMX2MY2 to calculate the variance of a given set of numbers. Note, the VAR.P and VAR.S functions are much easier to use than this formula.
Cells B19 to B28 contains numbers representing the weights of manufactured products. The image above shows a chart containing a blue line that represents the normal distribution based on a mean of 174 and a standard deviation of 15.85. The chart also shows the different standard deviations 1σ, 2σ, 3σ, -1a, -2σ, and -3σ which represents:
- 68% of the data falls between μ ± 1σ
- 95% of the data falls between μ ± 2σ
- 99.7% of the data falls between μ ± 3σ
Formula in cell E19:
Cell E19 returns 251.36 which represents the variance of the values in cell range B19:B28
Here's a breakdown of how it works:
- B19:B28 is the range of cells containing the numbers for which you want to calculate the average absolute deviation.
- AVERAGE(B19:B28) calculates the mean (average) of the numbers in the range.
- LAMBDA(a,SUMX2MY2(a,AVERAGE(B19:B28))) is a lambda function that calculates the sum of the absolute deviations from the mean for each number in the range.
- a represents each number in the range.
- SUMX2MY2(a,AVERAGE(B19:B28)) calculates the absolute deviation of each number from the mean, squares it, and then sums these squared deviations. However, the SUMX2MY2 function actually calculates the sum of the squares of the differences between corresponding values in two arrays, so in this case it's being used to calculate the sum of the squared differences between each value and the mean.
- BYROW(B19:B28,LAMBDA(a,SUMX2MY2(a,AVERAGE(B19:B28)))) applies the lambda function to each number in the range, effectively calculating the sum of the squared absolute deviations for each number.
- SUM(BYROW(B19:B28,LAMBDA(a,SUMX2MY2(a,AVERAGE(B19:B28))))) sums up these squared absolute deviations for all numbers in the range.
- COUNT(B19:B28) counts the number of values in the range.
- Finally, the formula divides the sum of the squared absolute deviations by the count of numbers to get the average of the squared absolute deviations, which is the variance of the set of numbers.
8. Function not working
The SUMX2MY2 function returns a
- #N/A error if the number of values in each array are not equal
- #NAME? error if you misspell the function name.
- propagates errors, meaning that if the input contains an error (e.g., #VALUE!, #REF!), the function will return the same error.
8.1 Troubleshooting the error value
When you encounter an error value in a cell a warning symbol appears, displayed in the image above. Press with mouse on it to see a pop-up menu that lets you get more information about the error.
- The first line describes the error if you press with left mouse button on it.
- The second line opens a pane that explains the error in greater detail.
- The third line takes you to the "Evaluate Formula" tool, a dialog box appears allowing you to examine the formula in greater detail.
- This line lets you ignore the error value meaning the warning icon disappears, however, the error is still in the cell.
- The fifth line lets you edit the formula in the Formula bar.
- The sixth line opens the Excel settings so you can adjust the Error Checking Options.
Here are a few of the most common Excel errors you may encounter.
#NULL error - This error occurs most often if you by mistake use a space character in a formula where it shouldn't be. Excel interprets a space character as an intersection operator. If the ranges don't intersect an #NULL error is returned. The #NULL! error occurs when a formula attempts to calculate the intersection of two ranges that do not actually intersect. This can happen when the wrong range operator is used in the formula, or when the intersection operator (represented by a space character) is used between two ranges that do not overlap. To fix this error double check that the ranges referenced in the formula that use the intersection operator actually have cells in common.
#SPILL error - The #SPILL! error occurs only in version Excel 365 and is caused by a dynamic array being to large, meaning there are cells below and/or to the right that are not empty. This prevents the dynamic array formula expanding into new empty cells.
#DIV/0 error - This error happens if you try to divide a number by 0 (zero) or a value that equates to zero which is not possible mathematically.
#VALUE error - The #VALUE error occurs when a formula has a value that is of the wrong data type. Such as text where a number is expected or when dates are evaluated as text.
#REF error - The #REF error happens when a cell reference is invalid. This can happen if a cell is deleted that is referenced by a formula.
#NAME error - The #NAME error happens if you misspelled a function or a named range.
#NUM error - The #NUM error shows up when you try to use invalid numeric values in formulas, like square root of a negative number.
#N/A error - The #N/A error happens when a value is not available for a formula or found in a given cell range, for example in the VLOOKUP or MATCH functions.
#GETTING_DATA error - The #GETTING_DATA error shows while external sources are loading, this can indicate a delay in fetching the data or that the external source is unavailable right now.
8.2 The formula returns an unexpected value
To understand why a formula returns an unexpected value we need to examine the calculations steps in detail. Luckily, Excel has a tool that is really handy in these situations. Here is how to troubleshoot a formula:
- Select the cell containing the formula you want to examine in detail.
- Go to tab “Formulas” on the ribbon.
- Press with left mouse button on "Evaluate Formula" button. A dialog box appears.
The formula appears in a white field inside the dialog box. Underlined expressions are calculations being processed in the next step. The italicized expression is the most recent result. The buttons at the bottom of the dialog box allows you to evaluate the formula in smaller calculations which you control. - Press with left mouse button on the "Evaluate" button located at the bottom of the dialog box to process the underlined expression.
- Repeat pressing the "Evaluate" button until you have seen all calculations step by step. This allows you to examine the formula in greater detail and hopefully find the culprit.
- Press "Close" button to dismiss the dialog box.
There is also another way to debug formulas using the function key F9. F9 is especially useful if you have a feeling that a specific part of the formula is the issue, this makes it faster than the "Evaluate Formula" tool since you don't need to go through all calculations to find the issue..
- Enter Edit mode: Double-press with left mouse button on the cell or press F2 to enter Edit mode for the formula.
- Select part of the formula: Highlight the specific part of the formula you want to evaluate. You can select and evaluate any part of the formula that could work as a standalone formula.
- Press F9: This will calculate and display the result of just that selected portion.
- Evaluate step-by-step: You can select and evaluate different parts of the formula to see intermediate results.
- Check for errors: This allows you to pinpoint which part of a complex formula may be causing an error.
The image above shows cell reference D3:D4 converted to hard-coded value using the F9 key. The SUMX2MY2 function requires equal number of values in both arrays which is not the case in this example. We have found what is wrong with the formula.
Tips!
- View actual values: Selecting a cell reference and pressing F9 will show the actual values in those cells.
- Exit safely: Press Esc to exit Edit mode without changing the formula. Don't press Enter, as that would replace the formula part with the calculated value.
- Full recalculation: Pressing F9 outside of Edit mode will recalculate all formulas in the workbook.
Remember to be careful not to accidentally overwrite parts of your formula when using F9. Always exit with Esc rather than Enter to preserve the original formula. However, if you make a mistake overwriting the formula it is not the end of the world. You can “undo” the action by pressing keyboard shortcut keys CTRL + z or pressing the “Undo” button
8.3 Other errors
Floating-point arithmetic may give inaccurate results in Excel - Article
Floating-point errors are usually very small, often beyond the 15th decimal place, and in most cases don't affect calculations significantly.
Functions in 'Math and trigonometry' category
The SUMX2MY2 function function is one of 62 functions in the 'Math and trigonometry' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form