Programming and writing about it.

echo $RANDOM

Tag: sympy

Doing Math with Python: Chapters 5 and 6 in early access

I am excited to share that the fifth and sixth chapters are available as part of the early access of my book Doing Math with Python.

10255353_654805211303462_239961520606625195_n

Chapter 5: Sets and Probability

This chapter starts off with how to create a set and demonstrating the common set operations. Utility of the different set operations are demonstrated via simple applications. For example, Cartesian product is used to write a program to simulate an experiment to calculate the time period of a simple pendulum of different lengths and at places with varying gravity. Union and intersection operations are applied to finding the probability of events.

The chapter then moves onto discussing how to generate uniform and non uniform random numbers, and using them to simulate scenarios such as a die roll and a fictional ATM which dispenses dollar bills of different denominations with varying probability.

One of the challenges at the end discusses drawing venn diagrams.

Chapter 6: Drawing shapes and Fractals

This chapter is logically divided into two parts. The first part introduces the reader to matplotlib patches which allows drawing geometric shapes (circles and polygons), followed by matplotlib’s animation API which allows drawing animated figures. The trajectory of a projectile motion discussed elsewhere in various contexts is animated combining both these things.

The second part of the book introduces the concept of geometric transformation. Combining that with the knowledge of generating random numbers learned earlier in Chapter 5, the reader will learn how to draw fractals such as the Barnsley Fern.

The challenges at the end gives the opportunity for the reader to explore the Sierpinski triangle and Henon’s function.

Trying out the programs

Using the Anaconda distribution (Python 3) should be the easiest way to try out all the programs in the book. You will need matplotlib, sympy 0.7.6 and matplotlib_venn to try out the programs. An installation guide will be available online soon.

Stay updated

I am working on the last chapter for the book. You can stay updated on the book via various channels:

Blog posts: http://echorand.me/category/doingmathwithpython/

Facebook page: https://www.facebook.com/doingmathwithpython

G+ Community: https://plus.google.com/u/0/communities/113121562865298236232

Twitter: https://twitter.com/mathwithpython

If you are interested in taking a look at a sample copy, I can try to get a sample for you to look at the current pre-released version of the book. Please feel free to get in touch.

Advertisements

Doing Math with Python: Two more chapters in Early Access

I am excited to share that the third and fourth chapters are available as part of the early access of my book Doing Math with Python.

10255353_654805211303462_239961520606625195_n

Chapter 3: Describing Data with Statistics

As the title suggests, this chapter is all about the statistical measures one would first learn in high school – mean, median, mode, frequency table, range, variance, standard deviation and linear correlation are discussed.

Chapter 4: Algebra and Symbolic Math with SymPy

The first three chapters are all about number crunching. The fourth chapter introduces the reader to the basics of manipulating symbolic expressions using SymPy. Factorizing algebraic expressions, solving equations, plotting from symbolic expressions are some of the topics discussed in this chapter.

Trying out the programs

Using the Anaconda distribution (Python 3) should be the easiest way to try out all the programs in the book.

Announcing early access for “Doing Math with Python”

Early Access promotion:

No Starch Press is running a promotion tomorrow (29/01/2015 – PST)  that will offer 40% off all Early Access titles on nostarch.com, including Doing Math with Python. The discount code is BRIGHTANDEARLY. Currently two chapters are available and more should be up in the coming days!

I am excited to write that my new book “Doing Math with Python” to be published by No Starch Press is now available via their “Early Access” program – which means if you now buy the book, you will get the chapters as and when they are available and also, the chapters may need more polishing.

10255353_654805211303462_239961520606625195_n

The book uses Python 3 exclusively and the Appendix A covers setup and installation instructions for Python 3 and the libraries used in the book. However, that is not yet available. Hence, at this stage, the easiest way would be to use a distribution such as Anaconda on Windows, Linux or Mac OSX (untested, I don’t have access to the OS).