%-------------------------------------------------------------------------------
% lecture10
% FUNCTIONS (continued)
% This M-File really isn't going to do much because of all the functions
% I'm intending that you cut and paste bits and pieces to try out
%-------------------------------------------------------------------------------
% Syntax reminder
% $function$ [output_args] = name(input_args)
%    H1 comment line accessed by $lookfor$
%    comments accessed by $help$
%    statements (optional)
%    $return$     (optional)
%-------------------------------------------------------------------------------
% Rules for args:
% + Can have zero to many input&output args
% + "Can call function with fewer inputs and outputs than required by function"
%   (actually, you may run into trouble with fewer inputs, but fewer outputs 
%    works OK)
%-------------------------------------------------------------------------------
% 1 output, 1 input
% function v=y(x)
%     v = x+1;
%
% >> y(1:2)
% ans = 2 3
%-------------------------------------------------------------------------------
% multiple inputs
% function v=y(x1,x2)
%     v=x1+x2;
% 
% >> y(1,2)
% ans = 3
%-------------------------------------------------------------------------------
% multiple outputs
% function [v,w] = y(x1,x2)
%     v = x1+x2;
%     w = x1.*x2;
%
% >> y(1,2)      % assumes you mean just the FIRST output
% ans = 3  
% >> z = y(1,2)  % assumes you mean just the FIRST output
% z = 3         
% >> [a b] = y(1,2) % now you get multiple outputs
% a = 3    
% b = 2
%-------------------------------------------------------------------------------
% no outputs
% function y(x1,x2)
%   x1+x2
%
% >> y(1,2)
% ans = 3
%-------------------------------------------------------------------------------
% no inputs
% function y() % could also say "function y"
%
% >> y % enter with no "()"...cool, huh?
% ans = 3 
%-------------------------------------------------------------------------------
% Search path for reference to script or function
% (See MASTERING MATLAB)
% + check if var is an assigned name in the current workspace
% + check if var is a built-in function
% + check if var is subfunction of the function file where var appears
% + check if var is a "private function" in M-File where var appears
%   (beyond scope of CS100M for now)
% + check if var.m exists in current directory
% + check if var.m exists in path, from top to bottom
%-------------------------------------------------------------------------------
% Creating your own toolbox
% + think of toolbox as a collection of functions
% + implications for software:
%   ultimately, related procedures collected together
%   almost all languages have this idea
%   users of software use toolbox (or similar entity for other languages)
%   later in Java, it's called the API....
% + how:
%   create directory inside $toolbox$ directory
%   put M-Files in the directory
% + see MASTERING MATLAB for more info
%-------------------------------------------------------------------------------
% FUNFUN (function function)
% + function with an input argument the name(s) of other function(s)
%   ex) ezplot('cos(x)')
%      $ezplot$ plots a function without having you to figure out other inputs
% + usually input names are strings
% + see $function demofunfun$
% + see $fzero$ (I didn't use in project3, but could have...) 
%-------------------------------------------------------------------------------
% Recursion
% + function calls itself
% + Yes, MATLAB can do that!
% + see $rsum$ example
% + used in project3 as a kind of "repeat" if one script fails to work
%-------------------------------------------------------------------------------
