Essential MATLAB for Engineers and Scientists, Third Edition

The objective of this chapter is to enable you to:
Represent your own functions with inline objects and function M-files.
We have already seen that MATLAB has a number of built-in (compiled) functions, e.g. Sin, sqrt, sum. You can verify that they are built-in by attempting to type them. Try type sin for example. MATLAB also has some functions in the form of function M-files, e.g. fzero, why. You can see what's in them with type, e.g. type why.
MATLAB enables you to create your own function M-files. A function M-file is similar to a script file in that it also has a .m extension. However, a function M-file differs from a script file in that a function M-file communicates with the MATLAB workspace only through specially designated input and output arguments.
Functions are indispensable when it comes to breaking a problem down into manageable logical pieces.
Short mathematical functions may be written as one-line inline objects.
This chapter outlines how to write your own functions, and also introduces MATLAB's interactive debugging facilities.
If two coupled harmonic oscillators, e.g. two masses connected with a spring on a very smooth table, are considered as a single system, the output of the system as a function of time t could be given by something like
You can represent h( t) at the command line by creating an inline...