# Seeking Math Help

*Published 10 years, 4 days ago*

So I have this equation that’s great for finding one term. Problem is, I need to solve for another term that’s scattered all across the right side. I’m hoping someone here has the mad algebra skills I managed to lose in the two decades since I last took a math class and can help me out.

Here’s the original equation:

Q = (3.07 × F × Y × (1 + 1.4 × ((D/V) × *e*^{(-2 × D/V)}))) / D^{2}

I want to be able to solve for D, not Q; in other words, have a single D on the left and everything else on the right of the equation. F, Y, and V are all variable terms; the *e* is the classic irrational constant. I tried for quite a while to do this and ran very firmly aground. The best I managed was this minor simplification:

Q = (3.07 × F × Y × (1 + 1.4 × (D / (V × *e*^{(2 × D/V)}))) / D^{2}

…and even that assumes that I did things correctly. Here’s the original equation in pretty shoulda-done-it-in-MathML-but-oh-well form:

I can shuffle the chairs around, as it were, but never really get anywhere close to having a single D on the left. “But it’s so *easy!*“, you may well be shouting. That’s why you’re working for Google and I’m not.

I remember having questions just like this on tests back in college: “Given this equation, solve for blah”. It’s been too long, though, and in all honesty I was never that great at this sort of thing in the first place. Help, please?

**[Update 14 Jan 09]**: several commenters have shown that what I’m trying to do is impossible. Frustrating, but that’s math for you. Looks like I’ll have to take another approach.

Mathematica evaluates the initial equation as:

(3.07 F (1-(2.8 D^2 e)/V^2) Y)/D2

3.07

F

(

1

–

2.8

D

2

e

V

2

)

Y

D2

Someone sent me this link, and I just glanced at it. You’ll need to take the natural logarithm of e^whatever to bring down the exponents. ln(e^x) = x. That should help you along.

mind = “blown”

but i did just forward this to my friend who’s finishing his phd in math.

That was actually where I ran aground, Phillip, but in the sense that my attempts to do that failed to yield the correct results. As in, when I just took that part of the equation and started adding ln() to bits of it, then ran test data through it, I got different results than before I’d done so. Which means I was doing it wrong. I just don’t know how, exactly.

Not sure I understand the results you posted, Mark. Sorry!

42

Pff… been a very long time for me too….

Still breaking my head on the d/v bits, but hope this simplification helps a bit:

D = √ (3.07 × F × Y × (1 + 1.4 × (D / (V × e(2 × D/V))) / Q )

I have no idea what the answer is, but I am shocked you are not using MathML to express this equation! Heresy! :)

I’m afraid it can’t be done. To get that D out of the exponential function (e^x) you need logarithms and then the “1+” starts to bother.

How about an approximate iterative solution? :-)

Holy crap! What happened to the CSS stuff :-o

I’m not sure if it’s possible, but the most important thing as I figure it would be to get rid of the exponient, that would be a good jumping place.

D^2 = 3.07FY(1 + 1.4(D/V)e^(2D/V))/Q

(Q D^2)/3.07FY = 1 + 1.4(D/V)e^(2D/V)

V(QDD/3.07FY – 1)/1.4V = e^(2D/V)

ln(V(QDD/3.07FY – 1)/1.4V) = 2D/V

At which point I think the whole thing starts to get even worse. If it wasn’t for that logarithm it would be possible to play around with it to get D on it’s own, but the logs and exponents mess everything up.

OK, my above comment is messed up, I’ve lost a D on the third line and gained a V in it’s place.

Yann is correct. This cannot be rewritten in terms of D but you can use calculus to approximate.

CSS4? =)

I guess someone with Mathematica or Matlab will help…

You can’t get a single D because you have 3 Ds in your formula.

If you can rearrange D^(1/2 * 1/D) into an expression with only one D, I’ll give you the answer.

The equation is non-algebraic. Playing with the constants, you essentially are trying to solve an equation of the form:

x^2 = a(1 + b*x*e^x)

Where a = 4*3.07*F*Y/V^2, b = -0.7, and x = -2*D/V. You might be able to pull something out using the Lambert-W function, but really the best way to solve this is simply to compute values of a and b, then graph y=x^2-a(1+b*x*e^x) and find zeroes of the equation by graphical inspection. (Or do Newton’s method or a bisection algorithm…)

In any case, it’s not as simple as solving a quadratic equation or anything.

As a physicist, I would ask for more info about what the terms involved are.

The more advanced you get in physics, the more your complex equations start to disappear, since you are able to dismiss small terms, or you can ignore complex ones. This is the beauty of physics. :)

Alas, if you’re in for straight maths, I fear your answer will be found via numerical methods.

There is no closed form solution. The following easy recursion converges in all the cases you are interested in. With

c = 3.07/1.4 F Y V

d = -Q V / 1.4

f = exp(-2/V)

notation, your equation becomes:

c+dD^2+ D f^D = 0

Rearrange it like this:

D = -c/(dD+f^D)

Now use this as a recurrence, that is, start with D=0, evaluate the right hand side, and plug the value into D, evaluate the right hand side, and so on. Keep on doing this until it converges, which will be quite soon.

This not a continuous function. It is not possible to solve in terms of D. Sorry.

Darn you, Eric! Now I have to stop all work to solve a hard problem!

42

@ Kevin: Being continuous has very little with being able to find an inverse, at least locally. Furthermore, the curve f(x) = x^2-a(1+b*x*e^x) clearly has a well-defined derivative, which is the heavy-handed way of proving that the curve is actually continuous.

What

on earthwould you be doing that would require this equation? :)Lol, Eric I think you got an entirely different crowd on this blog post.

One last insight:

Since x=-2*D*V (assuming D,V>0), e^x is fairly close to 0. So the solution will ultimately be dominated by x=-sqrt(a), which actually gives a tremendously good approximation for the solution (in the very least, an excellent initial value for the iteration:

x_0 = -sqrt(a)

x_{n+1} = -sqrt(a*(1 – 0.7 * x_n * e^(x_n)))

Daniel was correct (empirically at least) in that this seems to converge very rapidly.

This doesn’t look too hard to me

lets do some substitution and make it look a lot nicer first ;)

x = (3.07 × F × Y × (1 + 1.4 × ((D/V) × e(-2 × D/V))))

Now we have this

Q = x / D^2

a lot nicer eh?

Multiply with D^2 on each side of the =

D^2 × Q = X

Divide by Q

D^2 = X / Q

Stick substutute the x back to what it was

D^2 = (3.07 × F × Y × (1 + 1.4 × ((D/V) × e^(-2 × D/V)))) / Q

D = Sqr( (3.07 × F × Y × (1 + 1.4 × ((D/V) × e^(-2 × D/V)))) / Q )

Not too complicated, and def nothing about logarithms

I’ll show you in an example with numbers too

80 / 2^2 = 20

80 / 4 = 20

80 / 20 = 4 = 2^2

Sqr( 80 / 20 ) = 2

test it on a calc, it works :)

woha, hidden D’s I didn’t notice :S ignore my last post

That’s unfortunate. Mathematica says it’s not possible algebraically, but I could’ve messed up somewhere. Here’s the output:

Mathematica Output

As suggested above a numeric approach is best suited.

This is as far as I got before I gave up

QV = (3.07FYV / D^2) + ((4.298FY / D) * (e^-2)^(D / V))

or if you prefer

Q = (3.07FY / D^2) + ((4.298FY / D^2) * (D / V) * (e^-2)^(D/V))

The exponentials are getting to me :(

Well, dang. Looks like I’ll have to go with incrementing (or average-narrowing) D until I hit a reasonable approximation of the value of Q I’m seeking.

Incidentally, for those who are curious:

Q = radiant energy (cal/cm^2)

F = thermal partition (unitless)

Y = yield (KT)

V = visibility (miles)

D = distance (miles)

So it’s easy (relatively speaking) to calculate the radiant energy at a given distance. I had assumed that the inverse, finding the distance at which one find a given radiant energy, was a matter of reshuffling. Kind of frustrating to find that’s not so.

Thanks for all the effort and input, folks!

@ #22 (Jason Davis)

When D = 0, Q is undefined.

When D > 0, Q is positive.

When D < 0, Q is negative.

I don’t know where you got your equation, but the derivative of the equation at the top of the post is undefined at D = 0. Therefore, the function is not continuous.

The function may be solvable for only positive values of D, but I have no idea how to do that.

“Well, dang. Looks like I”ll have to go with incrementing (or average-narrowing) D until I hit a reasonable approximation of the value of Q I”m seeking.”

You can’t avoid iteration. But the recurrence I already suggested is way simpler than the bisection method. Here is the core of it:

c = 3.07/1.4*F*Y*V

d = -Q*V/1.4

f = math.exp(-2.0/V)

D = 0.0

for i in xrange(1000) :

D = -c/(d*D+f**D)

Or try Jason’s recurrence, it’s mostly the same.

I believe you when you say yours and Jason’s approaches are simpler, Daniel. The only problem is that I don’t really understand what either of you are saying. Or, more precisely, how to actually go about doing what you’re telling me to do.

Like, at the end of your comment, you do a “for i in” operation with no actual i in the equation, which has the solve-for term D on both sides of the equation. At which point my brain shorts out. Sorry.

I think maybe all the brain cells that would normally go toward understanding that kind of thing are currently devoted to holding a functional copy of the CSS line layout model.

When Jason says x_n he means <var>x<sub>n</sub></var> :-D

And Daniel’s i is just to express that repeating the assignation below 1000 times you’ll get an accurate enough solution

@Kevin:

Note that the domain of D is strictly positive; even including D=0 doesn’t introduce much difficulty. Glancing at the original function for Q, it definitely looks to be strict-monotonically decreasing, which should imply the existence of an inverse function over its range. (Existence doesn’t say anything about how to construct it, however.)

@Meyers:

Regarding the iteration, think of it as making a guess (x_0), then using that guess to make a *better* guess (e.g. going from x_n to x_{n+1}).

So:

var x0 = -Math.sqrt(a);

var x1 = -Math.sqrt(a*(1 – 0.7 * x0 * Math.exp(x0)));

while (Math.abs(x1-x0) > 1e-6) {

x0 = x1;

x1 = -Math.sqrt(a*(1 – 0.7 * x0 * Math.exp(x0)));

}

alert(x1);

That would be some JS to quickly calculate my re-parameterized value of x. (Of course, x=-2*D/V, so you are actually interested in D=-x1*V/2.)

[Fished this version of the comment out of the spam filters and restored it. Sorry about that, Jason! -E.]

I understood you up to the very last line about my actual interest, Jason. (And it’s “Meyer”– I paid extra to get have the trailing “s” removed, y’know.)

You are exactly correct about both points, Eric. Here is what’s going on.

Daniel and Jason are both relying on a magic trick, the “iterative solution”: find an alchemy turning a good guess into a better guess. If you find such an alchemy and invoke it on a reasonable guess many, many times, you can find a result as close to the true answer as you have patience and bits.

Here is a working python function:

import math

def distance_for_luminance(Q, F, Y, V):

# set up some stuff

c = 3.07 * F * Y / Q

a = 1.04 / V

f = math.exp(-2.0/V)

# start with a terrible guess

D = math.sqrt(a)

# A whole bunch of times ("more than enough"),

for i in xrange(10000):

# Turn the good guess into a better guess

D_new = (c / D) + a*c*(f**D)

# And adopt the better guess as our new value

D = D_new

return D

I think you'll have to reinsert indentation.

Now, you may not believe in this magic trick, and why should you? (A mathematician can tell you why, and when, that's what Grad School is for, but never mind.) The beauty is that you don't have to trust the method: a true solution speaks for itself.

`Perhaps by iteration, or perhaps from a whisper by the goddess Namagiri into your ear as you slept, just plug all values into both sides and`

seehow far off it is.Hrm. Replace initial _ with spaces.

import math

def distance_for_luminance(Q, F, Y, V):

__# set up some stuff

__c = 3.07 * F * Y / Q

__a = 1.04 / V

__f = math.exp(-2.0/V)

__# start with a terrible guess

__D = math.sqrt(a)

__# A whole bunch of times ("more than enough"),

__for i in xrange(10000):

____# Turn the good guess into a better guess

____D_new = (c / D) + a*c*(f**D)

____# And adopt the better guess as our new value

____D = D_new

__return D

Hi again, Erik (just kiddin’!)

Jason’s code iterates until two consecutive values of the sequence (x0 & x1) are close enough (10^-6 in his code) to be considered a solution X. But X=-2*D/V (see comment #25) so D=-X*V/2

Oooo. Lights in my head (are those “headlights”?) are beginning to slowly come on. Thank you all!

My friend is a math professor. He says the following in response to me telling him that people are reporting that this isn’t possible:

“

People are, in this case, correct. Variables in a linear term and an exponential term are rarely solvable algebraically.“As others have said, there is no way to rearrange that formula in terms of D. While you can use iterative and brute-force methods, Microsoft Excel can very easily do all the legwork for you! (Method below is for Excel 2000, commands might be different in newer versions!)

Put your known variables into Excel in cells A2:A5 (F,Y,D,V in that order – just because that’s the order they cropped up in the formula), you’ll have to make something up for D, then in A1 type the formula in:

=(3.07*A2*A3*(1+1.4*(A4/A5)*EXP(-2*A4/A5)))/(A4^2)

With A1 highlighted, go to Tools > Goal Seek. Set “to value” to what you want Q to be, and “by changing cell” to A4, and it will give you an approximation to about 3 or 4 dp.

If 2 D/V is small (<<1) then Exp(-2 D/V) = 1-2 D/V (approximately) and the whole eqn. becomes quadratic in D hence can be easily solved.

Otherwise the it cannot be solved in terms of elementary

(high-school) functions.

Best regards.