If you're not concerned about performing unneeded calls to u2_0 you can get 
away with (x.>Lbox/2) .* (0.5*(u2_0(x)+u2_0(Lbox-x))-u2_
0(Lbox/2))


Den onsdag 10 februari 2016 kl. 11:58:58 UTC+1 skrev Ferran Mazzanti:
>
> Hi folks,
>
> probably a stupid question but can't find the answer, so please help if 
> you can :)
> I would like to evaluate a if.. else.. statement on a whole array. 
> Actually it's a bit more complicated, as I have a function that
> previously was
>
> function u2(x)
>     return 0.5*(u2_0(x)+u2_0(Lbox-x))-u2_0(Lbox/2)
> end;
>
> for some other defined function u2(x) and constant L_box. The thing is 
> that I could directly evaluate that on a scalar x and on an array.
> Now I have to change it and check if x is smaller than Lbox/2, returning 
> the same as above if it is, or 0 otherwise.
> I tried something of the form 
>
> function u2(x)
>     return x.>Lbox/2 ? 0 : 0.5*(u2_0(x)+u2_0(Lbox-x))-u2_0(Lbox/2)
> end;
>
> but that complains when x is an array. What would be the easiest way to 
> achieve this? It should work for both scalars and arrays...
>
> Best regards and thanks,
>
> Ferran.
>
>

Reply via email to