# Mathematics FilterJanuary 22, 2021 10:22 PM   Subscribe

Help a biologist trying to do math and in over their head. I'm trying to do some modeling and would like to find the inverse of the equation f(x) = ln(|x|)/u - (ln(|vx-p|))/kv + C when 0<x<p/v. Is this possible? Can anyone point me to a solution or a resource where people good at math answer these types of questions? Stuck and really not sure who to ask. Thanks!
posted by 12%juicepulp to Science & Nature (10 answers total) 2 users marked this as a favorite

Try wolfram alpha. It’s a great site for evaluating math equations.
posted by Valancy Rachel at 10:38 PM on January 22

Wolfram Alpha is not loving this one, which is a bad sign for finding a closed form of the inverse in general.

If u = kv, it looks like your inverse will be a logistic model, which I am guessing you already know. If u and kv are small integers (at most 4), you can potentially find a formula using the quadratic, cubic, or quartic formula. (The last two are pretty awful.) I am not spotting any other algebra that will work. (Caveat: I am a mathematician, but not one who routinely works with messy equations.)

If a graph will suffice, Desmos can give you that (using sliders for your various constants).
https://www.desmos.com/calculator/eos0blg5kq

Math Stack Exchange is probably where you would get the best answer, if one is possible.
posted by ktkt at 11:34 PM on January 22 [4 favorites]

What kind of answer do you need?

For general values of the constants, the inverse function will not have a closed form (a nice formula in terms of familiar functions). But if you just need to compute values, there are lots of tools (Desmos worksheet, for example -- click the intersection of the curve and the line to get coordinates). Somewhere in between these poles is the possibility of a local approximation by series; would that be useful for your purposes?

(On preview, my answer is very similar to ktkt's, right down to the Desmos worksheet -- and we picked remarkably similar values for the constants! I'm going to post anyway because I'm amused by the similarity...)
posted by aws17576 at 11:39 PM on January 22 [7 favorites]

Fellow biologist here! I took a quick crack at it, and I might be having a brain fart but I think that while your equation probably is invertible in general, I'm not sure there's actually a simple algebraic form for the inverse. I can run you through the algebra I did to arrive at this conclusion, in case it helps you reason about your equation.

Tackling this I would start by using a variable substitution x = p/v * z, so that 0 < z < 1, which makes some things easier to reason about. Also, for the sake of readability, I'd substitute s = 1/u and t = 1/kv. Then letting y = f(x),

y = s*ln(|p/v * z|) - t*ln(|pz - p|) + C

From your constraint, p/v and z are both positive, so we can just use the property of logarithms that ln(a*b) = ln(a) * ln(b), and write:

y = s*(ln(p/v) + ln(z)) - t*(ln(|p|) + ln(|z-1|)) + C

And since z < 1, ln(|z-1|) = ln(1-z). Then using the property of logarithms that a*ln(b) = ln(b^a), we can rewrite this as

y = ln((p/v)^s) + ln(z^s) - ln(|p|^t) - ln((1-z)^t) + C

There's a bunch of ugly terms there that are just constants, so we can introduce a new constant

D = C + ln((p/v)^s) + ln(|p|^t)

and we get

y = ln(z^s) - ln((1-z)^t) + D

And using the property of logarithms that ln(a) - ln(b) = ln(a/b),

y = ln(z^s / (1-z)^t) + D

Then we can start trying to solve for z (which will eventually let us get x). Subtracting D from both sides and taking the exponential, we get

exp(y-D) = z^s / (1-z)^t

And unfortunately I think that's it; I don't know of any tricks for dealing with the right-hand side here when s and t can be any arbitrary values. There might be some special cases for s and t (especially if they're integers) for which this has an algebraic solution, but in general I don't think you can separate things out any further than this. But you can at least graphically explore how changing the constants s and t affects your solution using your favorite plotting software. And if you have measured values for these constants, you can solve it numerically.

On preview: I was going to also suggest Math Stack Exchange as another resource to check!
posted by biogeo at 11:51 PM on January 22 [6 favorites]

Physicist here; I deal with semi-nasty equations like this all the time. In principle, you might also be able to get a closed-form inverse function using biogeo's method, so long as the ratio between u and kv is a ratio of small integers (less than 5.) In that case, the problem reduces to finding the roots of a polynomial whose order is less than 5. But explicit solutions for cubic and quartic polynomials are (as noted above) extra nasty, and to be honest I doubt that it would elucidate any properties of the function.

So the next steps really depend on what you want to do with this inverse function. If you just want a graph of it, Desmos can do that; just swap the roles of x and y when you enter the equation. If you want something else, post again and the boffins here might be able to help.

I unthinkingly tried to use MathJax several times in preparing this answer. That's what comes from hanging out on Physics & Math StackExchange.
posted by Johnny Assay at 6:19 AM on January 23 [1 favorite]

This is all brilliant, I'm blown away by how helpful everyone is. The Desmos graph feels a little bit like black magic and is definitely a huge step in the right direction! Finally a nice looking growth curve.

This should allow me to verify that the equation fits the data. Assuming that checks out I want to see if I can derive the values of the different constants by by just measuring the initial growth rate and the time/rate when the growth rate is linear i.e. the inflection point for the growth curve.

Doing this will definitely require some more math so if you want to play along check back later!
posted by 12%juicepulp at 11:11 AM on January 23

We remember from calc 101 that the slope of the inverse is the inverse of the slope. 20 rabbits per day is equivalent to 1/20 of day per rabbit.
posted by SemiSalt at 12:40 PM on January 23

It should be invertible, but probably doesn't have a clean analytic inverse. Just rearranging a bit, in this range exp(-y) = x^-1/u * (p/v-x) ^ (1/kv) * c is a product of two monotone decreasing functions, and exp is monotone. If this is a data analysis problem, you probably want to look into nonlinear least squares or mcmc analysis like stan.
posted by a robot made out of meat at 5:50 PM on January 23 [1 favorite]

Pendantic (ha, hi biogeo): ln(a*b) = ln(a) * ln(b)
I'm pretty sure that's : ln(a*b) = ln(a) + ln(b)
I'm trusting that the actual equation stuff ln(|p/v * z|) can be turned into ln(p/v) + ln(z) ((dropping the |absolute| bit)) because both are positive.
posted by zengargoyle at 6:15 PM on January 23 [1 favorite]

Whoops, thanks for the correction! Yeah, that was a typo. The logarithm of the product is equal to the sum of the logarithms. And yes, I dropped the absolute value where the argument was known to be positive.
posted by biogeo at 7:43 PM on January 23

« Older Stay frosty   |   My basement is a home for rats and not for people Newer »

You are not logged in, either login or create an account to post comments