Maths behind sliding scale pricing [closed] - php

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I'm trying to work out a simple calculation for the following:
a phone model has the maximum sale price of £85.00 and this is if only 1 unit is purchased and a minimum sales price of £50.00 - this is if 150 units and over are purchased in one.
How can I work out a way of the price if between 2 and 149 units are purchased??
Thanks,
B.

Formula:
Y = 50 + ((85 - 50) / (150 - 1)) * (X - 1)
Result:
X = 1 --> Y = 85
X = 33 --> Y = 57.52
X = 150 --> Y = 50

You probably don't have a linear model in such situations. I don't know the right English term, but you would have more like a piecewise or stepwise function here.
But nevertheless, you can get a linear function through interpolation.

Related

Linear interpolation library with php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I need to interpolate points with php, do you know any library for that? A traditional search did not allow me to find any that good results.
I have a table with values in columns x and y.
X Y
10 676
20 894
30 1100
40 1200
50 1000
I was wondering if there is a function that can help with linear interpolation. For example, I want the interpolated value of Y that corresponds to X=35.
Thanks
That's simple math - no need to use any library at all.
If you want the Y value of X, you have to find the greatest value smaller than X (x0) and the lowest value greater than X (x1).
If this two values are equal, you don't have to do anything and just return the Y value in your table.
Otherwise, take the two corresponding Y values (y0 and y1) and do a interpolation with them.
d = (x - x0) / (x1 - x0) // value in the range of [0; 1]
y = y0 * (1 - d) + y1 * d // your interpolated value
in your case of x = 35 => x0 = 30, x1 = 40
d = (35 - 30) / (40 - 30) // 0.5
y = 1100 * (1 - 0.5) + 1200 * 0.5 // 1150

Clark's formula - population density [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a problem:
C. Clark's model of urban population densities indicating that population density varies with distance from the center of the city according to the equation Dx=D0e-bx where Dx is the population density at distance x from the center. D0 is the density at the center, e is the base of the natural logarithms, and b is a natural logarithm measuring the rate of change of density with distance.
How can I write this formula in php language?
Thanks!
What I have tried:
Dx = D/(x/b*b);
But I thinks this is wrong.
Not sure what's the problem here, so here's how I got it and you can say what did I get wrong. Afterwards, you can edit your question :)
Hence:
// this should be given
$d0 = 1.22;
$b = 0.37;
function dx($x = 0) {
global $d0, $b;
return $d0 /exp($b*$x);
}
echo dx(6.74); // d_{6.74}

Need A Modulus Formula In Php [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am creating a fee calculator and fee is calculated on based of capital. So I want a formula in php.
if capital is <=1000000 then fee is 1000
if capital is 1100000 - 2000000 fee is 2000
if capital is 2100000 - 3000000 fee is 3000
if capital is 3100000 - 4000000 fee is 4000
if capital is 4100000 - 5000000 fee is 5000
and so on
so what i want is i want a formula that will give me a fee of 1000 per 10 Lakh
Assuming your variable is called $capital, then this should work:
print ((int)(1000*ceil($capital/1000000)));
It divides by 1000000, rounds up, then multiplies by 1000.

Calculate stars from grades(5-1 and 1-5) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have grades from 1 to 5 where 1 is the best and 5 is the worst(But not just integral numbers like 1, also 1.14 and so on).
I want to calculate how many stars each grade would be(5 stars would be the best, 1 star the worst - 3 would stay 3 of course - but the rest?)
I googled to get the result but I'm not finding anything helpful. Maybe I'm missing the forest for the trees, I don't know. Basically it would be the reverse number I guess?
I want to do that in PHP.
Pretty straightforward I would think:
$new_grade = 6 - $old_grade;
Or for a more generic solution:
$new_grade = $grade_max + $grade_min - $old_grade;
Star = 6 - Grade
So:
5 → 1
4 → 2
3 → 3
2 → 4
1 → 5

How do make this calculation to achieve the answer I want? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
This is a bit of a puzzle. Look at the sum and result below:
$markTotal += ($session['Mark'] / 100 * $session['SessionWeight']);
Result on Browser:
Module: CHI2550 - Modern Database Applications 41.2 (this is $markTotal)
Session: AAB 72(this is $session['Mark']) 20% (this is $session['SessionWeight'])
Session: AAE 67(this is $session['Mark']) 40% (this is $session['SessionWeight'])
As you can see the answer to the calculation above is right, the answer is 41 .2 as it adds up the two session marks, divide by 100 and then times it by the total amount of the percentage.
But I want to include a total mark where except it is out of the total session percentage (60% for above example), it is out of a 100% but I can not work as simple as that as in above example one session is worth more than other. I have worked out that the answer for the total mark of the above example out of 100% should be 69, but how do I achieve this in my calculation.
Thank you and any help is much appreciated :)
You'd need to add up the total marks as well. So if session AAB has 90 total marks available (and the student got 72) and AAE has 80 marks (and got 67) then it'd be
(72) + (67) 14.4 26.8 41.2
(--) * 0.2 + (--) * 0.4 = ---- + ---- = ---- = 79.23%
(90) + (80) 18 34 52

Categories