Using MS Excel to simulate a formula using a variable? - excel

I'm very confused on how to use Microsoft Excel to simulate a "problem", but I've been assured that it's possible.
I have the equation
v(t) = (mg/c)(1-e^((-c/m)(t)))
And I know the values of m, g, k, and c.
m = 170
g = 32 ft/s^2
k = 2.5 lb/ft
c = 1.2 lb/ft/s
So my formula changes into
v(t) = (170*32/1.2)(1-e^((-1.2/170)(t)))
v(t) = (453.33)(1-e^((-.00705)(t)))
The problem is about a bungee jumper, and this is one function that I should use to find velocity, and another that is used for x (distance), but if I can learn how to properly implement this one, I should be able to easily figure out the other one.
I need to somehow implement this in Excel, as a spreadsheet simulation. I have no idea how to implement this in Excel, and I don't know the formulas to do it. I know I could just go through the formula manually and just substitute variables in for t (i.e., .5, 1, 1.5, 2, 2.5, ...), but I know there's supposed to be some way for Excel to do it for me. Additionally, I'm not sure how to simplify the powers and the "e" in my formula, and I actually don't know if I need it if I can just sub in variables like I think I can. Any help would be greatly appreciated.
EDIT: The other state equation, x(t), is below
x(t) = (mg/c)(t) + ((m^2 * g) / c^2))e^((-c/m)(t) - (m^2 * g / c^2))

This formula as mentioned in the OP:
v(t) = (453.33)(1-e^((-.00705)(t)))
needs a little adaptation, as suggested by #Tim Williams, to be suitable for Excel:
=453.33*(1-EXP(-.00705*t)
Excel does not multiply letters by numbers but will attempt to interpret t above as a named range (which may contain one or more numbers) before objecting. So t may be the name given to a range starting .5 and stepping .5 up to and including 10 (may easily be created with Fill , Series…).
If the above formula is then placed in the same row as 0.5 and copied down to suit the results should be as required.
It may however be worth noting that naming a range as a single letter is not best practice and for accuracy, convenience and versatility the constants (eg re gravity) and the variables (eg mass) would be better fed as parameters to the formula.

Related

Formula if "C" is empty

For now I have this formula:
d = abs(b-c) * a
Here is the example:
=abs(0,8894-0,8291)*10000
The result is 603.
Now, I'm trying to find c, Here is what I do so far:
c = abs(b*a)/d
How can I achieve it?
What you are looking for, is the "solver" feature of Excel. Be aware this is a numerical method, which works with approximation, and therefore can have accuracy issues.

How to calculate with the Poisson-Distribution in Matlab?

I’ve used Excel in the past but the calculations including the Poisson-Distribution took a while, that’s why I switched to SQL. Soon I’ve recognized that SQL might not be a proper solution to deal with statistical issues. Finally I’ve decided to switch to Matlab but I’m not used to it at all, my problem Is the following:
I’ve imported a .csv-table and have two columns with values, let’s say A and B (110 x 1 double)
These values both are the input values for my Poisson-calculations. Since I wanna calculate for at least the first 20 events, I’ve created a variable z=1:20.
When I now calculated let’s say
New = Poisspdf(z,A),
it says something like non-scalar arguments must match in size.
Z only has 20 records but A and l both have 110 records. So I’ve expanded Z= 1:110 and transposed it:
Znew = Z.
When I now try to execute the actual calculation:
Results = Poisspdf(Znew,A).*Poisspdf(Znew,B)
I always get only a 100x1 Vector but what I want is a matrix that is 20x20 for each record of A and B (based on my actual choice of z=1:20, I only changed to z=1:110 because Matlab told that they need to match in size).
So in this 20x20 Matrix there should always be in each cell the result of a slightly different calculation (Poisspdf(Znew,A).*Poisspdf(Znew,B)).
For example in the first cell (1,1) I want to have the result of
Poisspdf(0,value of A).*Poisspdf(0,value of B),
in cell(1,2): Poisspdf(0,value of A).*Poisspdf(1,value of B),
in cell(2,1): Poisspdf(1,value of A).*Poisspdf(0,value of B),
and so on...assuming that it’s in the Format cell(row, column)
Finally I want to sum up certain parts of each 20x20 matrix and show the result of the summed up parts in new columns.
Is there anybody able to help? Many thanks!
EDIT:
Poisson Matrix in Excel
In Excel there is Poisson-function: POISSON(x, μ, FALSE) = probability density function value f(x) at the value x for the Poisson distribution with mean μ.
In e.g. cell AD313 in the table above there is the following calculation:
=POISSON(0;first value of A;FALSE)*POISSON(0;first value of B;FALSE)
, in cell AD314
=POISSON(1;first value of A;FALSE)*POISSON(0;first value of B;FALSE)
, in cell AE313
=POISSON(0;first value of A;FALSE)*POISSON(1;first value of B;FALSE)
, and so on.
I am not sure if I completely understand your question. I wrote this code that might help you:
clear; clc
% These are the lambdas parameters for the Poisson distribution
lambdaA = 100;
lambdaB = 200;
% Generating Poisson data here
A = poissrnd(lambdaA,110,1);
B = poissrnd(lambdaB,110,1);
% Get the first 20 samples
zA = A(1:20);
zB = B(1:20);
% Perform the calculation
results = repmat(poisspdf(zA,lambdaA),1,20) .* repmat(poisspdf(zB,lambdaB)',20,1);
% Sum
sumFinal = sum(results,2);
Let me know if this is what you were trying to do.

How to produce a table of three inputs to reach a given output? (Excel model)

I have a very detailed excel model to calculate the profitability of a project, that we can call P.
The model has been simplified to compute from 3 unrelated variables. I would like to automatically create a table that shows how inputs A, B and C might vary in order to produce a pre-defined level of profitability, P. For instance, if A = 4 & B = 30, then C must = 2 in order for P to equal 20%. Likewise, if A = 5 & B = 25, then C must = 3 in order for P to equal 20%. A and B should be tested at sensible increments, perhaps 8 intervals each.
A laborious (not scalable) equivalent would be to manually define A and B, then goal-seek C to our pre-defined level of P - we'd then repeat for each combination of A and B at the given intervals and record in a two-way table.
I believe a conventional two-way data table would be pratical if the model sitting behind the inputs were greatly simplified, unfortunately this isn't possible.
Thanks to anyone that can lend a hand. Kind regards.
I think the best way to approach this will be with a VBA macro and the prebuilt GoalSeek Function something like this (p is in cell D1) :
Range(”D1”).GoalSeek Goal:=20 _
ChangingCell:=Range(“C1”)

How do I constrain a value to a range in excel?

In C++ I would use boost::clamp for this. Basically I have some excel function
A1*B2+C3+D4
I want to do constrain it to +/- some number, call it X1. The obvious way is this:
MAX(-X1, MIN(X1, A1*B2+C3+D4))
But I want to be able to do this:
CLAMP(A1*B2+C3+D4, -X1, X1)
Does this or something similar exist? I'm just curious - obviously the workaround works, it's just ugly.
This can be done using MEDIAN. MEDIAN picks the middle of the three values, thus effectively restricting the lower and upper limits.
For example say your minimum is 5 and your maximum is 10:
=MEDIAN(5,0,10) is 5
=MEDIAN(5,7,10) is 7
=MEDIAN(5,12,10) is 10
With spreadsheet formulas I don't think that you can do much better than that min/max construct. You could write clamp in VBA:
Function clamp(x As Double, lower As Double, upper As Double) As Double
If x < lower Then
clamp = lower
ElseIf x > upper Then
clamp = upper
Else
clamp = x
End If
End Function
If you enter that in a standard code module then you could e.g. do something like this:
In column A I have values in the range 0 to 2*pi. In C2 I have the value 0.5. In B1 I entered
=clamp(SIN(A1),-$C$2,$C$2)
and copied down. The graph shows the result.
(Since I gave a VBA solution I'll add the Excel-VBA tag. Even if you prefer a non-VBA solution, it is possible that others in the future might search the question and be comfortable with a VBA solution).

excel formula for working handling two different tax brackets

I'm making a spreadsheet in excel to help me understand how starting a part-time business on top of my full time job might affect my tax. I need to do this because I'm very close to my next UK tax bracket and I want to know exactly how it might affect my finances.
As part of this I'm trying to write an excel formula that will add two numbers then check if this new number is greater than a third number. I will refer to the two numbers added together as A and the third number as B. If A is not greater than B then I will multiply by 20% to find out how much of it is owed in tax. If A is greater than B I will subtract B from A to create number C and multiply B by 20% and C by 40% and add the two together to produce the final number I need. Can someone please xplain to me how to script this in Excel? I've looked for online examples but I'm not finding the language very penetrable. If I was using a scripting language I was more familiar with the code would look like this:
float taxThreshold = 42011.00;
int income = foo;
if(taxThreshold < income)
{
float higherRate = income-taxThreshold;
float standardTaxOwed = taxThreshold * 20%;
float higherRateOwed = higherRate * 40%;
float finalTaxOwed = standardTaxOwed+higherTaxOwed;
}
else
{
float finalTaxOwed = income * 20%;
}
I'm sure this is very simple to do, I just don't get the excel syntax. Can someone show me how this should be done? You'd not only be solving this problem but also giving me a means of translating from my current scripting knowledge into excel.
The easiest way is to store your 4 input parameters in some cells - and then name them. To do so, select the cell and type a meaningful name into the field that shows the address (i.e. left of the formula bar).
Once you have done this, you can simply use this formula:
=IF(Income>Threshold,Threshold*StandardTaxRate+(Income-Threshold)*HighTaxRate,Income*StandardTaxRate)
Without the naming, the formula would be something like this:
=IF(B2>B1,B1*B7+(B2-B1)*B8,B2*B7)
Both formulas will calculate you the tax you'd need to pay. If you want it more explicit, I'd recommend a layout such as this:
The formulas would read:
C7: =IF(B2>B1,B1,B2)
C8: =IF(B2>B1,B2-B1,0)
D7: =B7*C7
D8: =B8*C8
HTH!

Resources