Quantcast
Viewing all articles
Browse latest Browse all 11560

Re: Vectors and proraming in a fuction

Richard, I don't particularly want to compare a scalar to a vector. I would like to have a function result that is a vector, who's result depends on the comparison on of each value in the vector.

Basically, what I want is :

f(x)_1 = if(x<y1) (k1 * x) else (2* k1*x)

f(x)_2 = if(x<y2) (k2 * x) else (2* k2*x)

 

This is what Werner's example does (thank you very much !). I didn't know about the vectorization tool, and it seems to do the trick. I am just a bit puzzled why I can't apply it with k and y being global variables rather than function parameters.

 

I find it also quite strange that, outside of a function, operations involving scalars and vectors seem to "just work". y-3 or y>3 the expected answer, with operations applied element-wise. What is different in this example ? Is it the programing functions who don't like vector results ?


Viewing all articles
Browse latest Browse all 11560

Trending Articles