Advertisement
HimikoWerckmeister

Untitled

Jan 27th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. % MACM 316 - Week 3
  2. % Computation Time demo
  3. % Description: Finds the mean computation time for Gaussian Elimination on a
  4. % random matrix
  5. % Instructor: Ben Adcock
  6. %
  7.  
  8. clear
  9.  
  10. Ntr=200; % Number of trials
  11. N=200; % Matrix size
  12. stepsize = 5;
  13. %meanvector = zeros((N/stepsize),1);
  14. meanvector = zeros(N,1);
  15. xvector = 1:1:N;
  16.  
  17. %times=zeros(Ntr,1); % Vector of timing data for Ntr trials
  18. %times = zeros(N/stepsize,1);
  19. for i=1:N %keep incrementing for different N with set stepsize
  20. times = zeros(Ntr,1);
  21. for j=1:Ntr
  22.  
  23. % Form a random matrix A and right-hand side b (normally distributed)
  24. A=randn(N,N);
  25. b=randn(N,1);
  26.  
  27. % Apply backslash and calculate time taken
  28. tic;
  29. x=A\b;
  30. times(j)=toc;
  31.  
  32. end
  33. meantimes = mean(times);
  34. meanvector(i) = meantimes
  35. end
  36.  
  37. N;
  38. %mean_time=mean(times);
  39. plot(xvector,meanvector,'r+')
  40. %loglog(xvector,meanvector,'r+')
  41. title(['Mean time vs Matrix Size'])
  42. xlabel(['Matrix size'])
  43. ylabel(['Mean time'])
  44. hold on
  45. %scatter(xvector,meanvector)
  46. %lsline
  47. %hold on
  48. hold on
  49. %f = polyfit(xvector',meanvector,1)
  50. %plot(xvector,f)
  51. %x1 = [1:1:N]
  52. %y1 = polyval(f,x1)
  53. %loglog(x1,y1)
  54. %hold on
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement