Guest User

Untitled

a guest
Jan 17th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. function y = kron2()
  2. res =[];
  3. K=10;
  4. for n=2.^(3:6);
  5. x=rand((n).^2,1);
  6. A=rand(n);
  7. B=rand(n);
  8. t1 = realmax;
  9. for k=1:K;
  10. tic
  11. z = zeros(n);
  12. for i=1:n;
  13. z(i,:)=B*x((i-1)*n+1:i*n);
  14. end
  15. y=reshape((A*z)',1,n*n)';
  16. t1 = min(toc,t1);
  17. end
  18.  
  19. t2 = realmax;
  20. for k=1:K;
  21. tic
  22. y2 = kron(A,B)*x;
  23. t2 = min(toc,t2);
  24. end
  25.  
  26. res = [res; n, t1 , t2];
  27. end
  28.  
  29. figure;
  30. loglog(res(:,1),res(:,2),'r+',res(:,1),res(:,3),'m*');
  31. hold on;
  32. x=1:0.5:1000;
  33. plot(x, 0.00000008*x.^4)
  34. plot(x, 0.0000004*x.^2)
  35. end
Add Comment
Please, Sign In to add comment