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 ]
Jeff

Posts: 113
Registered: 11/22/09
Re: Can my code be made more efficient using MATLAB's vectorization?
Posted: Feb 16, 2013 5:51 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi. Slow response because I forgot to add the thread to my watchlist. But thanks for helping.

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message
>
> P_f = bsxfun(@times, W.^2, evals/(-N));
>


Thanks Bruno. Despite my sloppy code, I think you gave me what I need: bsxfun.


dpb <none@non.net> wrote in message <kfjhkn$8ea$1@speranza.aioe.org>...
> 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?


dpb:
a) That is not what was intended. The fixed boundary code is not complete (hopefully this is the "untested code" Bruno was referring too) and should not have been included. Eventually, the fixed code will look something like

P_p = ([U(:,nPlusOne); 0]-U(:,n)).^2;

except that 0 will really have to be something like zeros(T,1). I'm working on the periodic code first and will come back to that.

dpb <none@non.net> wrote in message <kfjhkn$8ea$1@speranza.aioe.org>...
> 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
>


b) Are you talking about the code for P_p? I am subtracting the n columns from the n+1 columns (that is, u(n+1) minus u(n)). I think you read my code as u(n+1) minus u(n). I hope so, anyway. Because if you read my code right and you think it is doing u(n+1) minus u(n-1), then in trouble!

I think my code already does what circshift does, at least for the periodic case. diff seems to be more for taking derivatives, so I don't think it will help.


Sorry to all who read this for the sloppy code. I'm learning the math and matlab coding at the same time.



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.