[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Trying to solve du/dt = i*u
From: |
Francesco Potorti` |
Subject: |
Re: Trying to solve du/dt = i*u |
Date: |
Sat, 16 May 2009 11:35:02 +0200 |
>Now, my modified script (appended below) has several "for loops," and
>I've read here on more than one occasion that it helps to vectorize
>"for loops" to speed things up. However, I can't see how to
>vectorize the "for loops" in my script. I would appreciate help with
>this from anyone.
By having a quick look, I'd say that you should be able to vectorise
much of the code.
I illustrate one possible strategy with the first loop:
K = 100;
U = zeros (K, 2*K+1);
V = zeros (2*K+1, 1);
for k = 1:K
for j = k+1:k+K
U(k, j) = z(K+k+1-j);
endfor
endfor
You easily remove the inner loop like this:
for k = 1:K
U(k,k+1:k+K) = z(K:-1:1)
endfor
I see no way of vectorising this one, but maybe others will.
--
Francesco Potortì (ricercatore) Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR Fax: +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa Email: address@hidden
(entrance 20, 1st floor, room C71) Web: http://fly.isti.cnr.it/