About this book
There are many books on MatLab, and many more on programming and on computing. But few – if any – take a procedural approach to the subject. This text attempts to do just that.
Programming texts tend to follow a traditional approach. You learn how to print Hello World. From there you learn to calculate, followed by selection, repetition, arrays, and then finally functions. Some books may include recursion, but if they do it is near the end if not the last topic in the text.
MatLab texts consistently take a different approach. Since MatLab is a matrix centered language – after all, MatLab is short for Matrix Laboratory – it starts with matrices and how to use them to solve engineering problems. They tend to avoid the more traditional topics in programming until later, and then only as to how they support matrix operations.
This approach is paradoxical. While the student learns to use MatLab they might not receive the exposure to the traditional programming topics that they would in a course taught in Python, or C++. This is fine if the goal of the course is to prepare them to apply MatLab to specific problems in future engineering classes. But engineering students eventually graduate and move on to industry or graduate school. Again, not a problem if, as an engineer, they never need to code in a language other than MatLab. But the chance of that in today’s technological world is slim.
This book bridges that gap between the traditional programming course and the MatLab course. Its goal is to introduce programming to an audience of engineers or engineering students with no prior experience in the topic. This approach starts with the traditional concepts of single value variables – or in the MatLab case, scalars – and then proceeds with the common programming structures. %It does make a significant change from tradition in its treatment of functions.
Programming pedagogy has always been variables, selection, repetition, functions or procedures, and – if time permits – classes and objects. The problem with this approach is that while we start calling functions from the beginning – trig functions, logarithms, square roots – we do not learn about writing functions till near the end of the course. But functions are what make programming plug and play. Once there is a basic understanding of functions the student can start reusing code in multiple programs. It quickly becomes obvious that much of programming is repetition of what they have done before. To take advantage of this, procedural programming is not put off till the end, but in this approach it is the second topic of the text coming right after variables and assignments.
Once the foundation of functions is laid the course moves onto selection, and since they already have exposure to functions, recursion – another change from tradition. Why recursion and why before repetition? Recursion is rarely taught in beginning program classes. But recursion is natural. It is how the world actually operates. With the basics of writing functions already done it is a natural progression to recursion.
From recursion the book proceeds to repetition structures – while loops – and, with the for loop, the first look at lists, vectors, arrays, and matrices. This leads into to the traditional MatLab topics vectors, matrices, and solving simultaneous equations.
In a normal semester the first chapter is assigned to the students as a reading to provide some history, and programming actually starts in
chapter 2. The goal of this text is not just learning to program but understanding computation and computing. This is the emphasis of the second chapter. It discusses computing, algorithms, flow charting, and algorithmic complexity – another topic rarely mentioned in an introductory course. Complexity provides a look at reality. While an algorithm can be developed and a program written, can the program actually run to completion in an amount of time so that a usable solution can be found?
Flow charts are another topic that while presented in the past has been dropped in most modern programming texts. In this book we bring it back. They provide an excellent visual representation of many of the concepts, and are thus used throughout the book.
My thanks go to all of the students who have already used this book, providing suggestions and identifying errors. I am hopeful that those who use it in the future will continue to do so with that same critical eye.
Joseph Brian Adams, Ph.D., PE
11 May 2021