On Thu, 2014-04-10 at 22:54 +0200, Erik Leunissen wrote:
4
__
C(x,t) = 2*x* \ - exp(x+(i-0.5))^2
/ -----------------
-- t
i=-4
Of course I'd prefer a vectorized way,
I assume the negative goes inside the exp, not outside, as that is
what you had in your code earlier.
That being said, I can see a couple of ways. I have not timed either
of them. Take your pick. There's a very straightforward way with
arrayfun and a less transparent way using permute and exploiting
broadcasting:
function z = C (xx, tt)
z = arrayfun ( @(x, t) 2*x*sum (exp ( -(x + (-4:4) - 0.5).^2))/t,
xx, tt)
z = 2*xx.*sum (exp ( -(xx + permute (-4:4, [1,3,2]) - 0.5).^2), 3)./tt
endfunction