Function M Files Function M files are like Script M files but can pass parameters and isolate variables These capabilities can be used to add new functions to MATLAB s list perform computational experiments and prepare graphics Example 1 Create a function M file for the function f x x 3 2 Execute edit at the command line to open the editor Enter the following function y f x y x 3 2 Save as prompted namely f m You may now use the function file to compute f 3 f 4 etc Example 2 Create a function M file for the function y of an object above the ground after t seconds 42 644 t 1 e t where y is the height 5 5 Open a new M file in the editor Enter function y height t y 42 5 t 644 5 1 exp t Save as height m You may now use the function file to compute height 3 height 5 etc Example 3 Plot the height function in example 2 and use the graph to estimate the maximum height Open a new M file in the editor Enter function examp2 AcroPDF A Quality PDF Writer and PDF Converter to create PDF files To remove the line buy a license close all t linspace 0 15 200 y height t plot t y grid on xlabel time in seconds ylabel height in meters title Graph of Function in Example 2 function y height t y 42 5 t 644 5 1 exp t Save the file as examp2 m Use Debug Run to execute with F5 AcroPDF A Quality PDF Writer and PDF Converter to create PDF files To remove the line buy a license
View Full Document