Introduction Functions  Environments:-  J  Matlab Mathematica Maple APL HP48G TI85 TI89
Function definitions in Matlab
function [y]=sample(a,b,n) 
y = (a : (b-a)/n : b); 
% or  linspace(a,b,n+1) 

function [y]=d(x) 
y = diff(x); 

function [y] = mids(x) 
n=length(x); 
y=(x(1:n-1) + x(2:n)) / 2; 

function [y]=S(x) 
y = cumsum([0 , x]); 

sum is a primitive function

A typical sequence to demonstrate that the derivative of the integral returns the original function might consist of 

               x     =  sample(0, 3, 100) ; 
               y     =  exp(- x .^ 2) ; 
               Iy    =  S (mids(y) .* d(x)) ; 
               DIy  = d(Iy) ./  d(x) ; 
              plot (x,y,mids(x),DIy) 
 

The four functions should be defined in separate M-files.   Because of the file references, the user-defined function names are NOT case sensitive (although variable names are).  In particular, beware that the definition of S.m interferes with symbolic combination operators in the symbolic toolbox.  This conflict is resolved by choosing another name such as csum instead of S
 (The functions can be downloaded by clicking on each of the file names: sample.m , d.m, mids.m , S.m
Introduction Functions Environments:-  J  Matlab Mathematica Maple APL HP48G TI85 TI89