fork(1) download
  1. clear all;clc;
  2. %// Datasize paramter(s)
  3. M = 500;
  4. N = M;
  5.  
  6. %// Scalar paramters
  7. A = 4.290;
  8. Tb = 2.34;
  9. p = 4.89;
  10.  
  11. %// Warm up tic/toc.
  12. for k = 1:50000
  13. tic(); elapsed = toc();
  14. end
  15.  
  16. %// Input vectors
  17. N0 = rand(M,1);
  18. lambda = rand(N,1);
  19.  
  20. disp('--------- With Proposed solution')
  21. tic
  22. f1vals = 1.0./sqrt(N0).*sqrt(Tb);
  23. out = p.*erfc(bsxfun(@times,f1vals,A - lambda')).*0.5 - ...
  24. erfc(bsxfun(@times,f1vals,A + lambda')).*(p-1.0).*0.5;
  25. toc
  26. clear out f1
  27.  
  28. disp('--------- With Knedlsepp Version - 1 solution')
  29. tic
  30. f = @(A,N0,Tb,lambda,p) p*erfc((1./sqrt(N0).*sqrt(Tb))*(A-lambda)')*0.5 ...
  31. +(1-p)*erfc((1./sqrt(N0).*sqrt(Tb))*(A+lambda)')*0.5;
  32. out2 = f(A,N0,Tb,lambda,p);
  33. toc
  34. clear out2 f
  35.  
  36. disp('--------- With Rayryeng solution')
  37. tic
  38. M1 = numel(N0);
  39. N1 = numel(lambda);
  40. N0_matrix = repmat(N0.', N1, 1);
  41. lambda_matrix = repmat(lambda, 1, M1);
  42. f = @(A,N0,Tb,lambda,p) p.*erfc(1.0./sqrt(N0).*sqrt(Tb).*(A-lambda)).*(1.0./2.0)-erfc(1.0./sqrt(N0).*sqrt(Tb).*(A+lambda)).*(p-1.0).*(1.0./2.0);
  43. out = f(A, N0_matrix, Tb, lambda_matrix, p);
  44. toc
  45. clear out f lambda_matrix N0_matrix M N
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
Success #stdin #stdout 0.92s 81472KB
stdin
Standard input is empty
stdout
--------- With Proposed solution
Elapsed time is 0.0832101 seconds.
--------- With Knedlsepp Version - 1 solution
Elapsed time is 0.084809 seconds.
--------- With Rayryeng solution
Elapsed time is 0.120952 seconds.