How to predict number sequences i.e. Excel? - excel

In Excel, there is a nice feature where if you enter 1, 2, 3 in three consecutive cells and then select the cells and drag down, it automatically fills in the rest of the cells as 4, 5, 6, 7, etc. It is also able to match more patterns. For example, if I did 2, 4, 6, 8, it would recognize I am adding 2 and then suggest 10, 12, 14, etc.
How does Excel know which numbers? Do they hardcode the different cases (i.e. adding some constant, subtracting some constant, multiplying by some constant) or is there some algorithm that can automatically predict this for you? (This question should be language-agnostic, but if it helps, I want to do this in jQuery)
Thanks!

I'm pretty sure it's a simple thing to do. Excel probably checks, when a user enters three numbers, the delta between each consecutive number. If they are the same both times, it will use that delta to predict the next number.

If you want to do this more generically than Excel does (only addition or subtraction of constant values), have a look at some interpolation algorithms from numerical methods point of view. This wikibook article is an ok tutorial.

In Excel, it only works with additions and substractions (that I know of, I just tried with multiplications and the results don't follow the same pattern as the originals).
Knowing that, I think it would be easy to calculate the difference between the first two cell, then check the difference between cell 2 and cell 3 to see if it's the same. You can then apply that transformation to the cells you want to predict.
*Example*
Cell1: 2
Cell2: 5
Cell3: 8
if(cell2 - cell1 == cell3 - cell2)
cell4 = cell3 + (cell2-cell1); //Cell4 will now be 11 since it increments by steps of 3
You could then use a for loop that would copy the value you want to all selected cells (if you want to make the next ten cells follow the pattern, use a for or a while loop that will update the value of those 10 cells)

Related

What function to use for this difficult excel calculation for the roulette wheel?

so I am a complete excel and math noob and I want to have a cell in excel which will display the "Pelayo number", which is used in calculating bias in a roulette wheel. You can read more about it here: https://www.roulette-bet.com/2015/06/the-roulette-bias-winning-method.html
enter image description here
Let me explain briefly what I want. As you can see on the image there are two columns, in one there are the numbers on a roulette wheel and and in the second one there is the frequency of each number. On top you see number of spins (852). The number on the bottom (23,02.....) is the expected frequency of each number. The table is dynamic, constantly evolving as I enter new data.
Now I want a cell to display the total number of positives. Which is calculated like this:
If there have been 300 spins, each numbers has to have been spun 300/36 = 8.33 in order to be breaking even. This means those which have been spun 8 times are losing a little, and those which have showed 9 times are winning something. If a number has appeared 14 times it is clear it has 14-8.33 = 5.67 which we will express in an abbreviated form like +5. Let’s suppose the exact same situation has occurred for 6 other numbers also, they all will make a total sum of 5.67 + 5.67 + 5.67 + 5.67 + 5.67 + 5.67+ 5.67 = 39.69. as no other number has been spun over 9 times, then we say the amount of total positives at this table at 300 spins is +39.
TLDR So ideally something like: Select all the numbers from (G6:G42) which are bigger than value in (G50) and then substract them one after another from the expected frequency (G50) and then add this all up.
I tried to solve it but just couldnt find a tutorial anywhere
I'll break this down for you, and show you a few helpful Excel concepts along the way.
Especially if you are a beginner, I'd recommend using a helper column. Helper columns are great ways to break down complicated functions into smaller, more manageable parts.
In H6, write =IF(G6>G$50,G6,0). That if statement will set us up for our sum, with either the value in G6 or a 0. The $ will be cleared up in a moment.
Then, hover your mouse over that cell, and a little square box will appear in the lower right corner of H6. Grab that tiny box, and drag it down to H42. This fills in the formula, adjusting all of the numbers relatively as you go. Note that the 50 stayed constant, however - that's what the $ did!
H6 is now your helper column. It doesn't find your answer, but it gets an important, intermediary step done.
Finally, wherever you'd like your answer, write =SUM(G6:G42), and you should be well on your way.
=SUMIF(G6:G42,">"&G50,G6:G42)-COUNTIF(G6:G42,">"&G50)*G50
It sums values that are over in G50 then distracts G50 value as much times as there were values to sum up to.
For example in case G50 is 23.02 and you have values 20, 21, 22, 23, 24, 25.
It would calculate like (22+23+24+25)-4*23.02

Count results across multiple conditions in Excel

I have the following table in which I want to compare scores across simulations for multiple players. How can I get the number of times that Phil Mickelson has a lower R1Score than Justin Rose?
This needs to be done in a formula of sorts, not using any PivotTables. I would need to compare the R1Score for Phil and Justin for SimNum 1, 2, 3, etc. to see how many times he beats Justin. Any help would be greatly appreciated!
If you have Office 365 you could use:
=SUM(IFERROR(--(FILTER(C2:C21,A2:A21="Phil Mickelson")>FILTER(C2:C21,A2:A21="Justin Rose")),0))
This is provided that the SimNum are in ascending order always.
If they're not in order but all values from 1 to x are present without any gaps, you could use the following:
=LET(value1,"Phil Mickelson",
value2,"Justin Rose",
data,A2:C21,
sorted,SORTBY(data,INDEX(data,,2)),
a,INDEX(sorted,,1),
c,INDEX(sorted,,3),
filter1,FILTER(c,a=value1),
filter2,FILTER(c,a=value2),
SUM(IFERROR(--(filter1>filter2),0)))
If your version of Excel has dynamic arrays this is easy to solve.
Start with this formula:
=COUNTIFS($C$12:$C$21,">"&C2)
If we drag that down column D we get these numbers: 9, 8, 9, 6, 4, 4, 9, 0, 8, 2 i.e. Simulation 1 is better than 9 simulations of Justin Rose, simulation 2 is better than 8, simulation 10 is better than 2 etc.
With Dynamic Arrays, instead of just supplying the cell containing Phil's first simulation, we can now provide his entire simulation range as well. This will give us a dynamic array, containing the same numbers as our original COUNTIF formula. Take note that the range is surrounded by a blue border.
Now we just need to add all of these numbers together to show how many total simulations are better:
=SUM(COUNTIFS($C$12:$C$21,">"&C2:C11))

Why is Excel not calculating the cube root as the cube root?

I have a suspicion Excel is calculating exponents that are repeating decimals represented as a fraction (e.g. 1/3) differently than ones that don't have repeating decimals (e.g. 1/2). It is preventing me for a formula that finds perfect cubes in a list of numbers.
Column A lists numbers 1 to 100.
Column B has the following formula (starting with row 5):
=IF($A5^(1/2)-ROUND($A5^(1/2),0)=0,1,0)
This should return "1" if the number in column A is a perfect square, like 1, 4, 9, etc. and does so correctly. This other formula I originally wrote also works: =IF(SQRT($A8)-ROUND(SQRT($A8),0)=0,1,0).
Column C has the following formula (starting with row 5):
=IF($A5^(1/3)-ROUND($A5^(1/3),0)=0,1,0)
Note that it is the exact same as the perfect square identifying formula, except there is a 3 where there was a 2. This is not returning a "1" for perfect cubes like 8, 27, 64. etc. (but does return a "1" for the number 1).
Can anyone help me correct this?
I apologize for not knowing how to pick a comment as an answer, so I aggregated the helpful comments and am posting them as an answer.
Main Explanation:
See Floating-point arithmetic may give inaccurate results in Excel. If you examine the underlying xml, you will see that Excel is calculating A1^(1/3) as 1.9999999999999998. The article explains why, and suggests some work arounds. – Ron Rosenfeld
Workaround I picked:
Can't you replace $A5^(1/3)-ROUND($A5^(1/3) with $A5 - ROUND($A5^(1/3))^3? – r3mainer
Thanks all!

Excel Sumif, Sumifs with partial strings in multiple columns?

So this is the simplified question I broke down from a former question I had here: Excel help on combination of Index - match and sumifs? .
For this one, I have Table1 (the black-gray one) with two or more columns for adjustments for various order numbers. See this image below:
What I want to achieve is to have total adjustments for those order numbers that contain the numbers in Total Adjustment column in the blue table, each of which will depend on the cell beside it.
Example: Order number 17051 has two products: 17051A (Apple) and 17051B (Orange).
Now what I want to achieve in cell C10 is the sum of adjustment for both 17051A and 17051B, which will be: Apple Adjustment (5000) + Orange Adjustment (4500) = 9500.
The formula I used below (and in the image) kept giving me error messages, and this happens even before I add the adjustment for Orange.
=SUMIF(Text(LEFT(Table1[Order Number],5),"00000"),text(B10,"00000"),Table1[Apple Adjustment])
I have spent the whole day looking for a solution for this and didn’t even come close to find any. Any suggestion is appreciated.
Assuming your headers always have the text "adjustment" in them, you could use:
=SUMPRODUCT((LEFT($B$4:$B$7,5)=B10&"")*(RIGHT($C$3:$F$3,10)="adjustment")*$C$4:$F$7)
In C10 you could add two sumproducts. This assumes that products are always 5 numbers long at the start. If not swop the 5 to use the length of the product reference part you are matching on.
=SUMPRODUCT(--(1*LEFT($B$4:$B$7,5)=$B10),$D$4:$D$7)+SUMPRODUCT(--(1*LEFT($B$4:$B$7,5)=$B10),$F$4:$F$7)
Which with table syntax is:
=SUMPRODUCT(--(1*LEFT(Table1[Order Number],5)=$B10),Table1[Apple Adjustment])+SUMPRODUCT(--(1*LEFT(Table1[Order Number],5)=$B10),Table1[Orange Adjustment])
Using LEN
=SUMPRODUCT(--(1*LEFT(Table1[Order Number],LEN($B10))=$B10),Table1[Apple Adjustment])+SUMPRODUCT(--(1*LEFT(Table1[Order Number],LEN($B10))=$B10),Table1[Orange Adjustment])
I am multiplying by 1 to ensure Left, 5 becomes numeric.

In EXCEL 2010: How i can do conditional formating to visualize the difference of two sets of variables...?

I would like to visualize the difference between two sets of variables e.g. I have two sets of variables Original and obtained as:
Original = {1, 5, 7, 9}
obtained = {2, 5, 6, 8}
Now, in Excel i want to visualize the difference between two sets, that means the variables are in original and also found in Obtained it can be colored in GREEN (cell color). The variables that could not find in the Obtained could be ORANGE and the additional variables could be RED.
(My algorithm use VC++ to generate "Obtained" sets, and i want to use MS Excel for conditional formatting)
Thanks in advance for your help.
I think maybe you might make a hidden row somewhere with something like:
=IF(ISNA(HLOOKUP(A1;$A$2:$D$2;1;0));"";"+")
assuming that your first set is in the first row, and the second set in the second - then drag the formula along the entire row of course - remember to keep the references absolute - if you change the comparison set range.
The notation above is openoffice calc but it's much the same in MSExcel (e.g. ; -> ,).
Now you conditionally format the second row ('obtained') with the "Formula is" (not "Value is"):
(A3="+")
for the positive case setting background to green and
(A3="")
for the negative case setting background to orange
Hope it helps at all.
yes use Conditional formatting.
Here are some links to help you:
Chip Pearson (Excel MVP legend) / cpearson.com
Debra Dalglish (Excel MVP Legend) / Contextures.com)
that should get you started
Philip

Resources