User-defined Functions (4/28) output argument Scripts name of the function input argument function distance dist2(x1,y1,x2,y2) DIST2 Calculate the distance between two points Function DIST2 calculates the distance between two points (xi,yl)and (x2,y2)in a Cartesian 号 coordinate system. Define variables: H1 comment line x1 x-position of point 1 % yl y position of point 1 2 x-position of point 2 other comment lines 号 y2 y-position of point 2 号 distance - Distance between points executable code % Record of revisions: Date Programmer Description of change 号 ==== ≤左=======三 ==================== 号 12/15198 S.J.Chapman Original code CaIculate distance. fdistance sgrt((x2-x1).^2+(y2-y1).^2); 同济大学 TONGJI UNIVERSITY output argument input argument other comment lines executable code H1 comment line name of the function function distance = dist2(x1, y1, x2, y2) %DIST2 Calculate the distance between two points % Function DIST2 calculates the distance between % two points (x1,y1) and (x2,y2) in a Cartesian % coordinate system. % Define variables: % x1 -- x-position of point 1 % y1 -- y-position of point 1 % x2 -- x-position of point 2 % y2 -- y-position of point 2 % distance -- Distance between points % Record of revisions: % Date Programmer Description of change % ==== ========== ===================== % 12/15/98 S. J. Chapman Original code % Calculate distance. distance = sqrt((x2-x1).^2 + (y2-y1).^2); User-defined Functions (4/28) Scripts