help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Iterative summation using sum(), fails with ezmesh


From: Erik Leunissen
Subject: Re: Iterative summation using sum(), fails with ezmesh
Date: Fri, 11 Apr 2014 10:28:42 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0

On 04/11/2014 04:16 AM, Jordi Gutiérrez Hermoso wrote:
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


Aha, OK.

Thanks very much,

Erik Leunissen.

HTH,
- Jordi G. H.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]