Book Image

Sage Beginner's Guide

By : Craig Finch
1 (1)
Book Image

Sage Beginner's Guide

1 (1)
By: Craig Finch

Overview of this book

Table of Contents (17 chapters)
Sage Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – manipulating trigonometric expressions


Sage has several methods that are used primarily when an expression involves trigonometric functions. Let's try them out.

var('x, y')
f(x, y) = sin(x) * cos(x)^3 + sin(y)^2
print("f(x, y)")
f.show()

g(x, y) = f.reduce_trig()    # also trig_reduce
print("After trig_reduce:")
g.show()

print("After expanding:")
show(g.expand_trig())       # also trig_expand

print("Simplify to get original expression:")
show(g.expand_trig().trig_simplify())    # also simplify_trig

The output is shown in the following screenshot:

What just happened?

We demonstrated some useful methods that are specifically designed to manipulate expressions that involve trigonometric functions. expand_trig and reduce_trig (or trig_expand and trig_reduce) are complementary methods that have a similar function to those used in the previous example. We also introduced the method called trig_simplify (or simplify_trig), which attempts to represent an expression in the most...