# Use Mathematica to solve equation derive the probability distributions using the Principle of Maximum Entropy

I am reading the article Deriving probability distributions using the Principle of Maximum Entropy and trying to derive some of the equations in it automatically using Mathematica.

I want to solve the system of equations below automatically.

$$1+\text{ln} p(x)-\lambda_0=0$$ $$\int_a^b p(x) dx=1$$

My code is

Solve[1 - λ0 + Log[p[x]] == 0  &&
Integrate[p[x], {x, -Infinity, Infinity}] == 1 , {p[x], λ0} ]


But I get the error output,

Solve: This system cannot be solved with the methods available to Solve.


What should I do to make Mathematica able to solve the above system of equations?

Note: the mathematical description in the OP has a difference compared to the code provided, namely the limits of integration. I am following the TeX version of the equations provided.

Solve the first one

sltn1 = Assuming[Element[λ0, Reals],
Solve[1 - λ0 + Log[p[x]] == 0, p[x]]] // First


and use the solution to solve the other one

Solve[Integrate[p[x] /. sltn1, {x, a, b}] == 1, λ0] // First


Edit: ask yourself this. Since, we don't know what

$$\begin{equation} \int^b_a dx ~ p(x) \end{equation}$$

is unless we specify $$p(x)$$, why should Mathematica evaluate it? This logic would lead you to break the problem into smaller parts that you can and the software can solve.

Edit: after the discussion in the comments with the author of the OP, many thanks for the input and verification, people who are using versions earlier than 13 should use

Assuming[{Element[λ0, Reals]},   Simplify[Solve[1 - λ0 + Log[p[x]] == 0, p[x]]]]


and the rest of the answer as it is.

• Thanks for your speedy answer. But I am still get the Solve: This system cannot be solved with the methods available to Solve. error. ibb.co/xmCGPCc Jan 15 at 13:37
• @Domen I am using 12.1.1.0 Jan 15 at 13:40
• @benjaminchanming try with a fresh kernel. Do Quit[] and then run the commands in the order I wrote them down and let me know. I hardly think that 12.1.1 will have troubles, so probably so previous definitions are messing up.
– bmf
Jan 15 at 13:41
• @benjaminchanming your notebook should look like this. Since your screenshot starts at input 11 I cannot know what happens in 11 lines of code I don't see :-) that's the reason for suggesting a clean kernel
– bmf
Jan 15 at 13:45
• @benjaminchanming perhaps in earlier versions you should wrap it inside a Simplify let's say. For example, does this Assuming[{Element[\[Lambda]0, Reals]}, Simplify[Solve[1 - \[Lambda]0 + Log[p[x]] == 0, p[x]]]] work?
– bmf
Jan 15 at 14:23