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