function s = mySum( n ) % =================================================== % Purpose: This function computes the sum from 1 to n. % Syntax: s = mySum( n ) % Inputs: n = integer % Output: s = result of summation % =================================================== % Initialize variable s = 0; % Check if number is positive if ( n < 1 ) return; else % Accumulate values for i = 1:n s = s + i; end end