How to Measure Code Execution Time & Find LDU Factorization of Matrix A

In summary: The basic approach is to use the backslash operator. Also, you may want to look into using sparse matrices to improve efficiency if your matrix is very large.
  • #1
scsig805
12
0
Alright I have to questions one is on how to measure the time it takes for my computer to solve a particular code I've tried the the "tic toc" and that seems to be dependent on the time frame that I typed in tic and toc. I need something that Is only dependent on the time taken to process and solve the command.
Second how do I find the LDU factorization of a matrix A? I saw LU and LDL but that was it
thanks Sean
 
Physics news on Phys.org
  • #2
sorry one more question I need to solve for x in Ax=b with A =rand 100*100 matrix and B=rand100*1 what's the quickest way to do so?
 
  • #3
99% of the questions asked in this forum about Matlab are already answered in the Matlab documentation. Indeed, not only do the Matlab docs answer your questions, they answer them more accurately, completely, and concisely than anyone here could.

scsig805 said:
Alright I have to questions one is on how to measure the time it takes for my computer to solve a particular code I've tried the the "tic toc" and that seems to be dependent on the time frame that I typed in tic and toc. I need something that Is only dependent on the time taken to process and solve the command.

Try this:

Code:
doc cputime


scsig805 said:
Second how do I find the LDU factorization of a matrix A? I saw LU and LDL but that was it

Matlab already has LU factorization, so it's easy to transform to LDU factorization. Any textbook on linear algebra will show you how to do this. In case you've forgotten, you can extract the diagonal from a matrix [itex]A[/itex] using the diag command. In Matlab, to look at LDU of a matrix A we would use

Code:
D = diag(diag(A));
LDUA = inv(D) * A;

LDUA is what you're looking for. Again, see any textbook on linear algebra for the details on this if you're feeling a bit rusty.

scsig805 said:
sorry one more question I need to solve for x in Ax=b with A =rand 100*100 matrix and B=rand100*1 what's the quickest way to do so?

Try looking at the Matlab documentation under Matlab -> Mathematics -> Linear Algebra -> Systems of linear equations for a step-by-step guide, including a discussion of efficiency.
 

Related to How to Measure Code Execution Time & Find LDU Factorization of Matrix A

1. How do I measure the execution time of my code?

To measure the execution time of your code, you can use a timing function provided by your programming language, such as time.time() in Python or System.currentTimeMillis() in Java. You can also use a third-party tool like perf or gprof to analyze the performance of your code.

2. What is LDU factorization of a matrix?

LDU factorization is a method of decomposing a square matrix into three parts: a lower triangular matrix (L), a diagonal matrix (D), and an upper triangular matrix (U). This method is often used in numerical linear algebra to solve systems of linear equations.

3. How do I find the LDU factorization of a matrix A?

To find the LDU factorization of a matrix A, you can use various algorithms such as Gaussian elimination, Cholesky decomposition, or LU decomposition. These algorithms are implemented in many programming languages and numerical libraries.

4. Why is it important to measure code execution time?

Measuring code execution time is important because it allows you to identify potential performance issues and optimize your code for better efficiency. It also helps in comparing different algorithms or implementations to determine which one is more efficient.

5. Can I use LDU factorization for any type of matrix?

LDU factorization can be used for any square matrix, as long as it is invertible. However, the method may not be efficient for matrices that are ill-conditioned or have a large number of zero elements. In such cases, other methods like QR decomposition or Singular Value Decomposition (SVD) may be more suitable.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
929
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
293
Replies
34
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
Replies
1
Views
1K
Replies
1
Views
642
  • Linear and Abstract Algebra
Replies
6
Views
1K
  • Mechanical Engineering
Replies
3
Views
2K
Back
Top