Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
1

Solving equations in SageMath

asked 3 years ago

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:

1σ2πexp((xμ1)22σ2)=1σ2πexp((xμ2)22σ2)

I know that the answer must be μ1=μ2. Can I solve it with SageMath? I tried:

x, mu1, mu2, sigma = var('x, mu1, mu2, sigma')
exp((0.5/sigma)*(x-mu1)^2)==exp((0.5/sigma)*(x-mu2)^2)

and

solve(exp((0.5/sigma)*(x-mu1)^2)==exp((0.5/sigma)*(x-mu2)^2))

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

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 3 years ago

tolga gravatar image

You can solve for mu1:

var('x, mu1, mu2, sigma')
result=solve(exp((0.5/sigma)*(x-mu1)^2)==exp((0.5/sigma)*(x-mu2)^2),mu1)
show(result)
Preview: (hide)
link

Comments

Thanks, that worked!!

YetAnotherUsr gravatar imageYetAnotherUsr ( 3 years ago )

By the way, what if I wanted to solve for two variables, meaning I wanted to check if for different σ1 and σ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 ( 3 years ago )
1

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

mwageringel gravatar imagemwageringel ( 3 years ago )

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

Stats

Asked: 3 years ago

Seen: 1,207 times

Last updated: Jul 20 '21