What is the easiest way of composing this polynomial expressions in Excel? - excel

This is trivial in programming languages, but when I need to do something quick & dirty and to see whether I got the coefficients right, I usually go for Excel.
So, what have I got,
c1(i) c2(i) c3(i)
0,321323232 1 0
0,32132122 0 2
0,321214324 1 2
...
..
.
The polynomial expression is
KT = SUM( AEA0 * c1(i) + J * c2(i) + PD * c3(i) )
i=1,37
One approach would be to make columns with AEA0, J, PD (btw, these are constants) and then multiply & sum them with the coefficient columns. I don't like this one because it adds a lot of extra stuff, and it messes up my copy pasting later (when I copy paste the coefficients to a text file).
Second approach would be to manually form an expression clicking all the cells one by one,
KT = AEA0 cell * A1 + J * B1 + PD * C1 + AEA0 * A2 + J * B2 + PD * C2 + ...
you get the point. Is there a way to improve this approach in some way so it takes a range of A1 to A37?
Is there some better approach to forming this kind of expressions?

Put the value for AEA0 in Z1. Put the value for J in Z2. put the value for PD in Z3.
Then you can use:
=SUM(A1:A37)*Z1+SUM(B1:B37)*Z2+SUM(C1:C37)*Z3

Related

Excel: Sort cell base on specific text

Let's say I have something like this.
I want to sort it to be something like;
is there a function to do this in excel? Like sorting the data base on the x?
You can do that, using a helper column. However, you seem to have two criteria in your question:
Count the amount of x characters. This, you can achieve using a CountIF().
Sort, according to the location of the x character (in case there is only one).
You can achieve the second, using the following system (imagine that, instead of x, there's the number 1):
=G1 * 2^4 + F1 * 2^3 + E1 * 2^2 + D1 * 2^1 + C1 * 2^0
This will create the following numbers for your cases:
8 : Some Text : 1
9 : Some Text : 2
1 : Some Text : 4
...
Combining both calculations gives you what you want.

How to convert an "enumerate" to array

I am trying to calculate sum(a.*b) = a[1] * b[1] + a[2] * b[2]+.....
The array a with length n is present in the sheet. Values of b though are not present directly.
To get b, there is a column of data and n indexes. b[i] = data[indexs[i]]
One way to find sum(a.*b) is to first buffer the value of b using INDEX(data, indexes) and then SUM(a * b).
I want it to be done in one cell with no buffering. So I tried replacing b with the formula of b like SUM(a * INDEX(data, indexes)). But excel considers INDEX(data, indexes) to be iterable and gives me [SUM(a * b[1]), SUM(a * b[2]), ...]
How do I tell excel to take INDEX(data, indexes) as an array?
sample
In earlier versions of Excel (pre-O365), you have to use the following manoeuvre to deliver an array using Index as described here:
=SUMPRODUCT(D3:D4*INDEX(A2:A10,N(IF({1},B2:B3))))
The curly brackets around the 1 {1} are not strictly necessary, but I tend to leave them in to signal that I am using this trick.

Raising a number to the power of a range of numbers

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!

what does E represent in microsoft Excel?

Excel has just output this trendline: y = 0.032x4 - 5608.x3 + 4E+08x2 - 1E+13x + 1E+17
How can I convert this equation into a useable form without the E's.
(how do you interpret these E's)
You can use the trendline from a graph in an equation, but, in addition to translating it correctly, you need to also format the trendline to show a maximum number of decimals (e.g 15), else your results will not be congruent with the graph.
Your formula would translate into something like:
y = 0.032*(x^4) - 5608*(x^3) + 4E+08*(x^2) + 1E+13*(x) + 1E+17
4E+08 will be interpreted by Excel as being 4*10^8 or 400,000,000. You don't have to do that yourself,
However, unless you have a very old version of Excel, where the LINEST function did not work properly, it is usually simpler to just use worksheet functions for that purpose.
For example, if this is a line graph where y is your range of y-values; your trendline is a 4th order polynomial, and your x-axis is just serial numbers 1..n, you could use:
=LINEST($A$4:$A$12,SEQUENCE(COUNT(y))^{1,2,3,4})
to return your sequence of m values.
And to return a point along the curve, you could use
=SUM(LINEST($A$4:$A$12,SEQUENCE(COUNT(y))^{1,2,3,4})*A4^{4,3,2,1,0})
where A4 represents a new_x value.
If you don't have the SEQUENCE function, there are a variety of other functions that can be used to generate a sequence of values; or you can just select your known_x's (which you would have to do anyway if they are not sequential {1..n})
The Scientific format displays a number in exponential notation,
replacing part of the number with E+n, in which E (exponent)
multiplies the preceding number by 10 to the nth power. For example, a
2-decimal scientific format displays 12345678901 as 1.23E+10, which is
1.23 times 10 to the 10th power.
Before
y = 0.032x4 - 5608.x3 + 4E+08x2 - 1E+13x + 1E+17
After
y = 0.032x4 - 5608.x3 + 4 x 10^8x * 2 - 1 * 10^13x + 1 * 10^17
Basically really large numbers,4 x 10^8x*2=400000000x*2, 1 x 10^13x=10000000000000x, 1E+17=100000000000000000

Calculating distances between 3-D coordinates in large data set...with a minor twist

I am trying to use excel to calculate the distance between two points with x,y and z coordinates using the formula distance=SQRT((X1-X2)^2+(Y1-Y2)^2+(Z1-Z2)^2)). The formula works just fine for single calculations my problem lies in my ability to apply this formula to a large table similar to the attached image. (The diagonal should equal zero)
Example of the table I have and the table I want to make:
Is it possible to do this in excel? Any insight would be appreciated. Thanks, Derrick
Okay I am going to do two things -- (1) Outline the solution and (2) Teach you to fish by explaining how to do this in the future.
Okay as some have shown VLOOKUP is your friend however when using this it is best to have your lookup chart on its own page so that you can easily expand it later however if you want to show both on the results page you have examples of doing that as well.
Also keep in mind that programs love numbers -- so whenever you can replace strings with intelligible numbers do so it speeds up processing.
So in my example I put your City Chart on its own sheet (CityChart) as follows
City | X | Y | Z
1 1 1 1
2 3 4 6
3 6 7 3
4 3 5 6
6 10 5 20
So the first thing you want to do is make sure you can retrieve the data from your lookup chart in a manner that you expect. So on a separate sheet we create a Distance chart as follows:
City | 1 | 2 | 3 | 4 | 6 | etc ...
1
2
3
4
6
etc...
Then in position 1,1 we do the basic lookup in order to get X1
X1 => =VLOOKUP($A2, 'CityChart'!$A$2:$D$6, 2)
$A2 Means grab the column City number
'CityChart'!$A$2:$D$6 Means use the lookup chart on sheet (CityChart)
with this range. As stated this makes it easier
to expand later on.
2 Means in the CityChart get the value from column 2 -- and if you look
that is our column labeled X
$ Means freeze the following value when copying
Press and the value it shows should be : 1
Now you can copy that cell from 1,1 and paste it to 2,1 through 6,1 and you should get the corresponding results from your CityChart
Now copy the formula without the = sign into a cell for later reference
VLOOKUP($A2, 'CityChart'!$A$2:$D$6, 2)
We conquered hurdle one.
Now we need to get X2
Basically the same formula but instead of grabbing Column 1 we grab Row 1 as follows -- again in cell 1,1 we write
X2 => =VLOOKUP(B$1, 'CityChart'!$A$2:$D$6, 2)
Validate that it works, copy it in to cells 1,2 through 1,6 to make sure it returns the appropriate values then copy the formula for later reference
We now have ....
X1 => =VLOOKUP($A2, 'CityChart'!$A$2:$D$6, 2)
X2 => =VLOOKUP(B$1, 'CityChart'!$A$2:$D$6, 2)
So we need to extrapolate this to Y and Z or CityChart Columns 3 and 4 as follows:
X1 => VLOOKUP($A2, 'CityChart'!$A$2:$D$6, 2)
X2 => VLOOKUP(B$1, 'CityChart'!$A$2:$D$6, 2)
Y1 => VLOOKUP($A2, 'CityChart'!$A$2:$D$6, 3)
Y2 => VLOOKUP(B$1, 'CityChart'!$A$2:$D$6, 3)
Z1 => VLOOKUP($A2, 'CityChart'!$A$2:$D$6, 4)
Z2 => VLOOKUP(B$1, 'CityChart'!$A$2:$D$6, 4)
Now we need to expand this and move towards your formula. We start with setting down our two encapsulating ( ) and then copy/paste our references in adding the subtraction sign as we go
(X1 - X2) => (VLOOKUP($A2,'CityChart'!$A$2:$D$6,2) - VLOOKUP(B$1,'CityChart'!$A$2:$D$6,2))
(Y1 - Y2) => (VLOOKUP($A2,'CityChart'!$A$2:$D$6,3) - VLOOKUP(B$1,'CityChart'!$A$2:$D$6,3))
(Z1 - Z2) => (VLOOKUP($A2,'CityChart'!$A$2:$D$6,4) - VLOOKUP(B$1,'CityChart'!$A$2:$D$6,4))
Why do this systematically well for one to avoid the mistake that is in your formula for instances -- if you look closely you will see you have one too many ")"
Next we add the ^2 to the end
(X1 - X2) => (VLOOKUP($A2,'CityChart'!$A$2:$D$6,2) - VLOOKUP(B$1,'CityChart'!$A$2:$D$6,2))^2
(Y1 - Y2) => (VLOOKUP($A2,'CityChart'!$A$2:$D$6,3) - VLOOKUP(B$1,'CityChart'!$A$2:$D$6,3))^2
(Z1 - Z2) => (VLOOKUP($A2,'CityChart'!$A$2:$D$6,4) - VLOOKUP(B$1,'CityChart'!$A$2:$D$6,4))^2
Then all that is left is to put that into your SQRT( ) function along with the + signs
SQRT( (VLOOKUP($A2,'CityChart'!$A$2:$D$6,2) - VLOOKUP(B$1,'CityChart'!$A$2:$D$6,2))^2 + (VLOOKUP($A2,'CityChart'!$A$2:$D$6,3) - VLOOKUP(B$1,'CityChart'!$A$2:$D$6,3))^2 + (VLOOKUP($A2,'CityChart'!$A$2:$D$6,4) - VLOOKUP(B$1,'CityChart'!$A$2:$D$6,4))^2 )
Once you have the full formula copy it and place it in front of an = sign within cell 1,1 and press return you should get 0
Then copy it and paste it either to the full row or full column -- then copy the full row/column and highlight the remaining cells and paste -- viola fast and easy expansion of the code.
The following formula should work.
=SQRT((VLOOKUP(NUMBERVALUE(RIGHT($A11,1)),$A$2:$D$6,2,FALSE)-
(VLOOKUP(NUMBERVALUE(RIGHT(B$10,1)),$A$2:$D$6,2,FALSE)))^2+
(VLOOKUP(NUMBERVALUE(RIGHT($A11,1)),$A$2:$D$6,3,FALSE)-
(VLOOKUP(NUMBERVALUE(RIGHT(B$10,1)),$A$2:$D$6,3,FALSE)))^2+
(VLOOKUP(NUMBERVALUE(RIGHT($A11,1)),$A$2:$D$6,4,FALSE)-
(VLOOKUP(NUMBERVALUE(RIGHT(B$10,1)),$A$2:$D$6,4,FALSE)))^2)
The RIGHT part of each function takes the "City #" and and retrieves the identifying #
The NUMBERVALUE makes the identifying city # a numbervalue rather than text.
The first VLOOKUP of each pair uses the column list (presumably Col A) to find the numbers for the first city (make sure the column reference is absolute with the $ in front of the column letter).
The second VLOOKUP of each pair uses the row list across the top of the matrix to reference the second cities coordinates (make sure the row reference is absolute with the $ in front of the row number).
Use the "$A$2:$D$6" part of the formula to create an absolute reference of the cities' reference numbers and the x,y,z columns of information. (use $ in front of both row numbers and column letters)
The third element of each VLOOKUP refers to the column number of the absolute reference (see step 5). In this case x=2, y=3 and z=4.
The "false" in each VLOOKUP statement is probabally not necessary, but I like to use it to prevent mistakes. It ensures an 'exact match' in the VLOOKUP formula.
Just to do your homework:
If your sheet looks like this:
then simply use the arrayformula
{=SUM((INDEX($B$2:$D$7,MATCH($A11,$A$2:$A$7,0),)-INDEX($B$2:$D$7,MATCH(B$10,$A$2:$A$7,0),))^2)^0.5}
and fill down/right ;)
EDIT
=SUMPRODUCT((INDEX($B$2:$D$7,MATCH($A11,$A$2:$A$7,0),)-INDEX($B$2:$D$7,MATCH(B$10,$A$2:$A$7,0),))^2)^0.5
will also work (non-array-formula)

Resources