Albert Danial
Python for MATLAB Development
Extend MATLAB with 300,000+ Modules from the Python Package Index
Logo of the publisher
Albert Danial
Redondo Beach, CA, USA
ISBN 978-1-4842-7222-0 e-ISBN 978-1-4842-7223-7
https://doi.org/10.1007/978-1-4842-7223-7
Albert Danial 2022
This work is subject to copyright. All rights are solely and exclusively licensed by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use.
The publisher, the authors and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, expressed or implied, with respect to the material contained herein or for any errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
This Apress imprint is published by the registered company APress Media, LLC part of Springer Nature.
The registered company address is: 1 New York Plaza, New York, NY 10004, U.S.A.
To Ashley, Theodore, Mimi
Preface
In 2018, I was chatting with a young engineer who had recently earned an engineering masters degree. MATLAB came up and she spoke of her frustration with license shortages when projects came due at school. I had the same frustrations25 years earlier. Had nothing changed?
Of course, a lot had changed.
By then, we had already found our separate ways to Python to do the kind of work we used to do in MATLAB. Why were so few MATLAB users aware of the power and freedom Python could bring them?
I began assembling notes comparing Python solutions to their MATLAB equivalents and shortly afterward learned of MATLABs py module. A binary API to Python?! Too good to be true. It was too good to be true, in a sense; early versions couldnt use critical modules such as NumPy.
The MathWorks improved py with each MATLAB release, though, and today MATLAB can run code from NumPy, SciPy, Pandas, matplotlib, statsmodels, dask, even modules compiled with Cython, Numba, Pythran, and f2py . The MATLAB + Python combination offers astounding possibilities to both languages, yet few MATLAB developers know of this capability or how to take advantage of it. Fertile ground for a new book, I thought.
Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub at https://github.com/Apress/python-for-matlab-development. For more detailed information, please visit http://www.apress.com/source-code.
Acknowledgments
Rachel Rybarczyks comments about MATLAB and Python inspired me to start the journey that led to this book.
Alain Sei, although bowing out as my coauthor after realizing the magnitude of the work ahead, nonetheless stayed on as my first reader. At our weekly meetings in building R2, Alain put thought-provoking spin on things to keep my perspective fresh.
Rocco Samuele helped elevate the literary quality of the text. While I dont have Roccos chops for the written word, his edit suggestions clarified my writing.
Ravi Narasimhans critique of an early draft felt more like a mugging than a review. After the bruises faded, it was clear hed given me a goldmine of improvement suggestions. Implementing them led to a more balanced tone and more convincing assertions. Ravi also provided the MATLAB examples for the point and line plots on maps shown in Section .
When Curtis Webb first told me about Numba four years ago, I dismissed his claims that it could make Python functions run 10 , even 30 fasterwithout using a C/C++/Fortran compiler. Impossible! Yet somehow, like a magical alien technology, Numba does just that. Best tip ever, thanks, Curtis!
Parker Hudnut gave valuable big picture suggestions on the books overall structure. Thanks! The beers on me the next time were at building H.
Thank you Steven Millett, Petra Poschmann, Drew Swalley, and Mark Vaughn for tips on missing or incomplete topics.
Thanks to Professor John Hedengren for letting me copy his predband() function in my section on prediction intervals (Section has excellent videos on statistical computations in Python.
Thanks to Professor James Doyle for advice on, and a technical review of, the frequency response section, Section . His classic red book on structural wave propagation [1] remains one of my favorite technical reads.
Dale Williamsons insights on structural dynamics were inspiring and educational, and for that Im grateful; thanks Dale. Errors with the formulation of equations and procedures are entirely mine.
My technical reviewers, Phillip Feldman and Darrell Yocom, are the unsung heroes behind the operational aspects of the code and examples. Both found numerous code errors and saved me from embarrassingly wrong explanations. Phillip guided me through the confidence and prediction intervals in the regression section, Section Section .
To the Apress team, thank you: Steve Anglin for taking a chance on me; Mark Powers for shepherding the book from early draft to production; Sherly Nandha for the extensive copy editing and typesetting work needed to turn my draft into a book.
Finally, and most importantly, thanks to Ashley, Theodore, and Mimi for believing in me and giving me time and space to write.
A.N.D.
November 2021
Table of Contents
About the Author
Albert Danial
is an aerospace engineer with 30 years of experience, currently working for Northrop Grumman near Los Angeles. Before Northrop Grumman, he was a member of the NASTRAN Numerical Methods team at MSC Software and a systems analyst at SPARTA. He has a Bachelor of Aerospace Engineering degree from the Georgia Institute of Technology and masters and Ph.D. degrees in Aeronautics and Astronautics from Purdue University. He is the author of cloc, the open source code counter.
Al has used MATLAB since 1990 and Python since 2006 for algorithm prototyping, earth science data processing, spacecraft mission planning, optimization, visualization, and countless utilities that simplify daily engineering work.
About the Technical Reviewers