Skip to main content
1-Visitor
August 13, 2019
Solved

Finding which combination of values gives the highest/lowest result

  • August 13, 2019
  • 1 reply
  • 3004 views

I've been scouring the forums for a while now and I'm starting to come to the conclusion that either my question is so simple that nobody else needs to ask how to do it or that it just can't be done. Put simply, I'm trying to find out how I can get MathCAD (using Prime 4.0) to return the highest or lowest result of a function given a list of possible input variables.

For example, if I have a simple function:

f(x,y) = x + y^2

and a list of possible values for x and y:

x = [3, -6, 2]
y = [2, 3, -3]

How can I get MathCAD to output the largest (11) or smallest (-2) result?

Best answer by Werner_E

Here are a few ways to do it

B1.png

But I would prefer to write a utility function to do the job

B2.png

Sometimes it may be a problem to have the function create the full matrix, so a different, a little bit more lengthy approach would do the same job:

B3.png

Worksheet in format P4 attached

 

EDIT: I just remembered that there was a similar, but more coomplicated/demanding question here in this thread

https://community.ptc.com/t5/PTC-Mathcad/Electronic-boards-design-assessment-of-the-component-tolerances/m-p/62873/highlight/true#M24885

There you can find a minmax function which will work with function with more than just two arguments. Not sure which version the file attached there is, but I guess the thread is old enough so the file should open with P4.

1 reply

Werner_E25-Diamond IAnswer
25-Diamond I
August 13, 2019

Here are a few ways to do it

B1.png

But I would prefer to write a utility function to do the job

B2.png

Sometimes it may be a problem to have the function create the full matrix, so a different, a little bit more lengthy approach would do the same job:

B3.png

Worksheet in format P4 attached

 

EDIT: I just remembered that there was a similar, but more coomplicated/demanding question here in this thread

https://community.ptc.com/t5/PTC-Mathcad/Electronic-boards-design-assessment-of-the-component-tolerances/m-p/62873/highlight/true#M24885

There you can find a minmax function which will work with function with more than just two arguments. Not sure which version the file attached there is, but I guess the thread is old enough so the file should open with P4.

spost11-VisitorAuthor
1-Visitor
August 14, 2019

That is probably the most thorough and well-documented answer I've ever received! Thank you so much!