Code covered by the BSD License  

Highlights from
Improving MATLABĀ® performance when solving financial optimization problems

image thumbnail

Improving MATLABĀ® performance when solving financial optimization problems

by

 

Jorge Paloschi,PHD and Sri Krishnamurthy,CFA May 2011, http://www.wilmott.com/magazine.cfm

vectorize(s)
function v = vectorize(s)
%VECTORIZE Vectorize expression.
%   VECTORIZE(S), when S is a string expression, inserts a '.' before
%   any '^', '*' or '/' in S.  The result is a character string.
%
%   VECTORIZE(FUN), when FUN is an INLINE function object, vectorizes the
%   formula for FUN.  The result is the vectorized version of the INLINE
%   function.
%
%   See also INLINE/FORMULA, INLINE.

% Modified vectorize function
% Authors:
% Jorge Paloschi (jpalosch@mathworks.com)
% Sri Krishnamurthy(skrishna@mathworks.com)
% Copyright 2011 MathWorks, Inc.

v = char(s);
if isempty(v)==1
    v = [];
else
    v = strrep(v,'^','.^');
    v = strrep(v,'*','.*');
    v = strrep(v,'/','./');
end
v(findstr(v,'..')) = []; % Remove any possible ..*, ../, etc.

Contact us