Computer Programming with MATLAB
Programmer’s Toolbox
Polymorphism
- Polymorphic: having multiple forms
- If a function can handle calls when the same input argument has different types: polymorphic function
- If a function can handle a variable number of input arguments: polymorphic also
- Many MATLAB functions return an output that has the same shape as the input provided (e.g., sqrt)
- Polymorphism is very powerful
Random Sequence Initialization
- When we start MATLAB and call rand, it always returns the same exact number: 0.8147 (As an exercise, try it at home
- Pseudo random number generator: initialized at startup and it generates the exact same sequence of numbers every time
- Repeatability for testing the program: good!
- What if we want “truly” random numbers?
- Initialize the MATLAB pseudo random number generator with rng!
Debugging
- It is easy to make mistakes!
- Syntax errors:
- MATLAB catches these errors
- Some may cause errors that MATLAB can catch
- Some may cause the wrong result every time
- Some may only cause problems occasionally (e.g., with a certain combination of inputs)
- Hard to notice and find the cause of MATLAB has built-in debugger Tool to help find errors (bugs)