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

Click For Summary
SUMMARY

This discussion addresses two primary topics: measuring code execution time in MATLAB and finding the LDU factorization of a matrix. For accurate timing, the cputime function is recommended over the tic and toc commands, as it provides a more reliable measure of processing time. To compute the LDU factorization of a matrix A, users can utilize MATLAB's built-in LU factorization and extract the diagonal using the diag command. Additionally, solving the equation Ax=b for a random 100x100 matrix A and a random 100x1 matrix B can be efficiently achieved by consulting the MATLAB documentation on linear algebra.

PREREQUISITES
  • Familiarity with MATLAB programming environment
  • Understanding of matrix factorization concepts, specifically LDU and LU
  • Knowledge of linear algebra, particularly systems of equations
  • Basic proficiency in using MATLAB functions such as diag and rand
NEXT STEPS
  • Explore the cputime function in MATLAB for measuring execution time
  • Study LDU factorization techniques in linear algebra textbooks
  • Review MATLAB documentation on linear algebra, focusing on solving systems of equations
  • Investigate performance optimization techniques in MATLAB for large matrix computations
USEFUL FOR

Mathematics students, data scientists, and engineers who utilize MATLAB for numerical computations and matrix operations will benefit from this discussion.

scsig805
Messages
11
Reaction score
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
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?
 
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.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
7
Views
3K