Raising a number to the power of a range of numbers - excel

The formula I would like to use looks something like this: SUMPRODUCT(x^(1:n),y^(n:1)). n=values in column A. 1:n is the exponents in forward progression from 1 to n in steps of 1. n:1 is the exponents in reverse progression from n to 1 in steps of 1. I would like the formula to be dynamic to fill in column B with the n values based on column A.

Try:
=SUMPRODUCT(5^ROW(1:100))
Or in Excel O365
=SUM(5^ROW(1:100))
As per #RonRosenfeld, a more sturdy solution could be =SUM(5^SEQUENCE(100)) in Excel 365.
EDIT: Based on OP's comments he could use (no O365):
=SUMPRODUCT(5^ROW(A1:INDEX(A:A,COUNTA(A:A))),7^LARGE(ROW(A1:INDEX(A:A,COUNTA(A:A))),ROW(A1:INDEX(A:A,COUNTA(A:A)))))

You can store the powers in a column and use the array formula:
SUM((A1:A100)^$B$1) where A column contains 5 in each cell and B column contains the range of powers you want to use. You can use an array formula in the different cell to get the answer.

Use the SERIESSUM function
The Excel SERIESSUM function returns the sum of a power series, based on the following power series expansion:
Power Series Equation
The syntax of the function is:
SERIESSUM( x, n, m, coefficients )
Where the function arguments are:
x - The input value to the power series.
n - The first power to which x is to be raised.
m - The step size that n is increased by, on each successive power of x.
coefficients - An array of coefficients that multiply each successive power of x.
The number of values in the supplied coefficients array defines the number of terms in the power series. This is illustrated in the following examples.
Example 1:
In the spreadsheet below, the Excel Seriessum function is used to calculate the power series:
5^1 + 5^2 + 5^3 + 5^4 + 5^5
formula: =SERIESSUM( 5, 1, 1, {1,1,1,1,1} )
output = 3905
Example 2:
1 * 2^1 + 2 * 2^3 + 3 * 2^5 + 4 * 2^7 + 5 * 2^9
formula: =SERIESSUM( 2, 1, 2, {1,2,3,4,5} )
output = 3186
I hope this is of help.

An Alternative Answer again. I think the correct for your case :-)
Using the SERIESSUM function allows the use of different coefficients therefore the reason for the use of the coefficients in an array. But because the coefficients are the same then this is simply a geometric progression.
The following formula will do that for you:
=n+n*(n)^(1)*(1-(n)^c)/(1-n)
where "n" is the number (5) and "c" is the number of the series (100)
This becomes:
=5+5*(5)^(1)*(1-(5)^100)/(1-5)

=SUMPRODUCT(5^ROW(A1:INDEX(A:A,COUNTA(A:A))),7^LARGE(ROW(A1:INDEX(A:A,COUNTA(A:A))),ROW(A1:INDEX(A:A,COUNTA(A:A)))))
This formula worked flawlessly!!!
Thank you #JvdV and everyone else for your efforts in helping me! GREATLY APPRECIATED!

Related

Sumproduct summing and multiplying 2 matrixes - 4 columns (not criteria)

I have some columns and i need pr line to add say from O:S and then multiply with corresponding values from column N
So first sum from O:S then multiply with N:N
I could do
=SUMPRODUKT(N:N;O:O) + SUMPRODUKT(N:N;P:P) + SUMPRODUKT(N:N;Q:Q) + SUMPRODUKT(N:N;R:R) + SUMPRODUKT(N:N;S:S)
so I multiply N with each of the columns O to S but im sure there is a better way !
Specialy since it could be from S through QQ and that would be one boring formula to write
=SUMPRODUKT(HVIS.FEJL(N:N*O:Q;0))
' or in English
=SUMPRODUCT(IFERROR(N:N*O:Q,0))
Thank you #VBasic2008 and #mayukh-bhattacharya
SUMPRODUCT: The Multiplier of Arrays
As expected, it's as easy as:
=SUMPRODUCT(N:N*O:S)
Here's a small visual study I 'conducted':

Excel Dynamic Array formula to create a running product of a column

I need to create a running product from a column of numbers (I could use a row, but a column is easier to demonstrate here.) The input might be any arbitrary array. In fact, in the application where I would deploy this, it will not be a range, but rather another dynamic array within a LAMBDA formula. Here is an example of the Input column of numbers and the desired Output from the formula:
Inputs
Expected Dynamic Array Output
10
10
8
80
3
240
4
960
5
4800
The formula would spill the results.
There are lots of solutions for a running total, but I've found no solution for a running product. I have tried a few different approaches, including SUBTOTAL and AGGREGATE with no success. I have also built a number of approaches that get the result, but are hard-coded to a fixed number of rows. I need the formula to adapt to any arbitrarily sized number of rows. The following formula is the closest I have gotten so far.
This LET formula delivers the result, but, as you can see is fixed to 5 rows:
=LET( a, {10;8;3;4;5},
v, SEQUENCE( ROWS(a) ), h, TRANSPOSE( v ),
stagr, (v - h + 1) * (v >= h),
m, IFERROR(INDEX( a, IF(stagr>0,stagr,-1), ), 1),
almost, INDEX(m,v,h) * INDEX(m,v,h+1) * INDEX(m,v,h+2) * INDEX(m,v,h+3) * INDEX(m,v,h+4),
result, INDEX( almost, , 1 ),
result )
The arbitrary array of numbers input is placed in the variable a.
The next step is to create some indexes that will be used to address these numbers: v is a sequence of vertical rows for each number in a and h is a the same sequence, but transposed into columns. stagr is an index matrix that is created from v and h that will later be used to address each item in a to form it into a multiplication matrix. If you replace the last result with stagr, you can see the shape of stagr. It just shifts a column down by one row until they are shifted all the way down.
Now we create the mulitplication matrix m using stagr by simply using INDEX, like this: INDEX(a,stagr). But this is not exactly what is needed because it takes the first row value (10) and replicates it because an INDEX of 0 is treated the same as 1. To get what we want, I forced an error by using and internal IF statement like this: INDEX( a, IF(stagr>0,stagr,-1) ) to replace the 0 results with -1. i.e. it will produce this:
Now, replace the errors with 1's by using IFERROR, so this explains how m is created and why. The result is a matrix like this:
and by multiplying m row-wise, we get the output we want, but this is where I fail.
For illustration, I created a variable almost that shows how I am trying to do a row-wise multiplication.
almost, INDEX(m,v,h) * INDEX(m,v,h+1) * INDEX(m,v,h+2) * INDEX(m,v,h+3) * INDEX(m,v,h+4)
You can see that I crudely multiplied one column times the next and the next... and using h + offset to get there. This produces the almost matrix and result just delivers the first column of that matrix, which contains the answer.
While an answer might be a good replacement for almost that would be dynamically sized, that is not my real question. I want a running product and I suspect that there is a wholly different approach than simply replacing my almost.
Just to be clear, the result must be a dynamic array that spills with no helper cells or CSE drag-down.
oh... and no VBA. (#stackoverflow - please add a no-VBA tag)
The only way I can find is to use DPRODUCT with OFFSET, but that requires a title row. It does not matter what is in the title row(it can even be empty), just that it is included.
=DPRODUCT(OFFSET(A1,0,0,SEQUENCE(COUNT(A:A),,2)),1,$ZZ1:$ZZ2)
The $ZZ1:$ZZ2 can be any empty cell reference.
If the values in A are dynamic then we can do:
=DPRODUCT(OFFSET(A1,0,0,SEQUENCE(ROWS(A2#),,2)),1,$ZZ:$ZZ)
There are plenty of interesting answers here. But, if summation is easy why not take logarithms of the number you want to multiply, sum those logarithms and then calculate the exponent of your sum to return to the product of the original numbers.
i.e. exploit the fact that ln(a * b) = ln(a) + ln(b)
Whilst not available to everybody (yet) we can use SCAN()
Formula in A1:
=SCAN(1,{10,8,3,4,5},LAMBDA(a,b,a*b))
The 1st parameter is our starting value, meaning the 1st calculation in the nested LAMBDA() is '1*10'.
The 2nd parameter can both take a 1D- & 2D-array (written or range-reference).
The 3rd parameter is a nested LAMBDA() where the result of our recursive function will then be used for the 2nd calculation; '10*8'. And the 3rd...etc. etc.
In the above sample a vertical array is spilled but when horizontal input is used this will obviously result in an horizontal spilled output. When a 2D-array is used this will spill a 2D-array as result.

Unable to SUM from COUNTIF

I have produced a set of data using a countif as exampled below:
=COUNTIFS(Matrix!$C6:$EZ6,"1",Matrix!$C$5:$EZ$5,"Attainment",Matrix!$C$3:$EZ$3,AD$3)
What this is doing is looking at a students grades against a subject and calculating the count of that grade. I have 5 grades, *, 1, 2, 3, 4, so I have 5 sets of calculated columns for each subject. What I am now trying to do is a weighted sum using the results of these countif's. * = 0, 1=1,2=2 etc, however students can get more than 1 grade per subject so I need to average these.
Student X got two 2 grades for biology and one 3 grade, I need to do (2x2/2) + (1x3/3) = 2.3
I have tried
=SUM((F4*0)+(AG4*1/AG4)+(BH4*2/BH4)+(CI4*3/CI4)+(DJ4*4/DJ4))
However, I get a divide by zero error as not all cells hold a value above zero.
Is there a way to create a formula that says if the cell value is greater than zero then do the calculations, but if not ignore. I can't do a nested if. So, if the sum of AG4*1/AG4 results in a number then add this, but if it produces a zero, do not and move on and do the same for the next calculation. I can't do a nested if as more than one calculation may return a positive value.
Your weighting formula seems wrong. You wrote '(2x2/2) + (1x3/3) = 2.3'. However, (2x2/2) + (1x3/3) returns 3.
Shouldn't it be (2x2) + (1x3) / (2+1) = 2.3 ?
Try using the following formula:
=(F4*0)+(AG4*1)+(BH4*2)+(CI4*3)+(DJ4*4) / SUM(F4,AG4,BH4,CI4,DJ4)
You can use wrap it in an IFERROR function to avoid errors for students with no grades

Summing a Product in Excel, over the same parameters

I've been struggling with something in excel which is quite easy to do individual cases of using an array, but I want to do in a single cell.
Effectively, in row C I have the multipliers I need, lets call them i_k, for j from 1 to n. The equation I want to calculate in mathematical notation is;
Sigma(from j = 0 to n) (Pi(from k = j to n) (i_k))
But I'm not quite sure how best to go about this. Effectively it should be;
(i_1)^n + (i_2)^(n-1) + (i_3)^(n-2) + ...
In the end. Any help?
I dont know if this is an elegant solution but I think this might solve it for you.
The key is to make a table so that your formulas continue.
The screenshot I have taken explains the formula I have used with its explanation I have used on top of it.
-- The first column will have the intended values of I
-- The second column's first row will have the value of N
-- The third column will have a formula which says:
=IF(ISNUMBER([#[Values of N]]),[#[Values of N]],C2-1)
This will give you the decreasing value of N
Now just multiply N with I on the 4th column using a simple multiplication and add the final result:

How to convert a matrix to a single column using Excel

I have the following matrix in Excel:
3 Columns: A, B, C
Row 1: a b c
Row 2: d e f
Row 3: ghi
What I need is a single column with all these values. The result should look like that:
a
b
c
d
e
f
g
h
i
The TRANSPOSE function doesn't work for that case. I tried out the INDIRECT function, but did not find a solution. I would rather prefer to handle it with standard Excel formulas than with a makro.
Any ideas?
Say we have:
In E1 enter:
=INDEX($A$1:$C$3,ROUNDUP(ROW()/3,0),IF(MOD(ROW(),3)=0,3,MOD(ROW(),3)))
and copy down to get:
Using similar formulas you can map any two dimensional table into a single row or single column. It is equally easy to map a single column or row into a table.
The answers above are quite good, but IMHO, the solution provided by Chip Pearson here (http://www.cpearson.com/excel/TableToColumn.aspx), is superior is most respects since it immediately/automatically:
1) Determines the Row/Col delim values on its own, and immediately works for rectangular, e.g. above one must explicitly enter 3 for num Cols and 3 for num Rows, and must also figure out which is which. Whereas Pearson's solution does this automatically (eg. rmf's comment/concern above).
2) Pearson provides both variants for Col-ordered and also Row-ordered.
For a generalized approach that will create an array, you can use:
=LET( Matrix, $A$1:$C$3,
rM, ROWS( Matrix ),
cM, COLUMNS( Matrix ),
cells, SEQUENCE( 1, rM * cM, 0 ),
INDEX( Matrix, INT( cells / cM ) + 1, MOD( cells, cM ) + 1 )
)
While this takes advantage of the LET function, it is used for readability. For those not using Excel365, it is possible to do this without LET, but it is just painful to read .
If you need the result to be delivered as a column, change the order of arguments in SEQUENCE
= LET( Matrix, $A$1:$C$3,
rM, ROWS( Matrix ),
cM, COLUMNS( Matrix ),
cells, SEQUENCE( rM * cM, 1 , 0 ),
INDEX( Matrix, INT( cells / cM ) + 1, MOD( cells, cM ) + 1 )
) )
Of course, A1:C3 can be any arbitrarily shaped array.
This was already covered in Item 2 from the very general
Excel: Formulas for converting data among column / row / matrix :
The top cell of your target range (say, $H$1) should contain
=INDEX($A$1:$C$3,INT((ROW()-ROW($H$1))/3)+1,MOD(ROW()-ROW($H$1),3)+1)
where $A$1:$C$3 cotains your source data.
Copy the formula downwards as needed.
You could also use
=OFFSET($A$1,INT((ROW()-ROW($H$1))/3),MOD(ROW()-ROW($H$1),3))
as metioned in the referred article.
I suggest you to check Excel unpivot option to perform your task.
Select your matrix
Go through the Get & Transform section in the Data tab and click From Table/Range
In the new Power Query Editor select the columns you want to unpivot
Go through the Any Column section in the Transform tab, click the arrow nearby Unpivot Columns and choose the best option (if you follow the step 3 you can click Unpivot only selected columns)
Close & Load
This process is useful especially for complex matrices.
Check the above link for further information
With the current version of Excel, I realized operations with matrix has improve greatly. For converting a matrix to a single column, I suggest combining INDEX and SEQUENCE Functions in the following way:
Matriz_to_Column_Formula:
=INDEX(matrix_range,
TRUNC((SEQUENCE(ROWS(matrix_range)*COLUMNS(matrix_range),1,0,1))/COLUMNS(matrix_range)+1,0),
MOD(SEQUENCE(ROWS(matrix_range)*COLUMNS(matrix_range),1,0,1),COLUMNS(matrix_range))+1)
If you want to remove empty spaces:
=FILTER(Matriz_to_Column_Formula, Matriz_to_Column_Formula<>"")
Here is a short explanation:
Index requires 3 things: matrix source, row and column. The row and column you calculate each time allows index to point at that specific element in your matrix source. Index would give you as many elements as you require, which is Rows*Columns.
Let me expand on Rows and Columns using SEQUENCE to navigate by each element:
Row:
TRUNC((SEQUENCE(ROWS(matrix_range)*COLUMNS(matrix_range),1,0,1))/COLUMNS(matrix_range)+1,0)
The formula SEQUENCE will generate as many elements as your matrix has, starting from 0 until Rows*Columns-1, and the division by columns will point only at a specific row. The +1 is used because sequence starts at 0 and INDEX Row element works from 1 to n. TRUNC is used only to get a integer number of the row.
Column:
MOD(SEQUENCE(ROWS(matrix_range)*COLUMNS(matrix_range),1,0,1),COLUMNS(matrix_range))+1
Here you apply the same principle, using SEQUENCE to generate as many elements as your matrix has from 0 to Rows*Columns-1, and by getting the remainder between the sequence and Columns you will point to the column you need to.
Alright, this is my first post, hope this helps anyone. Thanks for you help in many occasions!
Example in Excel:
Matrix to Single Column - Example in excel
Opt 1:
=INDEX(C3:E7,
TRUNC((SEQUENCE(ROWS(C3:E7)*COLUMNS(C3:E7),1,0,1))/COLUMNS(C3:E7)+1,0),
MOD(SEQUENCE(ROWS(C3:E7)*COLUMNS(C3:E7),1,0,1),COLUMNS(C3:E7))+1)
Opt 2:
=IF(INDEX(C3:E7,TRUNC((SEQUENCE(ROWS(C3:E7)*COLUMNS(C3:E7),1,0,1))/COLUMNS(C3:E7)+1,0),MOD(SEQUENCE(ROWS(C3:E7)*COLUMNS(C3:E7),1,0,1),COLUMNS(C3:E7))+1)="","",INDEX(C3:E7,TRUNC((SEQUENCE(ROWS(C3:E7)*COLUMNS(C3:E7),1,0,1))/COLUMNS(C3:E7)+1,0),MOD(SEQUENCE(ROWS(C3:E7)*COLUMNS(C3:E7),1,0,1),COLUMNS(C3:E7))+1))
Remove Empty:
=FILTER(INDEX(C3:E7,TRUNC((SEQUENCE(ROWS(C3:E7)*COLUMNS(C3:E7),1,0,1))/COLUMNS(C3:E7)+1,0),MOD(SEQUENCE(ROWS(C3:E7)*COLUMNS(C3:E7),1,0,1),COLUMNS(C3:E7))+1),
INDEX(C3:E7,TRUNC((SEQUENCE(ROWS(C3:E7)*COLUMNS(C3:E7),1,0,1))/COLUMNS(C3:E7)+1,0),MOD(SEQUENCE(ROWS(C3:E7)*COLUMNS(C3:E7),1,0,1),COLUMNS(C3:E7))+1)<>"")

Resources