How can I measure time on MATLAB?

Hi, I am trying to measure the running time of solving system of linear equations using tic , toc. I have to compute the system of linear equation with (A+aI) for different scaler a in one code. How to measure the time of computing the system of linear equations for all a. Do we need to compute the total as I did below or we need to take the average of time?
n=200;
A=full(gallery('tridiag',n,1,2,1));
b=randn(n,1);
tic
[L,U]=lu(A+3*eye(n));
t=L\b;
x=U\t;
time(1)=toc;
tic
[L1,U1]=lu(A+6*eye(n));
t1=L1\b;
x1=U1\t1;
time(2)=toc;
total=time(1)+time(2);

Respuestas (1)

David Hill
David Hill el 24 de Jul. de 2020
n=200;
A=full(gallery('tridiag',n,1,2,1));
a=[3,6];
b=randn(n,1);
for k=1:length(a)
tic
[L,U]=lu(A+a(k)*eye(n));
t(k)=L\b;
x(k)=U\t(k);
time(k)=toc;
end
totalTime=sum(time);

5 comentarios

Omar B.
Omar B. el 24 de Jul. de 2020
So, we do not need to calculate the avearge time?
David Hill
David Hill el 25 de Jul. de 2020
If you want average time, then:
avgTime=mean(time);
Omar B.
Omar B. el 25 de Jul. de 2020
Editada: Omar B. el 25 de Jul. de 2020
Thank you for your help. I was asking what is the best to compute the summation or the avearge time.
Walter Roberson
Walter Roberson el 25 de Jul. de 2020
What is "best" depends upon your needs, but mean() or median() is most often the useful measure.
Omar B.
Omar B. el 25 de Jul. de 2020
Thank you.

Iniciar sesión para comentar.

Categorías

Más información sobre Sparse Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 24 de Jul. de 2020

Comentada:

el 25 de Jul. de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by