> dpb <firstname.lastname@example.org> wrote in message <email@example.com>... >> 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 <firstname.lastname@example.org> wrote in message <email@example.com>... >> 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. ...
Yes, but you didn't define n so I presumed there was a typo and since you computed both a nPlusOne and a nMinusOne vector that the other vector was intended to be nMinusOne. If it's just 1:n then you don't need a subscript and :,n would reference one column (the nth one) unless n=[1:size(U,2)]
I haven't compared for relative speed but U(:,nPlusOne)-U is identical to circshift(U,[0 1])-U
Well, looking I see that circshift is an m-file so probably the special-case precomputed indices will outperform the packaged more general function.
diff() will take care of the subtraction as well unless you're sure you do want the difference array to be the same size--I was just checking that you think the wrapped position really does have meaning...if that's what you want, go for it.