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 – working with rational functions


Let's say you have used the Laplace transform to solve an ordinary differential equation. You have a rational function in the s domain, and you need to transform it back to the original problem domain. Here are some tools you can use to manipulate the symbolic expression to make it easier to perform the inverse Laplace transform:

var('s')
F(s) = (s + 1) / (s^2 * (s + 2)^3)
show(F)

print("Numerator: ")
show(F.numerator())
print("Denominator: ")
show(F.denominator())

print("Expanded:")
show(F.expand_rational())

print("Partial fraction expansion:")
pf(s) = F.partial_fraction()
show(pf)

The results are shown in the following screenshot:

What just happened?

We defined a rational function, and demonstrated the utility methods numerator and denominator to obtain different parts of the expression. The method expand_rational separates the expression into a sum of terms by multiplying out products of sums and exponentials, splitting the numerator...