MATHEMATICAL METHODSUSING MATLAB PROGRAMMING LANGUAGEApplications toIntegral Calculus, Equations, Derivatives and Differential EquationsScientific Books
INDEX
Chapter 1. THE matlab PROGRAMING FRAMEWORK
1.1 The MATLABworking environment
To start MATLAB, simplydouble-click on the shortcut icon to the program on the Windows desktop.Alternatively, if there is no desktop shortcut, the easiest and most common wayto run the program is to choose
programs from the Windows
Startmenu and select
MATLAB. Having launched MATLAB by either of thesemethods, the welcome screen briefly appears, followed by the screen depicted inFigure 1-1, which provides the general environment in which the program works. The most importantelements of the MATLAB screen are the following:
- The Command Window: This runs MATLAB functions .
- The Command History: This presents a history of the functions introduced in the Command Window and allows you to copy and execute them.
- The Current Directory: This shows MATLAB files and execute files (such as opening and search for content operations).
- Help (support): This allows you to search and read the documentation for the complete family of MATLAB products.
- The Workspace: This shows the present contents of the workspace and allows you to make changes to it.
- The Array Editor: This displays the contents of arrays in a tabular format and allows you to edit their values.
- The Editor/Debugger: This allows you to create, edit, and check M-files (files that contain MATLAB functions).
1.1.1 The MATLAB Command Window
The CommandWindow (Figure 1-1) is the main way to communicate with MATLAB. It appears onthe desktop when MATLAB starts and is used to execute all operations andfunctions.
Figure 1-1 Figure1-2 In the Command Window, it is possible to evaluatepreviously executed operations.
Figure 1-1 Figure1-2 In the Command Window, it is possible to evaluatepreviously executed operations.
To do this, simply select the syntax you wishto evaluate, right-click, and choose the option Evaluate Selection fromthe resulting pop-up menu (Figures 1-3 and 1-4). Choosing Open Selectionfrom the same menu opens in the Editor/Debugger an M-file previouslyselected in the Command Window (Figures 1-5 and 1-6). Figure 1-3 Figure1-4 Figure 1-5 Figure1-6 MATLAB is sensitive to the use of uppercase andlowercase characters, and blank spaces can be used before and after minus signs,colons and parentheses. MATLAB also allows you to write several commands on thesame line, provided they are separated by semicolons (Figure 1-7). Entries areexecuted sequentially in the order they appear on the line. Every command whichends with a semicolon will run, but will not display its output.
Long entries that will not fit on one line can be continuedonto a second line by placing dots at the end of the first line (Figure 1-8). Figure 1-7 Figure1-8 The option Clear CommandWindow from the Edit menu (Figure 1-9) allows you to clear the CommandWindow. The command clc also performs this function (Figure 1-10).Similarly, the options Clear Command History and Clear Workspacein the Edit menu allow you to clean the history window and workspace. Figure 1-9 Figure1-10 To help you to easily identifycertain elements as if/else instructions, chains, etc., some entries inthe Command Window will appear in different colors. Some of the existing rulesfor colors are as follows:
- Chains appear in purple while they are being typed. When they are finished properly (with a closing quote) they become brown.
- Flow control syntax appears in blue.
All lines between the opening and closing of the flow control functions are correctly indented.
- Parentheses, brackets, and keys are briefly illuminated until their contents are properly completed. This allows the user to easily see if mathematical expressions are properly closed.
- Comments in the Command Window, preceded by the symbol %, appear in green.
- System commands such as ! appear in gold.
- Errors are shown in red.
Below is a list of keys, arrows andcombinations that can be used in the Command Window.
Key | Control key | Operation |
CTRL+ p | Calls to the last entry submitted. |
CTRL+ n | Calls to the next line. |
CTRL+ b | Moves one character backward. |
CTRL+ f | Moves one character forward. |
CTRL+ | CTRL+ r | Moves one word to the right. |
CTRL+ | CTRL+ l | Moves one word to the left. |
Home | CTRL+ a | Moves to the beginning of the line. |
End | CTRL+ e | Moves the end of the line. |
ESC | CTRL+ u | Deletes the line. |
Delete | CTRL+ d | Deletes the character where the cursor is. |
BACKSPACE | CTRL+ h | Deletes the character before the cursor. |
CTRL+ k | Deletes all text up to the end of the line. |
Shift+ home | Highlights the text from the beginning of the line. |
Shift+ end |
Next page