# Matlab code help

• MATLAB
Alright I have to questions one is on how to measure the time it takes for my computer to solve a particular code Ive 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

Related MATLAB, Maple, Mathematica, LaTeX 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 whats 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.

Alright I have to questions one is on how to measure the time it takes for my computer to solve a particular code Ive 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 $A$ 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.

sorry one more question I need to solve for x in Ax=b with A =rand 100*100 matrix and B=rand100*1 whats 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.