How to get Simplified variance of a random variable?

Freya_the_Goddess
Thu, 23 Feb 2023 11:00:55 +0000
General Usage

Hi all,

I want to use Julia to get the end result like this:

the Expectation of (X - \mu)^{2} will be computed at the end to become:

E(X^{2}) - \mu^{2}

but how?

this is my try out:

using SymPy
# https://docs.sympy.org/latest/tutorials/intro-tutorial/simplification.html
@syms x, μ

v = expand((x-μ)^2)

function E(h)
	if h == x^2
	  return x^2
	elseif h==x*μ
	  return x*μ
	elseif h==μ^2
	  return μ^2
	end
end

what should I do next? I was thinking of creating a function with if and ifelse, maybe there is another way?

7 posts - 3 participants