Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
Hello everyone. I wonder how to have a sin function with 3 cycles (or more) that each cycle of it has different number of iterations. For example, I want iteration steps to be 1 in the first cycle and decrease to 0.5 in the second and third cycles (without decreasing or increasing the number of cycles).
Physical Mathematics
Solved! Go to Solution.
Try a function like this:
Where the third argument (PointsPerCycle) can be a scalar or an array, that determines the number of points per cycle.
Here you see it called in both modes:
And the resulting plots are:
As you can see for the first cycle (15 points per cycle) the two point sets coincide.
For the second cycle there are more boxes than x-es, in the third and following cycles there are twice as many boxes as there are x-es.
Success!
Luc
Try a function like this:
Where the third argument (PointsPerCycle) can be a scalar or an array, that determines the number of points per cycle.
Here you see it called in both modes:
And the resulting plots are:
As you can see for the first cycle (15 points per cycle) the two point sets coincide.
For the second cycle there are more boxes than x-es, in the third and following cycles there are twice as many boxes as there are x-es.
Success!
Luc
That is exactly what I am looking for. Thank you so much @LucMeekes for that. I just don't understand some part of it, especially the first line. Actually, I have never used "not boolean operator". Beside that, you are using an "if" statement without using an "otherwise" part for that. Also, what is the role of setting "Origin" to "r" in the middle of the function? Would you be so kind to briefly explain these? Best,
The first line just asks if the parameter PointsPerCycle is an array (a vector) rather than a scalar. IF that is not the case, the statements of the body of the IF-statment are executed. This is a simple case with a constant number of points per cycle, for each cycle the same value. At the end of the IF, the resulting matrix with the x- and y-data is returned by the function. The function ends here.
IF PointsPerCycle is an array, the body of the IF statement is not executed, but execution continues after the IF statement with the first assignment to r (which is used as the index to the matrix R) I preset it to ORIGIN. ORIGIN is a worksheet variable that points to the first element of an array (or first row and first column of a matrix). ORIGIN is usually set to 0, but you can set it to other values, the most common of which is 1. I want my functions to operate with any valye of ORIGIN (= be independent of the actual value of ORIGIN), hence I use its value, rather than assuming the user will have set it to 0...
I don't need an OTHERWISE for the IF because when the IF test is TRUE, the function returns R as part of the last statement in the IF body. I could use it, and it is 'better programming practice'. It would mean that all statements from r<- ORIGIN to the end would move to the body of the OTHERWISE.
But I usually choose to end the function when it's done, using the RETURN statement.
Success!
Luc
Thank you @LucMeekes for your thorough explanation. That was interesting and helped me a lot. Best,