Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
Why not simply
The problem in fact is not the function but its argument. i is a range and a range is NOT a vector but rather some sort of implicit loop. So f(i) is neither a range nor a vector - its kind of an invalid object suitable only for display. You can see this if you try to assign f(i) a variable:
But what you did works OK if you turn "i" into a true vector. The simplest way to do so is by using an immediate inline evaluation after the definition:
But that method of turning a range into a vector is undocumented and so is subject to be changed without notice.
So a more "legal" way could be this
Note that I use vectorization when I call f(v).
You will see why when you change the x^2 to x*x in the function definition and don't use vectorization 🙂
BTW, ranges should only be used on three occasions:
1) to index vectors and matrices
2) to provide a range of values for the abscissa in a 2D plot
3) in a program when you use a for-loop
Nothing else!
I just figured it out. I had to create a new function that returned an array. A bit uglier now in my opinion. I mean the original function returned the same matrix and values (see below) but does not work? Silly IMHO
Why not simply
The problem in fact is not the function but its argument. i is a range and a range is NOT a vector but rather some sort of implicit loop. So f(i) is neither a range nor a vector - its kind of an invalid object suitable only for display. You can see this if you try to assign f(i) a variable:
But what you did works OK if you turn "i" into a true vector. The simplest way to do so is by using an immediate inline evaluation after the definition:
But that method of turning a range into a vector is undocumented and so is subject to be changed without notice.
So a more "legal" way could be this
Note that I use vectorization when I call f(v).
You will see why when you change the x^2 to x*x in the function definition and don't use vectorization 🙂
BTW, ranges should only be used on three occasions:
1) to index vectors and matrices
2) to provide a range of values for the abscissa in a 2D plot
3) in a program when you use a for-loop
Nothing else!
Fantastic! Thank you!! That's much better 😄