Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
As the picture above, I want to get the max value for the function K,under a certain condition, but the max() return the value like a matrix,so how can I get the right value?
Solved! Go to Solution.
Ahh! So far I had overlooked that you just used the first value of vector Q when you tried to apply the "max" function, not the full vector.
So you are only interested in the maximum value of K for m=6 and Q=0.2.
This can be done the way you had tried. Just 2 corrections:
1) You have to define F as a vector, not a range
2) You must apply vectorization (the arrow over the expression)
actually just the function call of K must be vectorized
This gives you the max value of K, but does not reveal the corresponding F-value.
You could use the "match" function to get the index of the max values and calculate the F-value from this:
As already written in a previous answer you could also use the derivative to get F a bit more accurate.
BTW, in case you are not using Prime 11, the "vec" function is not available. But its easy to create your own "vec" function:
Problem is that F is not a vector but rather a range variable.
So you want m to be constant 6 and find the maximum of the 59406 values you get when you combine any of the 6 Q-values with any of the 9901 F-values?
First you have to define F as a vector. If you are using Prime 11 you can use the new function "vec" -> Fx:=vec(0.1, 0.101, 10)
Then you have to create a matrix (6 x 9901) with all the values. You may either use a small program with two nested for loops or use two range variables to index the elements. The last step is to use the "max" function to find the maximum of all the values in the matrix.
Of course you would get a different result as I did not bother to use your function and your values in the vectors.
Another option would be to do without the "max" function but simply looping through all the values and keeping the largest one so far:
For future questions keep in mind that you always should attach the worksheet itself, not just a picture and that you should say which version of Prime you are using.
Hi,thanks a lot!
okay! I will remember that when asking for help, it's better to attach the worksheet.
By the way, I have found that in order to get XY plot , I need to define the Fx as a range variable (And I am using Prime-11). But the max() is working need to define the Fx as a vector.
My early idea is to get the max value to draw the line like this picture.
And the final result is to get like this picture, to differentiate the areas between left and right
@GT_13604326 wrote:
Hi,thanks a lot!
okay! I will remember that when asking for help, it's better to attach the worksheet.
By the way, I have found that in order to get XY plot , I need to define the Fx as a range variable (And I am using Prime-11). But the max() is working need to define the Fx as a vector.
Yes, usually you would use a range variable to plot a function, but you can also use a vector.
But if you use a vector at the x-axis, you also have to use a vector at the y-axis. So to use a vector Fx for the plot, you would have to vectorize the function calls at the y-axis.
A range is kind of an implicit loop, not a data structure. So when you call "max" with Fx being a vector, Prime loops through Fx and applies the max function at each loop. So each turn juts one value is feeded in the K function and max returns the maximum of the result (whoch is just one value as well). All these results are then presented in a way which looks like a vector, but isn't.
Actually the very same result would be to expected when I accidentally vectorized the whole max(K(...)) function call and not just the K(....) inside of the max function. Fortunately "max" is a function which can't be vectorized and so this faux pas had no negative effect 😉
In the attached sheet I vectorized already the function definition of K, that way I don't have to use vectorization whenever K is called with a vector F as argument. I thought that the vectorization arrows look too ugly in the plot.
EDIT: On the other hand there is no need for F to be a vector anymore because I am using the derivative and the "root" function to determine the peaks. So you could also define F as a range used just for plotting and don't need to vectorize the definition of K.
Furthermore I use a function to determine the F-value of the maximum. I am not using the brute force way (creating a vector of values and choosing the largest value) but rather let the "root" function determine the zero of the derivative. That way its easy to plot the brown locus of the peaks.
Wow! Thanks again!
Finally, I got it!And I have learned a lot!
In the end, Best wishes!😁
And here is the version with a range F instead of a vector and without having to vectorize the definition of function K.
Vectorization (over vector Q) is only necessary for the matrix of the peak values.
Hmm. It's worth drawing a graph first:
(I've just set m to the constant value of 6, and not included it as an input variable below)
EDIT
When F = sqrt(1/6), Q=0, then K = 8.333333340*10^8
You are right - the value you found is not the max, When you set Q=0 as you did, we have a singularity at F=1/sqrt(6), So the "max" here is infinity 😉
But we don't know what @GT_13604326 means when he writes "under a certain condition".
Maybe he is only interested in the six Q values (0.2 to 5) and 9901 F values (0.1 to 10) he provided. So maybe Q never should drop beneath 0.2.
In this case the maximum is 2.522 for Q=0.2 and F=0.426. This max value could be increase by about 10^-5 if F is allowed to be set at 0.42576594386598241263.
For a value of Q>0 we can use the derivative wrt to F to find the max position.
@Werner_E wrote:
We don't know what @GT_13604326 means when he writes "under a certain condition".
Very true.
Thanks for reply!
Ahh! So far I had overlooked that you just used the first value of vector Q when you tried to apply the "max" function, not the full vector.
So you are only interested in the maximum value of K for m=6 and Q=0.2.
This can be done the way you had tried. Just 2 corrections:
1) You have to define F as a vector, not a range
2) You must apply vectorization (the arrow over the expression)
actually just the function call of K must be vectorized
This gives you the max value of K, but does not reveal the corresponding F-value.
You could use the "match" function to get the index of the max values and calculate the F-value from this:
As already written in a previous answer you could also use the derivative to get F a bit more accurate.
BTW, in case you are not using Prime 11, the "vec" function is not available. But its easy to create your own "vec" function: