Skip to content

Instantly share code, notes, and snippets.

@alphaville
Created January 28, 2013 22:56
Show Gist options
  • Select an option

  • Save alphaville/4660079 to your computer and use it in GitHub Desktop.

Select an option

Save alphaville/4660079 to your computer and use it in GitHub Desktop.
SMDV_QUAD returns x'*Q*x where Q is a sparse matrix and x a vector.
function [y, time] = smdv_quad(Q,x)%#codegen
%SMDV_QUAD returns x'*Q*x where Q is a sparse matrix and x a vector.
coder.extrinsic('tic');
coder.extrinsic('toc');
tic;
y=0;
for k=1:size(Q,1)
i = Q(k,1);
y = y + Q(k,3) * x(i) * x(Q(k,2));
end
time=toc;
end % end-funct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment