SciPy Recipes
  1. 386 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub
Book details
Book preview
Table of contents
Citations

About This Book

Tackle the most sophisticated problems associated with scientific computing and data manipulation using SciPy

Key Features

  • Covers a wide range of data science tasks using SciPy, NumPy, pandas, and matplotlib
  • Effective recipes on advanced scientific computations, statistics, data wrangling, data visualization, and more
  • A must-have book if you're looking to solve your data-related problems using SciPy, on-the-go

Book Description

With the SciPy Stack, you get the power to effectively process, manipulate, and visualize your data using the popular Python language. Utilizing SciPy correctly can sometimes be a very tricky proposition. This book provides the right techniques so you can use SciPy to perform different data science tasks with ease.

This book includes hands-on recipes for using the different components of the SciPy Stack such as NumPy, SciPy, matplotlib, and pandas, among others. You will use these libraries to solve real-world problems in linear algebra, numerical analysis, data visualization, and much more. The recipes included in the book will ensure you get a practical understanding not only of how a particular feature in SciPy Stack works, but also of its application to real-world problems. The independent nature of the recipes also ensure that you can pick up any one and learn about a particular feature of SciPy without reading through the other recipes, thus making the book a very handy and useful guide.

What you will learn

  • Get a solid foundation in scientific computing using Python
  • Master common tasks related to SciPy and associated libraries such as NumPy, pandas, and matplotlib
  • Perform mathematical operations such as linear algebra and work with the statistical and probability functions in SciPy
  • Master advanced computing such as Discrete Fourier Transform and K-means with the SciPy Stack
  • Implement data wrangling tasks efficiently using pandas
  • Visualize your data through various graphs and charts using matplotlib

Who this book is for

Python developers, aspiring data scientists, and analysts who want to get started with scientific computing using Python will find this book an indispensable resource. If you want to learn how to manipulate and visualize your data using the SciPy Stack, this book will also help you. A basic understanding of Python programming is all you need to get started.

Frequently asked questions

Simply head over to the account section in settings and click on ā€œCancel Subscriptionā€ - itā€™s as simple as that. After you cancel, your membership will stay active for the remainder of the time youā€™ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlegoā€™s features. The only differences are the price and subscription period: With the annual plan youā€™ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, weā€™ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access SciPy Recipes by V Kishore Ayyadevara, Luiz Felipe Martins, Ruben Oliva Ramos, Tomas Oliva, Ke Wu in PDF and/or ePUB format, as well as other popular books in Computer Science & Data Processing. We have over one million books available in our catalogue for you to explore.

Information

Year
2017
ISBN
9781788295819
Edition
1

Calculus, Interpolation, and Differential Equations

In this chapter, we will present the following recipes:
  • Integration
  • Computing integrals using a Gaussian quadrature
  • Computing integrals with weighting functions
  • Computing multiple integrals
  • Interpolation
  • Computing a polynomial interpolation for a set of data points
  • Univariate interpolation
  • Finding a cubic spline that interpolates a set of data
  • Defining a B-spline for a given set of control points
  • Differentiation
  • Solving a one-dimensional ordinary differential equation
  • Solving a system of ordinary differential equations
  • Solving differential equations and systems with parameters
  • Using ode and the objected-oriented interface to solve differential equations

Introduction

Common to the design of a railway or road building (especially for highway exits), as well as those crazy loops in many roller coasters, is the solution of differential equations in two or three dimensions that address the effect of curvature and centripetal acceleration on moving bodies. In the 1970s, Werner Stengel studied and applied several models to attack this problem and, among the many solutions he found, one struck him as particularly brilliantā€”the employment of clothoid loops (based on sections of Cornu's spiral). The first looping coaster designed with this paradigm was constructed in 1976 in the Baja Ridge area of Six Flags Magic Mountain, in Valencia, California, USA. It was built during the great American Revolution, and it featured the very first vertical loop (together with two corkscrews, for a total of three inversions). The following is an image of a roller coaster for you to relate this to:
>
The tricky part of the design was based on a system of differential equations, whose solution depended on the integration of Fresnel-type sine and cosine integrals, and then selecting the appropriate sections of the resulting curve. Let's see the computation and plot of these interesting functions:
import numpy as np
from scipy.special import fresnel
import pylab
t = np.linspace(-10, 10, 1000)
pylab.plot(*fresnel(t), c='k')
pylab.show()
This results in the following plot:
The importance of Fresnel integrals granted them a permanent place in SciPy libraries. There are many other useful integrals that shared the same fate and now lie ready for action in the scipy.special module. For a complete list of all of those integrals, as well as the implementation of other relevant functions and their roots or derivatives, refer to the online documentation of scipy.special at: http://docs.scipy.org/doc/scipy-0.13.0/reference/special.html.

Integration

In the next section, we will get ourselves acquainted with the methods of integration.

Getting ready

To get involved in the following recipe, we need to know about the following instructions and requirements:
  • To achieve the definite integration of functions on suitable domains, we have mainly two methodsā€”numerical integration and symbolic integration.
  • Numerical integration refers to the approximation of a definite integral via a quadrature process. Depending on how the function f(x) is given, the domain of integration, the knowledge of its singularities, and the choice of quadrature is the main part of this section.
  • In many cases, it is also possible to perform exact integration, even for non-bounded domains, with the aid of symbolic computation. In the SciPy stack, to this effect, we have an implementation of the Risch algorithm for elementary functions, and Meijer G-functions for non-elementary integrals. Both methods are housed in the SymPy libraries. Unfortunately, these symbolic procedures do not work for all functions, and due to the complexity of the generated codes in general, the solutions obtained by this method are by no means as fast as any numerical approximation.

How to do itā€¦

Symbolic integration is done through the following steps:
  1. The definite integral of a polynomial function on a finite domain [a,b] can be computed very accurately via the fundamental theorem of calculus, using the numpy.polynomial module. For instance, to calculate the integral of the polynomial p(x)=x5 on the interval [-1,1].
  2. We could issue the fo...

Table of contents

  1. Title Page
  2. Copyright
  3. Credits
  4. About the Authors
  5. About the Reviewer
  6. www.PacktPub.com
  7. Customer Feedback
  8. Preface
  9. Getting to Know the Tools
  10. Getting Started with NumPy
  11. Using Matplotlib to Create Graphs
  12. Data Wrangling with pandas
  13. Matrices and Linear Algebra
  14. Solving Equations and Optimization
  15. Constants and Special Functions
  16. Calculus, Interpolation, and Differential Equations
  17. Statistics and Probability
  18. Advanced Computations with SciPy