Preface


This tutorial is an introduction to the programming package matlab (created by MathWorks© ). This tutorial was developed solely for the purpose of education. The tutorial accompanies the textbook Applied Differential Equations. The Primary Course by Vladimir Dobrushkin, CRC Press, 2015; http://www.crcpress.com/product/isbn/9781439851043.

If you have not taken or are not taking a course regarding matlab or programming, such as CSCI 0150 or ENGN 0030, then please start with Tutorial for the first course. For those who have used matlab before, please note that there are certain commands and sequences of input that are specific for solving differential equations, so it is best to read through this tutorial in its entirety. MathWorks updates Matlab every year. Therefore, tutorials from other sources may or may not be compatible with this tutorial.

This tutorial contains software programs that are free: you can redistribute codes and/or modify scripts under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This tutorial is distributed in the hope that its material and codes will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. For full version of GNU General Public License, see https://www.gnu.org/licenses/gpl-3.0.en.html.

This tutorial corresponds to the matlab “m” files that are posted on the APMA 0340 website. You, as the user, are free to use the m files to your needs for learning how to use the matlab program, and have the right to distribute this tutorial and refer to this tutorial as long as this tutorial is accredited appropriately. Any comments and/or contributions for this tutorial are welcome; you can send your remarks to <Vladimir_Dobrushkin@brown.edu>

Many mathematical problems can be solved approximately by numerical computations. The computation steps operate on numbers, which are stored internally in floating-point representation. This representation has the drawback that neither computations nor solutions are exact due to rounding errors. In general, numerical algorithms find approximate solutions as fast as possible. Often such solutions are the only way to handle a mathematical problem computationally, in particular if there is no “closed form” solution known. (The most popular example for this situation are roots of polynomials of high degrees.) Moreover, approximate solutions are useful if exact results are unnecessary (e.g., in visualization).

Cleve Moler introduced the first version of matlab (short for "MATrix LABoratory") to a group of Stanford University students in 1979. In its original form, it allowed scientists to chain together calls to optimized Fortran routines using an interactive text-based interpreter. Jack Little and Cleve Moler, the cofounders of MathWorks, recognized the need among engineers and scientists for more powerful and productive computation environments beyond those provided by languages such as Fortran and C. In response to that need, they combined their expertise in mathematics, engineering, and computer science to develop matlab, a high-performance technical computing environment. matlab combines comprehensive math and graphics functions with a powerful high-level language. The heart of the matlab engine is its kernel, which is implemented in C++, while interfacing with programs written in other languages, including C, C++, Java, Fortran, and Python.

There is a certain level of compatibility that allows us to write and run most programs seamlessly both in matlab and Octave. Just as matlab has its toolboxes, Octave has a richful set of functions available through a project called Octave-forge (see the website octave.sourceforge.net). This function repository grows steadily in many different areas. Some functions we use in this book don’t belong to the Octave core, nevertheless they can be downloaded by the website octave.sourceforge.net.

matlab program and script files always have filenames ending with ".m"; the programming language is exceptionally straightforward since it has much in common with popular programming language C. matlab prompt always starts with a double arrow (>>), which tells you that the software is waiting for your input. In future, we will drop matlab prompt (>>) and write codes directly within a special box. However, in this introduction we show all details. To get help, simply type:
>> help
[a long list of help topics follows]

and for specific commands:
>> help fft
[a help message on the fft function follows].
      
Help is available through the online manual – select the `Product help’ entry from the Help menu on the main window. You can use the navigator to search for help, or you can use the index in the Contents window to learn about matlab features.

By typing semicolomn (;) at the end of your command, matlab surpresses windows output; otherwise, the output is sent to the screen. To quit matlab session, simply type quit or exit on Matlab prompt, or click at the end red button of windows right upper corner. Note that you don’t need to type a semicolon at the end of the line. If you do put a semicolon, the operation will be completed but matlab will not print the result. This can be useful when you want to do a sequence of calculations. Special numbers, like `pi’ and ‘i’ don’t need to be capitalized. But beware -- you often use "i" as a counter in loops – and then the complex number i gets re-assigned as a number. You can also do dumb things like pi=3.14. Later you can reset these special variables to their proper definitions by using clear i or clear pi.

The Command History window keeps track of everything you have typed. You can double left click on a line in the Command history window to repeat it, or right click it to see a list of other options. If you screw up early on in a sequence of calculations, there is no quick way to fix your error, other than to type in the sequence of commands again. You can use the ‘up arrow’ key to scroll back through a sequence of commands. If you are really embarrassed by what you typed, you can right click the command window and delete everything (but this will not reset variables). You can also delete lines from the Command history, by right clicking the line and selecting Delete Selection. Or you can delete the entire Command History. You can get help on matlab functions by highlighting the function, then right clicking the line and selecting Help on Selection.

When you start matlab, you should see the Graphic User Interface (GUI) shown below. The various windows may be positioned differently on your version of matlab – they are ‘drag and drop’ windows. You may also see a slightly different looking GUI if you are using an older version of matlab.

Return to computing page for the first course APMA0330
Return to computing page for the second course APMA0340
Return to Matlab tutorial for the first course APMA0330
Return to MuPad tutorial for the first course APMA0330
Return to MuPad tutorial for the second course APMA0340
Return to the main page for the course APMA0340
Return to the main page for the course APMA0330