Related
I'm a little stuck on an Excel question where I am required to assign certain locations (A, B, C, D, E and F) to output North, Centre and South in the column called 'Area'.
For example I am told that:
if any individual works in location A, C or D that would be classified as South.
If the work area is B and E then it would be Centre.
And finally if anyone works in area F then it would be North.
How should my external cells look?
Assuming the area letter to be assigned is in A1,
One way:
=IF(A1="F","North",IF(OR(A1="B",A1="E"),"Centre","South"))
This is probably the closest to what you were attempting. South was left as a default value to save specifying three letters for it (A, C and D - North and Centre only required three between them).
Another way:
=CHOOSE(CODE(A1)-64,"South","Centre","South","South","Centre","North")
This converts the letter into its code number and then deducts 64 (so A gives rise to 1, B to 2 etc.) and then feeds that as the choice to be selected from the options shown.
A third way:
=LOOKUP(R1,{"A","B","C","D","E","F"},{"South","Centre","South","South","Centre","North"})
Similar to the second way but without the character code conversion. A formula version of what is more often achieved with a lookup table (below).
A fourth way:
=VLOOKUP(A1,AreaTable,2,0)
This as mentioned by #Tim Williams. AreaTable was my choice of name for a Named Range comprising A to F in sequence in one column and in the column immediately to the right of that (matching rows) the same "South", "Centre", .... , "North".
IF
OR
CHOOSE
CODE
VLOOKUP
There are other ways such as, instead of the vertical Named Range, a horizontal one and HLOOKUP.
Am running Office Professional Plus 2013 on Windows 7.
Have a matrix as depicted in the following image:
Full matrix data is found in this Google spreadsheet. There are two tabs - generic terms and specific terms.
Matrix is used to classify items - such as specific plants. There are items assigned to this matrix, but they are not shown to reduce complexity.
The matrix is a normalized matrix, meaning that the columns are fixed - there is place in the matrix for all possible values. But in many cases there is no value (a NULL value) for a column. For example, the genus on row 8 is defined by kingdom : subkingdom : division : class : order : family : genus.
The columns subdivision, subclass, superorder, suborder and family are not used to define that specific genus. In contrast, the genus on row 14 is defined by subdivision.
Using symbols, the normalized matrix looks as follows:
The goal is create a de-normalized matrix - to reshape the matrix where a column no longer has a meaning, but is just a level in the outline. The general approach is to delete a NULL cell and - on the next line(s) - move its dependent "children" left.
The manual process would be:
Delete D5 and move Class left.
Delete E6 and move Order left.
Repeat ad nauseam.
The de-normalized matrix would look like this:
Fortunately, symbols in the first three columns are never NULL (C - constant) - we can reference them, but do not need to move them. But the position of a symbol in all other columns is variable (V - variable), depending on which nulls have been deleted.
There is one wrinkle. There are instances where an item (implied but not shown) is not mapped to genus. Instead, the item is mapped to a broader terms such as family. Row 15 is an example where family is the terminal node; genus is not used to define this item.
How to create an Excel formula or script that:
deletes a NULL position
on the row with the deleted NULL position, moves the term left
on the next row(s) that are related to the parent cell, move the term(s) to the left?
If it is easier to work with names (division, subdivision, class, etc.) than with symbols, that's OK. The Google spreadsheet provides the generic term and the specific term.
Here's a sample output of my formula based solution:
There are 2 helper columns (M, N).
Formula in M2 (calculates current item's position in row), fill the column with it:
=MATCH("*",A2:L2,0)
Formula in N2 (calculate new item's position in row), fill the column with it:
=IF(M2-M1>0,N1+1,IFERROR(LOOKUP(2,1/($M$1:M1=M2),$N$1:N1),M2))
Formula in O2 simply places the item in right column, fill entire range with it:
=IF($N2=O$1,INDEX($A2:$L2,1,$M2),"")
It takes some time to calculate all rows, but I think it produces the desired output.
EDIT:
I think I found a bug in my solution, the formula in N2 should be:
=IF(M2-M1>0,N1+1,LOOKUP(2,1/($M$1:M1<M2),$N$1:N1)+1)
I didn't notice it earlier, because it affects row 2468 (Amborellanae).
I have data for re-sightings of individuals in terms of their X (column G) and Y (column H) co-ordinates and the time (day) recorded in column B.
I have several thousand data entries and want to manipulate an equation so I can autofill an entire column to plot.
Where time = 0, that is the release point and I want the distance moved column to remain empty. So by using the IF function, I want to look at daily movement by calculating the Euclidean distance with a simple pythagoras equation, the SQRT function.
The equation I have written is as follows:
=IF(B2 > 0, "=SQRT(((G2-H2)^2)+((G3-H3)^2))", " ")
Where t=0, the cells remain empty as I wished. However, instead of providing me with a numerical value according to the equation, it just writes the equation exactly as it appears. When removing the inverted commas I get TRUE, so that's not it.
What am I doing wrong?
Using quotation marks as you did around "=SQRT(((G2-H2)^2)+((G3-H3)^2))" means just that, to have the result be the string between the quotation marks. What you want is to drop the quotation marks and the =:
=IF(B2 > 0, SQRT(((G2-H2)^2)+((G3-H3)^2)), "")
However, I think you got your formula wrong as you are mixing X and Y. Should it not be:
SQRT((G3-G2)^2 + (H3-H2)^2))
Also, you might be able to do away with the IF altogether by just starting the formula one cell down.
First of all, let me show you guys the equation in question.
In this equation S, V, and t are known constants. CFL is also known. We have an initial value for D, and we have no idea what k is.
What I need to do is find ideal values for both D and k that would minimize the residuals squared of a calculated CFL and a measured CFL. Using residuals squared is just a way for me to check if they're the best possible values, but it's fine if there's another way to go about this that uses some other method.
The residual squared is just the absolute value of the difference between the calculated and measured CFLs, which is then squared. The lower the residual squared, the better the fit we have. So I need the smallest possible residual squared resulting from putting both k and D into the equation. That'll result in a calculated CFL, which I can then compare to a measured CFL, allowing me to calculate the residual squared.
My first idea for how to do this, since I'm not sure how to use Excel equations, was to fix the value of D (since we have an initial starting value to work from) and then vary through different values of k, putting them into the equation to find a calculated CFL, and comparing that to the measured to find the residuals squared, until I find one that results with the smallest residuals squared. Then I fix k at that ideal value, and vary D until I find the smallest residual there as well. Then I fix D again, and go back to varying k. My idea was that I could keep bouncing back and forth like that until both D and k were within a certain percentage of their previous values. I assumed it would reach some sort of equilibrium with this method
However, the numbers just go crazy, and end up either going to zero or going to infinity. So I need to rework my process. Which is where you guys come in!
How would you go about finding the most ideal values for both D and k, which would result in a calculated CFL closest to the measured one, assuming you are given values for every variable above apart from k? Remember to factor in that the value of D given initially is simply a starting place to work from, and is not the most ideal value.
I've been working on this program for a long time (at least a month), and I'm just stuck as hell and desperate. I was hoping you guys could help me out.
Here are some initial values to work with:
S = 19.634954
V = 12.271846
D (initial) = 0.01016482
CFL (measured) = 0.401
t = 4
k = ?
Thank you for any ideas you might have.
As Dean said, your system has two unknowns, and in the general case an infinite number of solutions (different pairs of (D,k)). By fixing D, CFL is a continuous function of k, and as such, you should be able to find a k that gives the CFL you measured (within some accuracy). For this problem (i.e., finding k given CFL) you can use the Goal Seek tool. Here is how:
1) Problem setup:
Use the name of the variables to name the cells in which you input their values (Go to Formulas--> Defined Names --> Define Name and give some the name of each variable to a cell). Then input the values of your parameters in these cells, (give k an arbitrary value, eg = 1), and input the formula in cell CFL like:
=(S/V)*SQRT(D/k)*(ERF(SQRT(k*t))+SQRT(k*t/PI())*EXP(-k*t))
Again, note that S,V,D,k and t are defined as named ranges.
2) Problem Solution:
Go To Data --> Data Tools --> What-If Analysis --> Goal Seek and enter the following parameters:
Set Cell: CFL
To value: 0.401
By changing cell: k
This gave me k=0.151759378, which results in CFL = 0.401261265054823.
I hope this helps?
Edit: Finding some solution pairs using VBA:
1) Place the measured CFL value in a cell (I chose H2).
2) Replace named ranges k, D and CFL. I used rngK, rngD and rngCFL, each one starting from row 2 till row 20.
3) Fill down rngD with a step (I took 0.01) using the formula =INDEX(rngD,ROW()-ROW($C$2))+0.01. The first entry of rngD is in cell C2 and has the value 0.01016482. The formula is copied down to all other cells in the range.
4) Fill down rngK with some initial values (I took =1).
5) Fill down the rngCFL range with the formula =(S/V)*SQRT(INDEX(rngD,ROW()-ROW($G$1))/INDEX(rngK,ROW()-ROW($G$1)))*(ERF(SQRT(INDEX(rngK,ROW()-ROW($G$1))*t))+SQRT(INDEX(rngK,ROW()-ROW($G$1))*t/PI())*EXP(-INDEX(rngK,ROW()-ROW($G$1))*t)). I use the ROW() and INDEX() functions to refer to the Range element I need.
6) Finally, use this code in a sub:
Dim iCnt As Long
For iCnt = 1 To Range("rngk").Count
Range("rngCFL")(iCnt).GoalSeek goal:=Range("H2"), changingCell:=Range("rngK")(iCnt)
Next iCnt
The above generates 19 pairs (D,k) that give the measured CFL value.
You can't solve for two unknown variables in a 1 formula system. However if I take D as given then you have a 1 unknown/1 formula system.
I just simply used 1 column as a guess of k (for me column B. I used another column to represent the calculated CFL with the guessed k (for me column C). I have another column that has either a 1 or -1 (for me column D). Lastly I have a column that represents the absolute value by which I want to increment my guess.
I named cells with the given values of the variables to make it easier to use them.
I started with a guess of k=1.
Here are my formulas in my first row which was 7.
B7=.1
C7 =(s/v)*(d/B7)^0.5*(ERF(((B7*t)^0.5))+((B7*t)/PI())^0.5*EXP(-1*B7*t))
nothing in D7 or E7
in row 8:
B8=B7+E8+D8
C8==(s/v)*(d/B8)^0.5*(ERF(((B8*t)^0.5))+((B8*t)/PI())^0.5*EXP(-1*B8*t))
D8=1
E8=.01
in row 9 the B and C column is just copied down but D and E are as follows
D9==IF(C9>cfl,1,-1)
E9==IF(D9=D8,E8,E8/10)
Once you get those in you can just copy down however many rows you want.
What this does is every time the residual of the CFL switches signs the increment's sign will also flip. Additionally, the absolute value of the increment will also shrink by a factor of 10 to give more precision as it goes.
This is by no means the best way to solve your problem but it is a way.
I have this chart in which if any point in graphs exceeds specific limit then its color should change.
can anyone suggest me how to get the chart in VBA and then apply this kind of condition e.g i want to change the color of highest point in the above graph . Any help would be highly appreciated.
Using: ActiveWorkbook.Sheets("Sheet1").ChartObjects("Chart1").Chart.SeriesCollection(1)
Color of each point is .Points(PointNumber).Interior.Color
The number of points you have to cycle though is .Points.Count
The value of each point is .Points(PointNumber).Value
colors of the markers themselves (Applies only to line, scatter, and radar charts):
.Points(PointNumber).MarkerBackgroundColor = RGB(0,255,0) ' green
.Points(PointNumber).MarkerForegroundColor = RGB(255,0,0) ' red
.Points(PointNumber).MarkerStyle = xlMarkerStyleCircle ' change the shape
Let's take another approach, which does not require any code.
Assume your data is in columns A (sequence number or time) and B value, starting in A2 and B2, since your labels are in A1 and B1. We'll add a series to the chart that includes any deviant values from column B. This series will draw a marker in front of any deviant points so the original point will still be present, and instead of reformatting this point the new series displays a point.
In cell C1, enter "Deviant".
In Cell C2, enter a formula that detects a deviant point, something like:
=IF(AND(B2>upperlimit,B2
This puts the value into column C if column B exceeds upper and lower limits, otherwise it puts #N/A into column C, #N/A will not result in a plotted point.
Copy the data in column C, select the chart, and Paste Special as a new series. Format this series to have no line and whatever glaring marker you want to use to indicate an out of control point.