Math Mavens - Hopefully Easy Algebra Query

If you want to be certain that there’s only one real root, you can check the discriminant:

http://mathworld.wolfram.com/PolynomialDiscriminant.html

(The discriminant for general cubic equations is given in equation 5 of that page.)

If the discriminant D is positive, then there’s one real root and two complex ones. If D<0 then there are three distinct real roots. If D=0 then all the roots are real but there will be either one or two distinct roots.

Orbifold: Good point.

Using the variables defined in my previous post it can be easily determined what kind of roots you’re going to get:

If (b[sup]2[/sup]/4) + (a[sup]3[/sup]/27) > 0, there will be one real root and two conjugate imaginary roots.

If (b[sup]2[/sup]/4) + (a[sup]3[/sup]/27) = 0, there will be three real roots of which at least two are equal.

If (b[sup]2[/sup]/4) + (a[sup]3[/sup]/27) < 0, there will be three real and unequal roots.

Wow, I feel even dumber, if that’s possible.

I think I am misunderstanding here. So, is there a single analytic solution which I can use? Crafter_Man has one, Orbifold has one, and some nice fellow (whose name I don’t have because my e-mail isn’t open) sent me Mathematica output - all three of which are different. I don’t know which one I should use.

I am really, really reminded about how much I used to hate van der Waals.

Worst. Equation of State. Ever.

Anthracite, I strongly suspect all three of our answers will give the same answer for V, or at least will all give a correct answer. The only reason I don’t know for certain is that I quail at the thought of doing the algebra to check :slight_smile: But given the sources we’re using, I believe the only way one of could be wrong is if one of us made a typo.

My advice would be to chose whichever one is easiest for you to code and then test it with some sample inputs. Not that you didn’t already think of that, I’m sure.

Then just keep in mind that the equation you described can have up to three real solutions, and some of the solutions given here (mine, for example) only provide one. (But by checking the discriminant you can at least confirm it is the only one, if that is indeed the case.)

Crafter_Man’s solution is the one I’ve seen derived, so I’d be inclined to go with that one (not that I don’t trust Orbifold).

Anthracite: How you solve it is dependent on the signs & magnitudes of the original coefficients. This is because complex mathematics might be required.

Can you email me the range of values for P, B, R, T, and A? I’ll take a stab at it using Excel.

Oh, one more thing: I am very confident the solution I presented works. But I must admit it is somewhat confusing because the A & B constants in your original equation are not the same as

A = ((-b/2)+sqrt(((b[sup]2[/sup])/4)+((a[sup]3[/sup])/27)))^(1/3)
B = ((-b/2)-sqrt(((b[sup]2[/sup])/4)+((a[sup]3[/sup])/27)))^(1/3)

So in the three solution equations, make sure you use these calculated values for A & B, not the A & B coefficients from your original equation! (However, the A & B coefficients from your original equation are used to calculate p, q, and r. Can it be any more confusing?)

I hope this isn’t causing you a lot of fuss. But then, didn’t I send a long coal mail to you once…? :wink:

Anyhow. Here are the ranges that I would expect.

R is roughly 0.08206 +/- 0.00001 (liter atm / mol K)

T should range from about 0 to 3000 (K)

P should range from about 0 to 10 (atm)

A should range from about 0.1 to 100 ((liters[sup]2[/sup] * atm)/mol[sup]2[/sup])

B should range from about 0.01 to 0.5 (liters/mol)

Oooh, that reminds me…I may to withdraw my Fortran code. It occurs to me that Maple probably didn’t bother to check that the crap under the square root sign isn’t negative before it generated the code. So the code I posted might crash when calculating t46.

Hmm…does anyone know what happens when Fortran tries to take the square root of a negative number? Does it crash or is it smart enough to return a complex number?

Er, that should be “…I may have to withdraw my Fortran code…”. There, that’s actually English now…

I came up with an Excel program that algebraically calculates the roots. It was a bitch for two reasons:

  1. Complex arithmetic sucks in Excel. You have to use special functions.
  2. I found out Excel is stupid when it raises a negative number to a power. For my spreadsheet, I need to take the cube root of a number. This number may be positive, negative, and/or complex. To cover all cases, I thought I could simply use the IMPOWER function. But IMPOWER falls flat when you try to take the cube root of a negative real number. For example, the cube root of –8 is –2; IMPOWER gives me 1 + 1.732i. While this may be technically correct, I need the real answer! So I had to insert an IF statement.

Anthracite: I’ll email you the spreadsheet. Vary the constants (P, B, R, T, A) over their ranges and let me know which solution is correct (V[sub]1[/sub], V[sub]2[/sub], or V[sub]3[/sub]). We should then be able to come up with a single formula.

[minor hijack]
Don’t feel bad, Anthracite. I’m a pretty bright guy (I think), but I feel like Homer Simpson in these math threads.
[/minor hijack]

Crafter_Man wrote:

Holy Cow!

Let’s see…

1 + 1.732i = -2
1.732i = -1

so

i = -0.57737

That’s going to make complex math sooooo much easier! And some people say Microsoft is good for nothing…

( Sorry, couldn’t resist. [/hijack] )

Maybe I’m missing something…

(1 + 1.732i)^3 =
1 + 3 * 1.732i + 3 * (1.732i)^2 + (1.732i)^3 =
1 + 5.196i - 9 - 5.196i = -8

Which is right.

Just not useful, since -2 is the “better” root for Anthracite’s purposes.

Punoqllads wrote:

Sorry, I’d just never seen a use of i before where it was so obvious how one could give it an actual value. Your math is quite correct, of course, cancelling all the i’s so the value doesn’t matter. The only place I’d ever used complex numbers before was in plotting Julia sets, and the value of i itself doesn’t matter there, either. I just thought it mighty funny that after all this time, I finally learned that the square root of -1 is -0.57737…

Oh, crap! I blew the simple freaking algebra!

1 + 1.732i = -2
1.732i = -3

so

i = -1.732

Oh, my cheeks are pink!

Hey, just out of curiosity, does the IMPOWER function always return the cube root of x as a y + zi combo such that when set equal to the non-complex cube root, as I jokingly did above, i can be calculated to be equal to -z? Or was that just a coincidence?

Also, FWIW, if some number y + zi is the cube root of x, then calling

r = sqrt(y[sup]2[/sup] + z[sup]2[/sup])
p = y/r
q = z/r

then

r * ((-p/2 - q * sqrt(3)/2) + (p * sqrt(3)/2 - q/2)i)
and
r * ((-p/2 + q * sqrt(3)/2) + (-p * sqrt(3)/2 - q/2)i)

are also cube roots of x.

SIGN[-8] x CUBEROOT[ABS[-8]], or something similar, would work.

Negative 8 has three cube roots, all distinct (-2, 1+1.732i, 1-1.732i). They can’t be arbitrarily set equal to each other, any more than the two square roots of 4 (2 and -2) can be set equal just because they’re both a square root of 2.

Not even close. Try the Peng Robinson EOS on for size. It’s in the VDW family, but worse.

P = RT / (V - b) - a(T) / (V * (V - b) + b * (V - b))

I suppose you already know about P, T, and R. V is molar volume (that’s whythe n vanishes), and b is pretty much the VDW b. Numerator in the final term, a(T) is a function of temperature that changes with each gas.

I guess the Patel-Teja EOS is even worse, but I’ve never seen anybody in their right mind use it.

In other words, in my thermodynamics class, there was celebration when we only had to work a problem through with a VDW EOS. Of course, that may be because my professor was sadistic.

Not a coincidence. The n solutions to z = x[sup]1/n[/sup] will always sum to zero.

Well, I didn’t know that, either, ultrafilter, but that’s not the same as I what I was asking. Take a negative number m, and it’s real cube root, n. If I want to get the complex roots, are they always in the same form as we saw above? In other words, are the two complex roots always 1 +/- (n-1)[sup]1/2[/sup]i, as they are in the case of the cube root of -8? It’s the negative-square-root aspect I was surprised by, that’s all.

Actually, the answer to that last question is no. Since you said that all the roots sum to zero, the real parts of the complex cube roots of a negative number, m (which has a real root n), must be -(n/2), on each, to make the sum work out. And if those parts are -(n/2), then, following from the expansion of (a+b)[sup]3[/sup], the complex parts must be equal to, um… |m|+|n/2|[sup]3[/sup], er… (|1.25m|/3)[sup]1/2[/sup]i, right?

Lemme check… If we set m equal to -27, then n is -3, the real halves of the complex roots are 1.5, and the complex parts of the complex roots are 3.354, or -3, 1.5+3.354i and 1.5-3.354i. No, that’ll never work. If the format is y+zi, then to work out correctly, 3y[sup]2[/sup]z needs to equal z[sup]3[/sup], so z equals 1.732y for every cube root?

m = -27, n = -3, y = 1.5, z = 2.598, so…

(1.5+2.598i)[sup]3[/sup] =
(3.375 + 32.252.598i + 31.5(2.598i)[sup]2[/sup] + (2.598i)[sup]3[/sup]) =
(3.375 + 17.537i - 30.373 - 17.536i), which, forgiving a little bit of rounding slop, equals -27.

So, only in terms of m, the cube roots of m when m is a negative value are:

r[sub]1[/sub] = -(|m|[sup]1/3[/sup])
r[sub]2[/sub] = -(r[sub]1[/sub]/2) + (3[sup]1/2[/sup]/2)r[sub]1[/sub]i
r[sub]3[/sub] = -(r[sub]1[/sub]/2) - (3[sup]1/2[/sup]/2)r[sub]1[/sub]i

Are those right?

If we swap all the signs, do we get cube roots for positive m? At least the first one would work.

[Lisa Simpson] Somebody! Grade me! [/Lisa Simpson]

And, using the numbers for the cube root of -27, we can follow the joke, and do this:

1.5 + 2.598i = -3
2.598i = -4.5
i = -1.732

From which I learn that you’ll probably always get -1.732 by doing that to those complex cube roots, instead of, in my question from my post above, -z. It was a coincidence, in that the example number was -8, which made z equal to +1.732.

(Really sorry about this hijack, Anthracite, but I got fascinated.)