Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
Hello,
Considering the following function:
How to find:
on the interval of x:
Mathcad Prime 8 file attached.
Thank you.
Solved! Go to Solution.
You could do as Luc suggested, but the symbolic engine (or its interface) is not capable enough to give you all needed solutions. "assume" and "fully" are ignored and just one solution is returned.
It should work that way, but only does for simpler functions where Primes symbolic has not to switch to its float mode.
EDIT: It works for simpler functions, but we should omit "fully"!
So in your case you may resort to numeric methods like the "root" function:
You may also try a utility function like the one below, but it sure won't work for all type of functions.
To distinguish between maxima and minima, the second derivative can be used:
Attached file is in P9 format
Take the derivative of f to x, f'(x). Solve f'(x)=0. That should give you (at least) 4 roots. Calculate f(x) for each of these roots and determine from their values which one is global or local, max or min.
Success!
Luc
So, only one root the derivative of f(x) wants to give to us (at least in Mathcad Prime (8)).
You could do as Luc suggested, but the symbolic engine (or its interface) is not capable enough to give you all needed solutions. "assume" and "fully" are ignored and just one solution is returned.
It should work that way, but only does for simpler functions where Primes symbolic has not to switch to its float mode.
EDIT: It works for simpler functions, but we should omit "fully"!
So in your case you may resort to numeric methods like the "root" function:
You may also try a utility function like the one below, but it sure won't work for all type of functions.
To distinguish between maxima and minima, the second derivative can be used:
Attached file is in P9 format
I thought about root, but in the root it must be specified an initial guess of each individual root. And this it is something like that per guess. Now, of course, with the graph in front of our eyes the things are much easier to guess each initial guess root. I do not like pretty much this variant with guessing the solutions...
I know that in Mathcad15 there is a function by which the solution is found by giving an interval. Is it possible something like that also in Mathcad Prime?
@Cornel wrote:
I thought about root, but in the root it must be specified an initial guess of each individual root. And this it is something like that per guess. Now, of course, with the graph in front of our eyes the things are much easier to guess each initial guess root. I do not like pretty much this variant with guessing the solutions...
That exactly was the reason why I quickly wrote the utility function "Extrema()". Look it up in my answer above. You specify the function and the interval and it returns the extrema. Its a function which sure would require some additional work to deal with the situation when one of the x-values used by chance IS exactly an extreme position or to deal with discontinuities, etc. But the function provided could be a starting point for your own attempts.
I know that in Mathcad15 there is a function by which the solution is found by giving an interval.
I don't know what you are talking about!? Are you talking of a built-in function? Which one?
Maybe you confuse it with "localmin()" and "localmax()". These functions are still available in Prime, too, but they don't work for functions but rather only for sampled data vectors, as ttokoro already has shown, and they also have their own numeric limitations.
I know that in the past questions about finding all zeros of a function in a given interval came up here in the forum quite often and me an others may have provided some kind of utility functions, don't remember. They sure all had their limits and drawbacks, though. You may search the forum, maybe you can find something you like.
In Mathcad 15: root(f(x)/function, x/variable, a,b), a and b are the range of the interval (like a=-6 and b=7 in the above example). Isn't it like that?
And can you also attach your variant in Mathcad Prime 8 file?
@Cornel wrote:
In Mathcad 15: root(f(x)/function, x/variable, a,b), a and b are the range of the interval (like a=-6 and b=7 in the above example). Isn't it like that?
???
Look again to what I have posted! Thats exactly the way I had used the "root" function. It works the same in Prime as in real Mathcad. "root" will always give you just one return value, it never returned all roots in a given interval, but in can be used in a program which tries to collect all roots, like I did in the "Extrema()" function.
And can you also attach your variant in Mathcad Prime 8 file?
No, sorry. I can't back convert Prime 9 files. Thank you, PTC.
Thats the reason for all the pictures. Shouldn't be that difficult to retype.
@Werner_E wrote:
@Cornel wrote:
In Mathcad 15: root(f(x)/function, x/variable, a,b), a and b are the range of the interval (like a=-6 and b=7 in the above example). Isn't it like that?
???
Look again to what I have posted! Thats exactly the way I had used the "root" function. It works the same in Prime as in real Mathcad. "root" will always give you just one return value, it never returned all roots in a given interval, but in can be used in a program which tries to collect all roots, like I did in the "Extrema()" function.
Ok. Now I understand what you are trying to say to me. Thank you.
I remember that in an older thread I provided a function similar to the aforementioned "Extrema" which found all zeros in a given interval and used the "root" function not by providing a range, but rather by providing a guess value. I divided the interval in many parts (similar to what i did in "Extrema") and used all values as guesses to let root find a solution and collected all in a vector. Afterwards it was necessary to clean up and remove all the duplicate values which were found and also the values aoutside of the given interval. Maybe this was ls elegant but I guess it was a more robust approach. Could not find the thread now, though.
And these are the manual calculations (only for (at least my) understanding):
What does trim and match (and also NaN) functions do? What are their purposes? When do we must use trim, match and NaN functions?
@Cornel wrote:
And these are the manual calculations (only for understanding):
Yes, that method was used by me in the first approach shown. I just put the interval limits in vectors and calculated all values in one go using vectorization.
What does trim and match (and also NaN) functions do? What are their purposes?
When do we must use trim, match and NaN functions?
Whats wrong with looking them up in the help?
The get the maxima I used f2(X)<0 to create a vector with 1 at the position where the second derivative at X is negative and 0 otherwise. Then I used "match" to find the indices of zeros and used "trim" to delete the X-values at these positions. What then remains are the maxima.
Similar approach for the minima.
@Werner_E wrote:
What does trim and match (and also NaN) functions do? What are their purposes?
When do we must use trim, match and NaN functions?
Whats wrong with looking them up in the help?
The get the maxima I used f2(X)<0 to create a vector with 1 at the position where the second derivative at X is negative and 0 otherwise. Then I used "match" to find the indices of zeros and used "trim" to delete the X-values at these positions. What then remains are the maxima.
Similar approach for the minima.
Ok. Thank you.
Can you attache also the Mathcad Prime 8 file?
Now I am using Prime 9. Copy and Paste can do from Prime 9 to 8, only one equation each time.
Plot and programming are also one item for Copy and Paste to lower version.
How to find the maximum point: (x1, f(x1)) in the phase-frequency bode plot for G(s) function from below...?
Mathcad Prime 8 file attached.
How about just to use the derivative of the very function you would like to see the max of?
You may also use the "maximize" function to do the job, but I guess that its necessary to define an auxiliary function
I used ff as free variable so to not interfere with the vector f you defined.
Thank you very much, Werner_E and LucMeekes.
Success!
Luc