fork(3) download
  1. nX=5;
  2. nY=5;
  3. nZ=5;
  4. A=rand(nX,nY,nZ);
  5. B=rand(nX,nY,nZ);
  6. C=rand(nX,nY,nZ);
  7. MM=[1/2 -1i/sqrt(2) -1/2; 1/sqrt(2) 0 1/sqrt(2); 1/2 1i/sqrt(2) -1/2];
  8. for x=1:nX
  9. for y=1:nY
  10. for z=1:nZ
  11. mytemp = MM\[A(x,y,z) B(x,y,z) C(x,y,z)]';
  12. D(x,y,z)=mytemp(1);
  13. E(x,y,z)=mytemp(2);
  14. F(x,y,z)=mytemp(3);
  15. end
  16. end
  17. end
  18.  
  19. ## vectorised
  20.  
  21. X = MM\[A(:)'; B(:)'; C(:)'];
  22. Dp = reshape(X(1,:), nX, nY, nZ);
  23. Ep = reshape(X(2,:), nX, nY, nZ);
  24. Fp = reshape(X(3,:), nX, nY, nZ);
  25.  
  26. norm(D(:) - Dp(:))
  27. norm(E(:) - Ep(:))
  28. norm(F(:) - Fp(:))
  29.  
Success #stdin #stdout 0.21s 65096KB
stdin
Standard input is empty
stdout
ans =  7.7728e-16
ans =  4.7621e-16
ans =  2.8504e-16