Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function y = kron2()
- res =[];
- K=10;
- for n=2.^(3:6);
- x=rand((n).^2,1);
- A=rand(n);
- B=rand(n);
- t1 = realmax;
- for k=1:K;
- tic
- z = zeros(n);
- for i=1:n;
- z(i,:)=B*x((i-1)*n+1:i*n);
- end
- y=reshape((A*z)',1,n*n)';
- t1 = min(toc,t1);
- end
- t2 = realmax;
- for k=1:K;
- tic
- y2 = kron(A,B)*x;
- t2 = min(toc,t2);
- end
- res = [res; n, t1 , t2];
- end
- figure;
- loglog(res(:,1),res(:,2),'r+',res(:,1),res(:,3),'m*');
- hold on;
- x=1:0.5:1000;
- plot(x, 0.00000008*x.^4)
- plot(x, 0.0000004*x.^2)
- end
Add Comment
Please, Sign In to add comment