for loop - How can I compute the time it takes Matlab to do gaussian elimination for various sized matrices? -
this code have far compute how long takes, on average, matlab implement gaussian elimination on matrix of size n=200:
ntr=50; % number of trials n=200; % matrix size times=zeros(ntr,1); % vector of timing data ntr trials i=1:ntr % form random matrix , right-hand side b (normally distributed) a=randn(n,n); b=randn(n,1); % apply backslash , calculate time taken tic; x=a\b; times(i)=toc; end n mean_time=mean(times)
how can modify code computes various values of n such n=200, 500, 1000, 3000 etc? tried loop randn can take in scalar values... end result looking plotting loglog graph of n values against average time taken. appreciated!
you should set vector size want evaluate , in loop define n n=all_the_n(i). way randn take scalar value , iterate on different n.
all_the_n=[100 200 300 400]; %matrix size ntr=4; times=zeros(ntr,1); i=1:ntr n=all_the_n(1,i); a=randn(n,n); b=randn(n,1); f=@() a/b; times(i,1)=timeit(f) end
Comments
Post a Comment