Inlining


Run and explain the following:

function inline_ex
n  = 1e7;
x  = 0;
dx = 1 / n;

tic
s = 0;
for k = 1:n
  s = s + sin(x) * exp(x) * atan(x);
  x = x + dx;
end
toc
s

x = 0;
tic
s = 0;
for k = 1:n
  s = s + f(x);
  x = x + dx;
end
toc
s

function y = f(x)
y = sin(x) * exp(x) * atan(x);


Back