2
$\begingroup$

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?

$\endgroup$

1 Answer 1

3
$\begingroup$

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.

$\endgroup$
12
  • $\begingroup$ 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 $\endgroup$ Jan 15, 2023 at 13:37
  • $\begingroup$ @Domen I am using 12.1.1.0 $\endgroup$ Jan 15, 2023 at 13:40
  • $\begingroup$ @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. $\endgroup$
    – bmf
    Jan 15, 2023 at 13:41
  • $\begingroup$ @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 $\endgroup$
    – bmf
    Jan 15, 2023 at 13:45
  • 1
    $\begingroup$ @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? $\endgroup$
    – bmf
    Jan 15, 2023 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.