Ask Your Question

Solving equations in SageMath

asked 2021-07-19 21:16:32 +0200

YetAnotherUsr gravatar image

Hey! I'm new to sage and I'm trying to see how complex are the calculations that I can express in SageMath. So I considered the following example, the comparison between the likelihood of two normals with different means but same variance:

$$ \dfrac{1}{\sigma\sqrt{2\pi} } \exp{\left(-\dfrac{(x-\mu_1)^2}{2\sigma^2}\right)} = \dfrac{1}{\sigma\sqrt{2\pi} } \exp{\left(-\dfrac{(x-\mu_2)^2}{2\sigma^2}\right)} $$

I know that the answer must be $\mu_1 = \mu_2$. Can I solve it with SageMath? I tried:

x, mu1, mu2, sigma = var('x, mu1, mu2, sigma')



but that doesn't seem to work. Is it possible to do so in sagemath? Thanks!!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-07-20 09:52:26 +0200

tolga gravatar image

You can solve for mu1:

var('x, mu1, mu2, sigma')
edit flag offensive delete link more


Thanks, that worked!!

YetAnotherUsr gravatar imageYetAnotherUsr ( 2021-07-20 15:39:21 +0200 )edit

By the way, what if I wanted to solve for two variables, meaning I wanted to check if for different $\sigma_1$ and $\sigma_2$, I tried the following:

var('x, mu1, mu2, sigma1, sigma2')
result = solve((1/sigma1^2)*(x-mu1)^2 + log(sigma1)==(1/sigma2^2)*(x-mu2)^2+log(sigma2), mu1, sigma1)

But it didnt't work out. How can I define for several variables the solution?

YetAnotherUsr gravatar imageYetAnotherUsr ( 2021-07-20 15:56:36 +0200 )edit

Usually, you need a second equation to solve for two variables.

mwageringel gravatar imagemwageringel ( 2021-07-20 21:15:32 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2021-07-19 21:16:32 +0200

Seen: 755 times

Last updated: Jul 20 '21