Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.


Math Forum
»
Discussions
»
Software
»
comp.softsys.matlab
Notice: We are no longer accepting new posts, but the forums will continue to be readable.
Topic:
Can my code be made more efficient using MATLAB's vectorization?
Replies:
4
Last Post:
Feb 16, 2013 6:55 PM



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


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 N1. 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 n2 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(n1), 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.



