Chapter 7

Function M-files

The objective of this chapter is to enable you to:

ent Write your own 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.

Functions are indispensable when it comes to breaking a problem down into manageable logical pieces. Hence, MATLAB enables you to create your own function M-files. A function M-file is similar to a script file in ...

Get Essential MATLAB for Engineers and Scientists, 5th Edition 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.