function [capital,interest]=compound(capital,years,rate,timescomp); % COMPUND: function to compute the compounded capital and the interest. % call syntax; % [capital,interest]=compound(capital,years,rate,timescomp); % x0 = capital; n = years; r = rate; k = timescomp; if r>1 | r<0 | x0<0 | n<0 | k<0 % check for common mistakes error('Your input must be positive. Also check your interest rate. For 5% enter .05, not 5.') else capital = x0*(1+r/k)^(k*n); interest = capital - x0; end;