First of all, math is not my area.
Imagine a problem like this:
I have a number of money to spend, say 500, and i need to spend them on a fixed number of days, say 20. I have a fixed maximum of money to spend per day, like 50. I don't need to spend money on a day.
Now i need to know how to calculate the total number of money I have to spend each day to get a spending curve like the following:
My goal is a function that takes a number of money and a number of days, and returns an tuple with day number and ammount of money for that day.
I know i need to use logarithms of some type, and i've tried pretty much everything that my brain can handle. I've been looking at wolfram mathworld and this formula:
y = a + b ln x
But it does not really help me.
An hint or example in PHP, Python or C# would be great, but any language will do.
PLEASE let me know if you need any more information or if the question is vague, I really want to solve this. Thank you!
I don't understand why you want a log distribution. A parabolic one will do to obtain the curve form you want:
spend[day] = a day^2 + c
where:
a -> (6 * (TD - TA)) / (TD *(-1 - 3 * TD + 4 * TD^2))
c -> -((1 + 3 * TD - 6*TA*TD + 2 * TD^2)/ (-1 - 3 * TD + 4 * TD^2))
TA = Total Amount
TD = Total Days
With this the amount you spend the last day is 1.
For your example values: (amt 500, days 20)
Are you sure what you are asking for is not a linear equation?
For example
y=f(x)=-50x+500 and the total number of days would be x where y=0.
Related
I'm following one of BQ courses from Google's Skill Boost program. Using a dataset with football (soccer) stats, they're calculating the impact of shot distance on the likelihood of scoring a goal.
I don't quite get how the shot distance is calculated in this part:
SQRT(
POW(
(100 - positions[ORDINAL(1)].x) * 105/100,
2) +
POW(
(50 - positions[ORDINAL(1)].y) * 68/100,
2)
) AS shotDistance
I know the distance formula is used (d=√((x_2-x_1)²+(y_2-y_1)²)) but:
why use ORDINAL(1)? How does it work in this example?
why detract first from 100 and then from 50?
For the record, positions is a repeated field, with x,y int64 nested underneath. x and y have values between 1 and 100, demonstrating the % of the pitch where an event (e.g. a pass) was initiated or terminated.
The whole code is as follows:
WITH
Shots AS
(
SELECT
*,
/* 101 is known Tag for 'goals' from goals table */
(101 IN UNNEST(tags.id)) AS isGoal,
/* Translate 0-100 (x,y) coordinate-based distances to absolute positions
using "average" field dimensions of 105x68 before combining in 2D dist calc */
SQRT(
POW(
(100 - positions[ORDINAL(1)].x) * 105/100,
2) +
POW(
(50 - positions[ORDINAL(1)].y) * 68/100,
2)
) AS shotDistance
FROM
`soccer.events`
WHERE
/* Includes both "open play" & free kick shots (including penalties) */
eventName = 'Shot' OR
(eventName = 'Free Kick' AND subEventName IN ('Free kick shot', 'Penalty'))
)
SELECT
ROUND(shotDistance, 0) AS ShotDistRound0,
COUNT(*) AS numShots,
SUM(IF(isGoal, 1, 0)) AS numGoals,
AVG(IF(isGoal, 1, 0)) AS goalPct
FROM
Shots
WHERE
shotDistance <= 50
GROUP BY
ShotDistRound0
ORDER BY
ShotDistRound0
Thanks
why use ORDINAL(1)? How does it work in this example?
As per the BigQuery array documentation
To access elements from the arrays in this column, you must specify
which type of indexing you want to use: either OFFSET, for zero-based
indexes, or ORDINAL, for one-based indexes.
So taking a sample array to access the first element you would do the following:
array = [7, 5, 8]
array[OFFSET(0)] = 7
array[ORDINAL(1)] = 7
So in this example it is used to get the coordinates of where the shot took place (which in this data is the first set of x,y coordinates).
why detract first from 100 and then from 50?
The difference between 100 and 50 represents the position of the goals on the field.
So the end point of the shot is assumed to be in the middle of the goals which along the x axis from 0 - 100, 100 is the endline of the field, while on the y axis the goals is in the middle of the field equal distance from each sideline, so therefore 50 is the middle point of the goals.
I am sure everyone is familiar with the famous 21 matchsticks game where each person picks up 1,2 or 3 matches and the last person to pick up a match loses.
Let's simplify the game and assume that it is only possible to pick 1 or 2 matches. My question is, how many games are possible?
I know this is very easy to solve recursively, however, I am trying to come up with a combinatorial solution.
To provide an example, let's reduce 21 to just 4 matches. The number of possible games would be 5. {'MCM', 'MMMM', 'CC', 'CMM', 'MMC'}. Where C represents removing 2 matches and M represents removing a single match.
Symbolic method allows us to deduce that the generating function for this combinatorial class is
f(z) = 1/(1 - z - z^2 - z^3)
At this point, we can obtain the answer through a power series expansion, e.g. see here. The coefficient on z^21 will give the number of possible games in "21 matchsticks" (it might be 233317).
Looking back, suppose that players were allowed to take one match only. Then, there would be only one possible scenario. For each game length (power of z), there is only one game outcome:
1/(1 - z) = 1*1 + 1*z + 1*z^2 + 1*z^3 + 1*z^4 + 1*z^5 + ...
If players are allowed to take one or two matches, we have multiple scenarios:
1/(1 - z - z^2) = 1*1 + 1*z + 2*z^2 + 3*z^3 + 5*z^4 + 8*z^5 + ...
The coefficients recover the Fibonacci sequence and can be interpreted as a number of integer compositions of n using only numbers 1 and 2.
Allowing for taking one, two or three matches leads to the following expansion,
1/(1 - z - z^2 - z^3) = 1*1 + 1*z + 2*z^2 + 4*z^3 + 7*z^4 + 13*z^5 + ...
which can be found in this OEIS sequence, cordially named the "Tribonacci numbers".
It is possible to arrive at the 233317 answer using pen, paper and a shifted generalization of the Pascal triangle, although I would leave that task to someone else.
As an aside, I highly recommend the book "Analytic Combinatorics" by Philippe Flajolet and Robert Sedgewick for their introduction to the symbolic method and beyond.
I would just like to start by saying my calculus is terrible and I have next to no experience with using it.
I am trying to find an algorithm to help scaling in my game. Specifically it should scale the amount of waves that spawn per level. Ideally it will take any number as a level up to the max integer value. There would also be a minimum value and a maximum value that would be the minimum waves and maximum waves. So:
level = 0 to infinity
minValue = 3
maxValue = 40
result = an algorithm that will have a max curvature of the max value and shouldnt exceed it no matter what value the level is. I'm not sure how to calculate this but I think it would also need some kind of threshold that i could control to dictate the curvature based on the the level.
Try the next approach:
mult = Min(1, (level/MaxLevel)**Somepower))
minValue + (maxValue - minValue) * mult
Choose Somepower value suitable for your tasks. For example, value 2 gives parabola (note that value might be less than 1)
If you want more complex curve, show a picture of desired form.
Edit:
For the case when curve tends but does not become above some level, you can choose some function with horizontal asymptote. For example:
max * x /(x+1)
or
max * arctan(k*x) * 2 / Pi
I think this is simple but maybe I'm over thinking it or I'm just crap at Math.
I'm trying to work out a formula for a incremental payment plan calculator without interest, That starts with low payment and ends on the 8 month with higher payment.
$6,600 / 8 = $825 per month
The above is showing $825 per month for 8 months.
I want the first payment to start low and increment up per month until the last payment is higher until the 6,600 is payed.
how would I work this out in Math terms.
In some sense you are underthinking it rather than overthinking it, since there are infinitely many solutions and you haven't given any criteria for choosing between those solutions.
Presumably you want the increments to be the same size each month.
Let x be the initial amount and y the monthly step size
You want
x + (x+y) + (x + 2y) + ... + (x + 7y) = 6600
or
8x + 28y = 6600
Mathematically, this equation has infinitely many solutions. If you specify that x,y are positive and that furthermore, x has at most 2 decimal places so as to be exactly expressible as currency, there are still a very large number of solutions.
What you can do is solve for y in terms of x to get that:
y = (1650 - 2x)/7
But -- you would still have to pick x. This formula would allow you to explore the trade-off between x and y. For example, if pick x = 500 then y is (approximately) 92.86 (you would probably have to adjust the final payment by a few pennies to get it to balance out in the end).
This is driving me nuts. I am looking for the formula to evenly calculate x values within a range of minimum and maximum values. For instance...
min = 4
max = 20
x = 3
Should equate to...
= 8, 12, 16
I feel like the answer is right in front of my face, I'm sure I covered it at some point during one of my math or statistics courses, but I just can't puzzle it out. I have looked at similar questions here, but they are all programming specific and aren't really shedding any light for me. I would think there has to be a basic formula for this. Any help would be greatly appreciated.
assuming t = 1..x:
a[t] = min+t*(max-min) / (x+1)