Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X
Hello ptc community
I have tried to find the maximum value of a function evaluated in a defined range, however the max or min function can only be applied to vectors. I would like to know if there is a function or some way that allows me to obtain the maximum value of a function. I try to vectorize the results as attached in the example, however this is limited to functions lacking units as far as I could see. I would appreciate any help
This is the function that I have been working on, it is only referential but with this I wanted to imply that I prefer to use units during the calculation. (for more details see the attached sheet)
here I show how it is possible to vectorize a function already evaluated in a defined range
but the above is not possible if units are used
Solved! Go to Solution.
You cannot use a range with a unit assigned as an index to a vector. (Ranges are for plotting and indexing!) But you can create a vector that mimics the same range with your units:
May by so
well it seems that it was something simple xD, thanks
But since we are here, I would like to know that it takes into account the maximize function, although the first requirement argument is the function, the second argument is a value that remains to be defined by the user that will give me a local maximum of the evaluated function. In the case of evaluating M_k with a parameter between 0 and 10, it gives me a value of 3 that corresponds to the maximum value of the function between that range, but if I wanted the second value that corresponds to 4.
Now if I assign a value between 11 and 20 as a parameter, it should give me 21, which corresponds to the maximum value, however, sometimes it gives me 19.5, sometimes 19. Why is this? Although this is a problem of maximums and minimums in a function, I am not allowed to apply derivatives since the function is generated from conditionals.
thanks for your answer, It seems to me a good alternative way to evaluate the maximum values, but I would like to know why the values of the maximize function varied and did not coincide in an answer
it tells me that a conditional expression cannot be evaluated 😞
You cannot use a range with a unit assigned as an index to a vector. (Ranges are for plotting and indexing!) But you can create a vector that mimics the same range with your units:
Yes, that was my mistake, I was using a range with a unit assigned as the index of a vector, which is meaningless, I didn't understand how this type of vectorization worked. I already understood it, thank you very much. Now I only have the doubt of why the maximize function gave those results.
Looks like you found a bug in Prime 5 which is already fixed in Prime 6:
Here is another (clumsy and sure not satisfactory) workaround for this Prime bug using the built-in "localmax" function:
Thanks for your answer, it is true there are some errors that the new version has fixed, I was also testing and now it allows me to vectorize the function with a small program evaluating the function in a certain domain and grouping the answers in a vector, this I could not do it in the older version.
Regarding the solution that you propose for maximums and minimums, the localmax function does not seem awkward to me, it is the one required to find not only a maximum point of a range. Thank you