Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
So a few days ago i made a post of my graphs not working.
Back then i asked 3 teachers to look at it but they all couldn't solve it. Luckly the ptc community could.
But now i need to present the solution and i want to add fancy things so it looks more complex then it is.
For example first check of something is a range but somehow my second value wont work for it.
Any other idea's to make it look more complicated?
Probeer eens
dus zonder
Succes!
Luc
Dag Luc,
Dan zegt het 0, dit betekend volgens mij dat het geen range is. kan ik dan op een manier zien wat het wel is?
Prime alerts you that you are misusing a range, using it for something it is not intended for.
A range is not a collection of values like a vector (even though Prime unfortunately displays them the same way). A range rather is an instruction, kind of an implicit loop.
A range can/should be used for
1) indexing the elements of vectors and matrices
2) creating a for-loop in a program
3) making plots
So using a range as a function argument is perfectly OK when creating a plot
and Prime even is willing to display the values calculated (which may be misleading...)
but what this function call actually creates is not a valid data structure recognized and accepted by Prime.
You experienced this when you tried to use "IsRange" and you get the very same error message if you simply try to assign it to a variable
The right hand side simply is treated as an invalid data structure to Prime which it refuses to use - its not a scalar, not a vector and also not a range.
And IsRange(ϕ) sure must return 0 because its not a range but rather a function
So use ranges just for what they are intended for and vectors for the rest. And no, you are by no means the first person to stumble over this difference between ranges and vectors, and you certainly won't be the last. I guess it's happened to all of us at some point, and it's an age-old pitfall.
So to create something like a table of values you should use vectors.
Starting with Prime 11 we have a convenient function "vec" to do so.
The three function arguments are the same as you used for creating the range.
One word of caution because you named the second value θ.1stap. In a range definition and also in "vec" this second value is NOT the desired step width, but rather the second value in the list created. Its identical with the step width only if the first value is zero!
"vec" creates a true vector (or more general a matrix or an array)
Now you an use this vector as argument of your function
and the result is a valid data structure, a vector (matrix, array)
One word of caution: You should vectorize the function call whenever you use a vector as argument of a function which is written for scalar arguments. Its not necessary in case of your function, however, it is best to get into the habit of always vectorizing in such cases, as this saves you from having to check whether it is necessary in each specific case.
An example: The three functions f1, f2 and f3 seem to be identical, doing the very same
But when you provide a vector of values as function argument, you see differences
Reason is that in f2 and f3 the first multiplication is done with two vectors now and Prime of course has to use vector multiplication (dot product, scalar product) here.
So I got into the habit of applying always vectorization when I feed a vector into a scalar function, not having to think about if it would be really necessary or not:
In your sheet you could now create tables or whatever you had in mind
You may also consider using a range phi with a smaller step width to make for smoother plots and a vector phi with less values for the tables. And you don't have to define that range/vector right on top of the sheet as you had done, but rather right in front of its first use (plot, table, ...)
And of course you could also use vectors for plotting even though ranges are made for it and may feel more natural to be used in plots.
