Guest User

gpu reimann sum

a guest
May 8th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.71 KB | None | 0 0
  1. %full code listing
  2.  
  3.  
  4. t = 0:50000/10000:50000;
  5. omega = 0:10000/10000:10000;
  6. K=1
  7. wt = t'*omega;
  8. wt = wt'; %transposed the matrix as this was originally done in the wrong order
  9. wtgpu = gpuArray(wt);
  10. swtgpu = sin(wtgpu);
  11. clear wtgpu; %no longer needed
  12. swt = gather(swtgpu);
  13. cthw=coth(K*omega);
  14. %%
  15. cothm = zeros(10001,10001); %initialize a large enough matrix
  16. for j = 1:10001
  17.      cothm(j,j) = cthw(j);
  18. end
  19. cothm(1,1)=0;
  20. integralmatrix = (omega(2)-omega(1))*swt*cothm;
  21. % now we sum across the matrix to integrate across omega for each time step t
  22.  
  23. k = 1:10001;
  24. coft = arrayfun(@(n)sum(integralmatrix(n,:)),k); %i don't know how this function                  
  25. %works but it works fast
  26.  
  27. %%
  28. plot(t,coft)
Advertisement
Add Comment
Please, Sign In to add comment