Thread Subject: How to speed up this code

Subject: How to speed up this code

From: Gorkem

Date: 29 Jun, 2011 17:31:40

Message: 1 of 1

Hello everyone;

I have a for loop which performs the following portion of code:

%% a0 a1 and a2 are auxilary variables.
M=1e6;
colInner=sparse([1 a1/a0 a2/a0 zeros(1,M-2)]);
rowInner=sparse([1 zeros(1,M)]);
A=sptoeplitz(colInner,rowInner);
A=[sparse([1 0 a2/a0 zeros(1,M-1)]') [sparse(zeros(1,M+1)); A]];
x=[0; 0; x];
nApproximate=A\x;
L=A\sparse([eye(2);zeros(M,2)]);
nUnobservable=-(L'*L/a0^2)\(L'*nApproximate/a0^2);

loglikelihood= -(M/2) * log(2*pi) -((M+2)/2) * log(a0^2) -0.5*log(det(L'*L/a0^2)) ...
                        - 0.5*(nApproximate+L*nUnobservable)' * (nApproximate+L*nUnobservable)/a0^2;

A matrix has a certain structure which is as =[row1; [column1 innerToeplitz]];
A is also a sparse matrix. I use the sptoeplitz function for the construction of A: Link for that function is:
http://www.mathworks.com/matlabcentral/fileexchange/13353-sparse-toeplitz-matrix-construction

However, my code is too slow compared to my needs. Above code is processed in 1 minute approximately for one iteration. How can I speed up my operation? Is there any alternative function for sparse Toeplitz matrix construction which is the part taking the most.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com