Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Can my code be made more efficient using MATLAB's vectorization?
Replies: 4   Last Post: Feb 16, 2013 6:55 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
dpb

Posts: 8,152
Registered: 6/7/07
Re: Can my code be made more efficient using MATLAB's vectorization?
Posted: Feb 14, 2013 3:32 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 2/14/2013 11:49 AM, Jeff wrote:
> Is there a better, more MATLAB-y way, to write this code (that is,
> using vectors)? Eventually, this will be used for large amounts of
> data (from a program running on a cluster), so I need it as efficient
> as possible.
>
> U and W are T rows x N columns matrices. Variable evals is a 1 by N
> matrix of the eigenvalues (of some other matrix which doesn't matter
> for this post). For now, the largest value of T is about 1000, but
> eventually it will be many thousands (maybe even millions).
>
> So the first thing I need to do (variable P_p) is subtract the each
> entry on the row from the one to its right (for now, I only have
> periodic conditions coded). I think I have that variable coded fairly
> efficiently (yes? no?).
>
> if strcmp(boundary,'periodic')
> nMinusOne=[N 1:N-1];
> nPlusOne=[2:N 1];
> elseif strcmp(boundary,'fixed')
> nMinusOne=[1:N-1];
> nPlusOne=[2:N];
> end


...

First, a couple of questions...

a) The periodic solution as written will be N columns whereas the fixed
will be N-1. Is this intended/desired?

b) As written the difference between n+ - n- of the array for periodic
will be that of column n minus n-2 rather than the "one on its right"
which implies a first difference. To illustrate if N were 5, say, the
two column vectors you generate are

[5 1 2 3 4]
[2 3 4 5 1]

which results in deltas of 2-5, 3-1, 4-2, etc., ... Is this intended or
did you intend

[5 1 2 3 4]
[1 2 3 4 5]

instead?

W/ those answers, then can progress to next step (altho I'll note you
may find

doc diff
doc circshift

of interest)...

--




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.