Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I evaluate an expression with trignometric functions & also complex numbers in Sagemath?

I wanted to verify if n-th roots of unity are actually the n-th roots of unity?

i.e. if (root)^n = 1

I was trying to use sagemath to do this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

For e.g. for regular expressions sage seems to evaluate stuff

For e.g.

sage: x = var('x')
sage: f(x) = (x+2)^3
sage: f(5)
343

But I am unable to do this

sage: a = var('a')
sage: b = var('b')
sage: f(a, b) = (a + i*b)^3
sage: f(cos((2*pi)/3) , sin((2*pi)/3))
(1/2*I*sqrt(3) - 1/2)^3

How do I make sage raise it to power 3 & evaluate?

>Solution :

A sage expression has several methods to manipulate it, including expanding, factoring and simplifying:

e = f(cos((2*pi)/3) , sin((2*pi)/3))
e.expand()
e.simplify()
e.full_simplify()
e.factor()

You can see the list of all available methods by typing the name of the variable, followed by a dot, followed by a tabulation: e.<tab>.

In your case, it would appear e.full_simplify() should do the trick.

Relevant documentation:

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading