Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % MACM 316 - Week 3
- % Computation Time demo
- % Description: Finds the mean computation time for Gaussian Elimination on a
- % random matrix
- % Instructor: Ben Adcock
- %
- clear
- Ntr=200; % Number of trials
- N=200; % Matrix size
- stepsize = 5;
- %meanvector = zeros((N/stepsize),1);
- meanvector = zeros(N,1);
- xvector = 1:1:N;
- %times=zeros(Ntr,1); % Vector of timing data for Ntr trials
- %times = zeros(N/stepsize,1);
- for i=1:N %keep incrementing for different N with set stepsize
- times = zeros(Ntr,1);
- for j=1:Ntr
- % Form a random matrix A and right-hand side b (normally distributed)
- A=randn(N,N);
- b=randn(N,1);
- % Apply backslash and calculate time taken
- tic;
- x=A\b;
- times(j)=toc;
- end
- meantimes = mean(times);
- meanvector(i) = meantimes
- end
- N;
- %mean_time=mean(times);
- plot(xvector,meanvector,'r+')
- %loglog(xvector,meanvector,'r+')
- title(['Mean time vs Matrix Size'])
- xlabel(['Matrix size'])
- ylabel(['Mean time'])
- hold on
- %scatter(xvector,meanvector)
- %lsline
- %hold on
- hold on
- %f = polyfit(xvector',meanvector,1)
- %plot(xvector,f)
- %x1 = [1:1:N]
- %y1 = polyval(f,x1)
- %loglog(x1,y1)
- %hold on
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement