APPENDIX D
TIPS FOR PROGRAMMING IN MATLAB
D.1 USEFUL TIPS FOR PROGRAMMING
Matlab is a technical programming language which is widely used by researchers
due to convenience in programming and powerfulness in computation. The user
interface of Matlab is simple and it is easy to learn for programming, especially for
beginners. Matlab provides many powerful toolboxes developed for certain fi elds
suitable for students and researchers to their researches. The basis of computation
in Matlab is based on matrix operations. However, the performance of computation
in Matlab is slower than that of some other programming languages such as C or
Delphi. Therefore, speeding up the calculation in Matlab is also a very important
work when coding an algorithm. The purpose of this appendix is not a tutorial on
Matlab but to present the users some important tips to enhance the calculation
and simplify the programs coded in Matlab. These tips are especially useful for
large scale problems in terms of computational time and programming simplicity.
By adhering to these tips, the user can save considerable computational time
compared to the normal programming of the same algorithm. The difference in
computational time can be clearly observed in large-scale problems with several
variables. Moreover, with complex algorithms, these tips can help to considerably
reduce the length of the program to ease its management. Moreover, readers can
develop new ideas for faster calculation further based on these tips.
The essential idea to speed up to calculation in Matlab that we would like to
introduce consists of the following points:
- Try to use the built-in functions: The built-in functions are the ones directly
coded in Matlab; their source code cannot be viewed by the user as opposed
to the functions developed in the toolboxes which are separately included in
Matlab and whose source code can be viewed by the users by the *.m tag. The
advantage of the built-in functions is that they perform a task faster than the
functions in toolboxes do. Therefore, in programming the users should try to
use the built-in functions or their combination fi rst before choosing functions
from toolboxes. To identify whether a function is a built-in one or not, use
the command type <function name>. On the other hand, using the functions
available in Matlab, either built-in functions or toolbox functions, would be
better than functions developed by the user since the included functions are
mature in terms of correctness and fast performance time.
- Apply matrix operations in programming: The basic calculation of Matlab is
based on matrix. Therefore, matrix operations are most suitable for Matlab
coded algorithms to provide for fast computation and simple programming.
Get Artificial Intelligence in Power System Optimization now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.