Solving Logarithmic Expression

68 Views Asked by At

In the context of the thermodynamics of mixing two separate gases at the same temperature and pressure, one has the generic equation, \begin{gather*} -\frac{\Delta S_{mix}}{nR} = X_A \ln(X_A) + X_B \ln(X_B) \end{gather*} where $S$ is the entropy, $n$ is the moles, $R$ is the ideal gas constant, and $X_A$ refers to the mole fraction of a substance $A$ in the mixture. If we are given $\Delta S_{mix}$ along with the total moles of gas, and if we exploit the fact that the two mole fractions should add to 100% ($X_B = 1-X_A$), this amounts to solving a difficult logarithmic equation of the form, \begin{align*} C &= x \ln(x) + (1-x) \ln(1-x) \\ &=\ln(1-x) + x\ln \left( \frac{x}{1-x} \right) \end{align*} where $C$ is just a constant for convenience. After trying several different manipulations with the rules for logarithms, I just ended up with what seems like a more intractable mess. Is there a way to actually solve this algebraically for $x$, or is there absolutely no hope here?

1

There are 1 best solutions below

6
On BEST ANSWER

Start using$$x \log(x) + (1-x) \log(1-x)=-\log(2)+\sum_{n=1}^\infty \frac{2^{2 n-1}}{n (2 n-1)}\left(x-\frac{1}{2}\right)^{2 n}$$

To give an idea of the quality of the approximation, consider the partial sum $$S_p=-\log(2)+\sum_{n=1}^p \frac{2^{2 n-1}}{n (2 n-1)}\left(x-\frac{1}{2}\right)^{2 n}$$

and the corresponding infinite norm $$\Phi_p=\int_0^1\Big(x \log(x) + (1-x) \log(1-x)-S_p \Big)^2\, dx$$

$$\left( \begin{array}{cc} p & \Phi_p \\ 1 & 2.38986\times 10^{-3} \\ 2 & 4.79841\times 10^{-4} \\ 3 & 1.68129\times 10^{-4} \\ 4 & 7.72283\times 10^{-5} \\ 5 & 4.16231\times 10^{-5} \\ 6 & 2.49278\times 10^{-5} \\ 7 & 1.60876\times 10^{-5} \\ 8 & 1.09776\times 10^{-5} \\ 9 & 7.82106\times 10^{-6} \\ 10 & 5.76722\times 10^{-6} \\ \end{array} \right)$$

Truncate the series to some order and use power series reversion.

This would give $$\color{blue}{x=\frac 12 +t-\frac{t^3}{3}\sum_{n=0}^\infty a_n\,t^{2n}}\qquad \text{where} \qquad \color{blue}{t=\sqrt{\frac{C+\log (2)}{2} }}$$ where the first coefficients are $$\left\{1,\frac{13}{30},\frac{97}{210},\frac{25307}{37800},\frac{5 6827}{49896},\frac{1457147323}{681080400},\frac{14645196257}{3 405402000},\cdots\right\}$$

Edit

For $0\leq x \leq \frac 12$, I already wrote (have a look here) that we can make a good approximation

$$x \log(x) + (1-x) \log(1-x) \sim -\log(2) \big(4 x (1-x) \big)^{3/4}$$ So, the first estimate is $$\color{blue}{x_0=\frac 12(1-t)}\qquad\text{where}\qquad \color{blue}{t=\sqrt{1-\left(\frac{|C|}{\log (2)}\right)^{4/3}}} $$ is a decent approximation of te solution.

To improve it, use the first iterate of Newton method $$x_1=x_0-\frac {f(x_0)}{f'(x_0)}$$ where $$f(x)=x \log(x) + (1-x) \log(1-x)-C$$ $$f'(x)=\log (x)-\log (1-x)$$

$$\large\color{blue}{x_1=\frac {\log(1+t) -(C+\log(2)) } {2 \tanh ^{-1}(t) }}$$

Some numbers

$$\left( \begin{array}{cccc} c & x_0 & x_1 & \text{solution} \\ -0.05 & 0.007564 & 0.008696 & 0.008713 \\ -0.10 & 0.019289 & 0.020496 & 0.020506 \\ -0.15 & 0.033611 & 0.034481 & 0.034484 \\ -0.20 & 0.050185 & 0.050505 & 0.050505 \\ -0.25 & 0.068936 & 0.068599 & 0.068599 \\ -0.30 & 0.089935 & 0.088903 & 0.088906 \\ -0.35 & 0.113377 & 0.111666 & 0.111674 \\ -0.40 & 0.139600 & 0.137270 & 0.137283 \\ -0.45 & 0.169147 & 0.166300 & 0.166318 \\ -0.50 & 0.202903 & 0.199687 & 0.199710 \\ -0.55 & 0.242414 & 0.239038 & 0.239065 \\ -0.60 & 0.290813 & 0.287584 & 0.287612 \\ -0.65 & 0.356713 & 0.354163 & 0.354187 \\ \end{array} \right)$$

For sure, the first estimate of Halley or Householder methods (still closed form formulae) wold be better. No problem to write them.