Mathematical function for a gradually falling parabolic curve in 1st quadrant

261 Views Asked by At

I need a mathematical function for $y=f(x)$ such that $f(0)=25$ and decreases gradually to $f(100)=0$. Ideally, the function should look something like below, decreasing gradually for lower values of $x(<30)$ but faster for higher values of $x$.
Approximate plot values: $$ \begin{array}{c|cccccccccc} x&0&5&10&20&30&50&60&70&90&100\\\hline y&25&24&22&18&15&10&8&5&2&0 \end{array} $$

Edit : For my requirements I believe an inverted parabolic function would be a better fit than for a choice of negative exponent ( with $y$ sign reversed)

Thanks in advance.

3

There are 3 best solutions below

2
On BEST ANSWER

Using following code in MATLAB,

x = [0 5 10 20 30 50 60 70 90 100];
y = [25 24 22 18 15 10 8 5 2 0];
f = fit(x', y', 'exp1')

you can find an expression of the form $a\cdot\exp(b\cdot x)$ that fits best through your given points. The above code snippet results in

General model Exp1:
ans(x) = a*exp(b*x)
Coefficients (with 95% confidence bounds):
   a =       26.62  (24.19, 29.04)
   b =    -0.02188  (-0.02615, -0.01761)

The plot below shows the curve.

plot(f, x, y)

enter image description here


Extending upon this, you can also find an expression as a sum of two exponentials of the form $a\cdot\exp(b\cdot x) + c\cdot\exp(d\cdot x)$ by replacing

f = fit(x', y', 'exp1')

with

f = fit(x', y', 'exp2')

The result is

General model Exp2:
f(x) = a*exp(b*x) + c*exp(d*x)
Coefficients (with 95% confidence bounds):
   a =      -7.941  (-79.16, 63.28)
   b =    0.003243  (-0.04323, 0.04971)
   c =       33.37  (-37.4, 104.1)
   d =    -0.01101  (-0.03311, 0.01108)

and enter image description here This plot fits through most of your points.


According to this, you can use the following commands to find polynomial functions:

  1. Of form $p_1\cdot x^2 + p_2\cdot x + p_3$ with

f = fit(x', y', 'poly2')

which results in

Linear model Poly2:
f(x) = p1*x^2 + p2*x + p3
Coefficients (with 95% confidence bounds):
   p1 =    0.001145  (0.0007975, 0.001492)
   p2 =      -0.365  (-0.3998, -0.3302)
   p3 =       25.28  (24.63, 25.93)

and enter image description here

  1. Of form $p_1\cdot x^3 + p_2\cdot x^2 + p_3\cdot x + p_4$ with

f = fit(x', y', 'poly3')

which results in

Linear model Poly3:
f(x) = p1*x^3 + p2*x^2 + p3*x + p4
Coefficients (with 95% confidence bounds):
   p1 =  -4.791e-06  (-1.961e-05, 1.003e-05)
   p2 =    0.001867  (-0.0003975, 0.004131)
   p3 =     -0.3922  (-0.484, -0.3004)
   p4 =       25.43  (24.6, 26.27)

and enter image description here

3
On

Both functions $$y_1=\frac{25}{e^{100}-1}(e^{100-x}-1) \qquad\text{and } y_2=\frac{25}{e^4-1}(e^{4-x/25}-1)$$ pass through $(0,25)$ and $(100,0)$, but it's unlikely they would pass near those inner points ($y_1$ is almost flat for $x>5$) since the inner points look somewhat linear (and are also integers). If the inner points matter so much, a fit (as suggested by others) will do.

Last edit: OP already choose an answer; I just wanted to give a last function before leaving the issue for good: $$y_3= \frac{25}{e-1}(e^{1-x/100}-1).$$

0
On

One "almost exponential" function that's not a bad approximation of the function, would be $$ y(x) = 42 e^{-0.0091x}-17 $$

On the other hand, if you want a polynomial that exactly fits the set of points, you need to solve for the coefficients $a_i$ of $$ y(x) = \sum_{i=0}^9 a_i x^i $$ With Python, I made the following code:

import math
import numpy as np

x = np.array([00.0, 05.0, 10.0, 20.0, 30.0, 50.0, 60.0, 70.0, 90.0, 100.0])
y = np.array([25.0, 24.0, 22.0, 18.0, 15.0, 10.0, 08.0, 05.0, 02.0, 000.0])
z = np.polyfit(x, y, 9)

print z

and the result is

[ -2.35822733e-14   8.59716765e-12  -1.23964321e-09   8.81258004e-08  -2.96675445e-06   1.86358094e-05   1.67292491e-03  -4.42724486e-02  -2.11928208e-02   2.50000000e+01]

Mathematically put, the polynomial that you want is $$ y(x) = a_0 + a_1 x + a_2 x^2 + a_3 x^3 + \dots + a_9 x^9 $$ where $$ \left\{ \begin{array}{ccr} a_9 &\approx& -2.35822733\times 10^{-14} \\ a_8 &\approx& 8.59716765\times 10^{-12} \\ a_7 & \approx& -1.23964321\times 10^{-09} \\ a_6 &\approx& 8.81258004\times 10^{-08} \\ a_5 & \approx& -2.96675445\times 10^{-7} \\ a_4 & \approx& 1.86358094\times 10^{-05} \\ a_3 & \approx& 1.67292491\times 10^{-03} \\ a_2 & \approx& -4.42724486\times 10^{-02} \\ a_1 & \approx& -2.11928208\times 10^{-02} \\ a_0 &=& 25 \end{array} \right. $$ This is a complicated expression but it should match the points exactly.