Book Image

Mastering Python Scientific Computing

Book Image

Mastering Python Scientific Computing

Overview of this book

Table of Contents (17 chapters)
Mastering Python Scientific Computing
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Trigonometry and complex numbers


Mostly, the input for a trigonometric function is a radian angle, whereas an inverse trigonometric function returns the radian angle. This module also provides functions for conversion from degree to radian and radian to degree. Besides basic trigonometric functions, such as sin, cos, and tan, SymPy has trigonometry simplification and expansion functions.

SymPy also supports complex numbers to cope up with situations where no real number solution exists. For example, consider this equation: x**2+4=0. For this equation there is no real number solution; its solution will be -2*I or +2*I. This I denotes the square root of -1. The following program demonstrates trigonometric functions and gives a solution of this equation in the form of complex numbers:

from sympy import *
x, y = symbols('x y')
expr = sin(x)*cos(y)+cos(x)*sin(y)
expr_exp= exp(5*sin(x)**2+4*cos(x)**2)

trigsimp(expr)
trigsimp(expr_exp)
expand_trig(sin(x+y))
solve(x**2+4,x) #complex number as solution...