3

I have come across a strange kind of curve, which I can’t imagine what is the equation behind. I’ve tried a variety of approaches, from numerically calculating the derivative and second (and so on) derivative$\ldots$ but that gave me no clue about the very nature of this curve.

Strange curve

@user21820: The data can be found on pastebin [here].(http://pastebin.com/UbhmETsd)

This sequence of points seems to grow with a slope of exactly 1 until the slope decreases to zero quite sharply$\ldots$ I numerically calculated the first three derivatives of this curve:

The first derivative looks like:

first derivative

Interestingly (I think), the first derivative’s “turning point” is at $x=500$, just like the $y$ maxima of the function I a looking for$\ldots$ This is numerically verified by the looks of the second derivative:

second derivative

Is the third derivative of any help? (Note that the grey line here should not to be considered.)

third derivative

Well$\ldots$ Hope you can help me!

N.B.: I can provide the raw data if necessary, but I felt this would render the question unreadable (2000 values$\ldots$)

Edit 1: @Ron: The plot of $f(x) = 500 \tanh(x/500)$ in red; and $f(x) = 500 \sqrt \tanh{((x/500)^2)}$ in green:

tanh models

Edit 2: @user21280: This is also very close but there seems to be a little discrepancie, again around the bending point.

tanh integral

Edit 3: The story behind this mysterious curve: In a closed system with two compartments A and B, exchanges of some element E occurs between these two compartments. A is finite while B is not. Flux from A to B (Fab) in one unit of time is a fraction of stock of E in A (Fab = 0.001 * A). Flux from B to A is a fraction of stock of E in B times the fraction of free “space” in A (Fba = 0.1 * B * (Amax-A)/Amax).

Considering, at the start of simulation, that A = 0 and B = x, for x = 1:2000, what is the value y of B at the equilibrium? (given Amax = 500)

Beq

When B0 gets high enough, A is saturated and B_eq (y) increases as a linear function of B0. Hence the idea of substracting B0 from B_eq. Which gives away my mysterious curve.

Edit 4: The reproducible R code behind:

Amax <- 500 # max stock of element in solid phase

A0 <- 0 # stock of element in solid phase (A) at time zero

niequ <- 1000 # time allowed for reaching equilibrium between A and B

rec <- c(0)

for(B0 in 1:2000){ # B0 = stock of element in B at time zero A <- A0

B &lt;- B0

for(i in 1:niequ){

    Fab &lt;- .001*A
    Fba &lt;- 0.1*B*(1-A/Amax)
    B &lt;- B - Fba + Fab
    A &lt;- A  + Fba - Fab

}
rec &lt;- c(rec,mean(B))

} rec <- rec[-1] plot(rec~c(1:length(rec))) # B at equilibrium as a function of B at time zero

rec2 <- (rec-c(1:length(rec))) # substraction of linear increase rec2 <- -rec2 # for working with positive values (easier for me)

plot(x=c(1:length(rec)), y=rec2) # the mysterious curve...

Rócherz
  • 3,976
Rodolphe
  • 149
  • 2
    Where does the data come from? I don't think one always should expect that collected data can be represented by some very simple function. Of course one could come up with some "monster" that will fit it pretty good, but as I read it this is not what you look for? – mickep Dec 29 '14 at 12:18
  • @mickep: You are right, this is important and I will try to explain how I came across this curve in a few minutes. – Rodolphe Dec 29 '14 at 12:55
  • Could you provide the numerical data? Use pastebin or something else. – XYZT Dec 29 '14 at 13:09
  • Try some linear combination of these two suggestions. :) – Lehs Dec 29 '14 at 13:12
  • Can you check how well the graph of the second derivative matches a (flipped) Gaussian curve? –  Dec 29 '14 at 13:15
  • @NikhilMahajan: done. – Rodolphe Dec 29 '14 at 13:17
  • @Rahul - It drops too slow to be Gaussian. Too fast to be Lorentzian. – XYZT Dec 29 '14 at 13:40
  • @Rodolphe: The data you've provided doesn't have enough significant digits to get a useful third derivative. – XYZT Dec 29 '14 at 13:46
  • @NikhilMahajan: First, thanks for looking so deep into this datas. Actually, all values have 7 significant digits, although 'R' automatically drops all trailing zeroes. – Rodolphe Dec 29 '14 at 13:51
  • Compare your plot for the third derivative with the one made from the data you provided: http://i.imgur.com/GpdiswK.png .

    Most of the action happens around $x = 500$ but the data you've provided has only 4 decimal places around that part of the data. (Sorry, I didn't mean SIGNIFICANT DIGITS in the previous comment)

    There is no way to get as smooth a plot as yours with the precision of the data you've provided on Pastebin.

    – XYZT Dec 29 '14 at 13:56
  • 1
    State your source of the data.. The data fits too perfectly to a curve to be from real-world measurements. – user21820 Dec 29 '14 at 14:04
  • @NikhilMahajan: OMG I have to recognize that's ugly. Sorry for that. Working on curating code for adding it to the question. – Rodolphe Dec 29 '14 at 14:41
  • Code and story behind added. – Rodolphe Dec 29 '14 at 14:58
  • 1
    Equilibrium occurs at $F_{ab}=F_{ba}$. Solve for $a$ and $b$ subject to the conservation of stock, $a+b=a_0+b_0=x$. You get $$a= \frac{1}{2} \left(x+505-\sqrt{x^2-990 x+255025}\right),\b= \frac{1}{2} \left(x-505+\sqrt{x^2-990 x+255025}\right).$$ –  Dec 29 '14 at 15:08
  • @Rahul: It seems you got the answer. Wow! Please consider posting this as an answer ? so I can accept it ? Maybe with slightly more steps ? Thanks. – Rodolphe Dec 29 '14 at 15:25
  • @Rahul, Turns out I was twenty minutes behind, with an error as well. – Empy2 Dec 29 '14 at 15:41
  • @Michael: Yes, Rahul got it first and right. But your answer was useful also (after correction) for the "step by step" part. – Rodolphe Dec 29 '14 at 15:43

4 Answers4

2

This to me seems like a hyperbolic tangent function:

$$f(x) = a \tanh{b x}$$

A quick inspection reveals that $a$ should be about $500$. Perhaps the slope at $x=0$ being about $1.0$ would imply that $b=1/500$. Obviously, these numbers should be taken with a grain of salt but at least represent a starting point for the analysis. The functional form seems to at least match somewhat the derivative profiles.

EDIT

A comparison to the data showed that $f$ did not bend fast enough. Another possibility is

$$g(x) = 500 \sqrt{\tanh{\left [\left (\frac{x}{500} \right )^2\right ]}}$$

A quick inspection shows that there is a better fit to the bending, although the behavior of the second derivative is a bit different.

Ron Gordon
  • 138,521
  • Wait a minute, neither does your function fit. Your function fits the first derivative very well according to my experience of sigmoid functions. – user21820 Dec 29 '14 at 12:29
  • @user21820: a plot of the second derivative reveals a bump below the axis as illustrated. The only difference is that the second derivative has a nonzero slope at zero, but I feel this is a minor point. The third derivative has the same general behavior as pictured. The OP may wish to introduce additional parameters to improve the fit, but this is a good start. – Ron Gordon Dec 29 '14 at 12:31
  • @RonGordon: Your were closer than i never was with this equation, however it does not seem to "bend fast enough" when compared with the actual data. I added a plot of your equation for comparison. – Rodolphe Dec 29 '14 at 12:37
  • @Rodolphe: see my edit, which accounts for the bending. – Ron Gordon Dec 29 '14 at 12:40
  • @RonGordon: edited the graph with adjusted equation in green. – Rodolphe Dec 29 '14 at 12:47
  • @Rodolphe: Fine. I hope you can see how I was able to refine my guess based on the fit, and perhaps you can further refine this result to get a simple function that you can use. – Ron Gordon Dec 29 '14 at 12:49
  • @RonGordon: Yes I think I understand. I will try to refine it through nonlinear estimate of exponent coefficient ? then post the edit – Rodolphe Dec 29 '14 at 12:53
2

I don't know a good reason for the data, but it looks like $x \mapsto \int_0^x \left( \frac{1}{2} - \frac{1}{2}\tanh(\frac{t-500}{100}) \right)\ dt$. It matches all the graphs perfectly as far as I can tell.

[Edit: After Rodolphe finally told the origin of the data...]

It can be seen that it is just a differential equation $\frac{da}{dt} = -pa+q(1-\frac{a}{m})(c-a)$ where $a$ is the amount in $A$, $c$ is the total amount in both, $m$ is the capacity of $A$ and $p,q$ are fixed parameters. The differential equation is separable and just requires integrating the reciprocal of a quadratic function, which is easy. I'm too lazy to do it though.

[Edit: After Rodolphe posted the code, it is clear that I misunderstood the process...]

Michael did it so I don't have to. Great!

user21820
  • 57,693
  • 9
  • 98
  • 256
2

At equilibrium, $$F_{ab}=F_{ba}\\ 0.001A = 0.1B(1-A/A_{\max.})\\ 0.001A = 0.1(x-A)(1-A/A_{\max.})\\ 0.01AA_{\max.}=(A-x)(A-A_{\max.})\\ A^2-(x+1.01A_{\max.})A+xA_{\max.}=0\\ A_\text{eq.} = \frac12\left(x+1.01A_{\max.}\pm\sqrt{x^2-1.98A_{\max.}x+1.0201A_{\max.}^2}\right)\\ A_\text{eq.} = \frac12\left(x+505\pm\sqrt{x^2-990x+255025}\right)\\ \text{(probably the negative square-root)}\\ y=x-A_\text{eq.} = \frac12\left(x-1.01A_{\max.}\mp\sqrt{x^2-1.98A_{\max.}x+1.0201A_{\max.}^2}\right)\\ y=\frac12\left(x-505\mp\sqrt{x^2-990x+255025}\right)\\ \text{(probably the positive square-root)} $$

Rócherz
  • 3,976
Empy2
  • 50,853
1

Here is IMHO a slightly more direct approach.

Indeed, this curve with 2 neat asymptotes invites to consider it as a (branch of) hyperbola having a horizontal asymptote with approx. equation $y-500=0$ and a slant asymptote with approx. equation $y-x=0$. The common equation of all hyperbolas with such asymptotes is:

$$(y-500)(y-x)=k$$

where $k$ is constant (where the LHS is the product of the LHS of the asymptotes).

Forcing the curve to pass by a certain point $A(x_0,y_0)$ clearly fixes the value of the constant. If we fix (approx.) $A(1,0.9900796)$ (according to the given data), we obtain the following equation:

$$(y-500)(y-x)=k_0\tag{1}$$

If we expand (1) as a polynomial in $y$ with parameter $x$, we get a quadratic equation

$$y^2-(x+500)y+(500x-k_0)=0$$

whose solutions are:

$$y=\tfrac12 \left(x+500 \pm \sqrt{(x+500)^2-(500x-k_0)} \right)$$

finding back the solution given by others.

Remark: in fact the $\pm$ sign accounts for the two branches of the hyperbola. Clearly, we need to replace it by a minus sign in order to get the desired branch.

Jean Marie
  • 81,803