Albert Danial

Python for MATLAB Development

Extend MATLAB with 300,000+ Modules from the Python Package Index

Albert Danial
Redondo Beach, CA, USA
ISBN 978-1-4842-7222-0e-ISBN 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 master’s degree. MATLAB came up and she spoke of her frustration with license shortages when projects came due at school. I had the same frustrations—25 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 MATLAB’s py module. A binary API to Python?! Too good to be true. It was too good to be true, in a sense; early versions couldn’t 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.

Acknowledgments

Rachel Rybarczyk’s 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 don’t have Rocco’s chops for the written word, his edit suggestions clarified my writing.

Ravi Narasimhan’s critique of an early draft felt more like a mugging than a review. After the bruises faded, it was clear he’d 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 12.​4.

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 × faster—without 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 book’s overall structure. Thanks! The beer’s on me the next time we’re 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 11.​7.​3). His website1 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 14.​13.​7. His classic “red book” on structural wave propagation [1] remains one of my favorite technical reads.

Dale Williamson’s insights on structural dynamics were inspiring and educational, and for that I’m 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 11.​7.​3. Darrell was the original “observant reader” mentioned at the end of the TCP Recipe, Section 7.​18, and first altered me to MATLAB’s type downcast behavior for mixed-type math, Section 15.​2.

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
Index 687
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 master’s 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
Darrell Yocom
earned a master’s degree in Computer Science from USC and has over 40 years of experience programming in the aerospace industry. Through the years, he’s seen programming change from the monolithic spaghetti-Fortran programs of the 1970s to today’s object-oriented approaches. Darrell is an avid sailor and sails the Pacific weekly on his sailboat, Stargazer.
 
Phillip Feldman
, after receiving a PhD in Electrical Engineering from the University of Southern California in 1987, spent six years as a technology policy analyst with the RAND Corporation in Santa Monica, CA. Since then, he’s worked in the aerospace industry for over 20 years.

Much of this work involves communications satellites and related technology. Outside of work, Dr. Feldman has a broad range of interests, many of which are showcased on his website at http://phillipmfeldman.org .

 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.64.126