# Working with a random variable in an equation

A very simple and direct question, I know. But there are, in my view, surprisingly few simple and direct answers on the net.

My question is, suppose I have the following equation $Y = 1/(C-(A-B))$ and $B$ is a random variable that follows the Normal distribution, say. How do I:

1: Use Mathematica to obtain the equation for $Y$?

2: Find the mean of the equation found in 1.

• I don't understand the question. It seems $Y=1/B$. Perhaps show how'd you work it out by hand to clarify. – Szabolcs Jul 16 '18 at 13:16
• @Szabolcs The equation simplifies, to 1/B. I will change it slightly to make it a little more useful. – user120911 Jul 16 '18 at 13:21
• Maybe you want TransformedDistribution and Mean. – Szabolcs Jul 16 '18 at 13:21
• Note that Mean won't work here as this particular $Y$ has no mean (doesn't converge). – Szabolcs Jul 16 '18 at 13:22
• Perhaps in your item 1, you mean you wish to "obtain the distribution of $Y$", where you could be more specific: do you want an PDF? CDF? other means of representing the distribution of $Y$? For your item 2, since a mean need not exist, what sort of answer do you expect when the mean does not exist? – Eric Towers Jul 16 '18 at 18:52

dist = TransformedDistribution[1/(b + 1), b \[Distributed] NormalDistribution[]]


PDF[dist, x]


You can use RandomVariate to sample or Mean to compute the mean. Note that this particular distribution has no mean though (so the calculation will fail).

• While the Mean cannot be evaluated, the Median can and evaluates to 1/(1 - Sqrt[2]*InverseErf[ -1 + Erf[1/Sqrt[2]]]) or approximately 0.709826. You can also evaluate the modes with the primary mode at 1/2 and the secondary mode at -1 – Bob Hanlon Jul 16 '18 at 16:20

I'm not clear what you are after. You have given an equation for Y and you are asking to use Mathematica how to obtain the equation for Y. Why would you need to get as output what you have just specified using input?

If you mean that you want to simplify the equation, isn't this simply Y=1/B?

I think when you ask to find the mean of the equation, you mean that you want it expressed in terms of B. This isn't specifically a Mathematica problem.

There seems to be some interesting material elsewhere on StackExchange - look here:

https://stats.stackexchange.com/questions/80874/expectation-of-reciprocal-of-a-variable