by Allen Downey, revised and maintained by Craig Scratchley.

This is the page for the second edition. The first edition is still available here.

Read this book online.

Download the book in PDF .

Supporting MATLAB code and the LaTeX source for the book are in this GitHub repository.

### Description:

*Modeling and Simulation in MATLAB, 2nd Edition* is an introduction to programming in MATLAB and simulation of physical systems.

Most books that use MATLAB are aimed at readers who know how to program. This book is for people who have never programmed before.

As a result, the order of presentation is unusual. The book starts with scalar values and works up to vectors and matrices very gradually. This approach is good for beginning programmers because it is hard to understand composite objects until you understand basic programming semantics. But there are some challenges:

- MATLAB documentation is written in terms of matrices, and so are the error messages. To mitigate this problem, the book explains the necessary vocabulary early and deciphers some of the messages that beginners find confusing.
- Many of the examples in the first half of the book are non-standard MATLAB. I address this problem in the second half by translating the examples into a more idiomatic style.

The book puts a lot of emphasis on functions, in part because they are an important tool for controlling program complexity, and also because they are useful for working with MATLAB tools like fzero and ode45.

We assume that readers know calculus and physics at the high school level, but not linear algebra. We present differential equations and use numerical methods to solve them, but we don’t assume that readers have seen differential equations before.

There are small exercises within each chapter and a few larger exercises at the end of some chapters.