Skip to main content
1-Visitor
August 1, 2016
Solved

A question about return a value based on a preset criteria

  • August 1, 2016
  • 26 replies
  • 8280 views

Hi All, I have a question about judging a value to meet specific criteria, would anyone advise how to implement it? I attached the example in this thread.

In this worksheet, we have the radio button to choose an X value. Y is defined as a function of X. We want to search the proper X, by which the  obtained Y value will be closest (but smaller than) 200. How can we implement this and let MathCAD return the proper X value?

return a value.JPG

Thank you!

Best answer by Werner_E

Similar answer as I gave yesterday:

Another way would be to calculate the exact value of x and then search for the closest value in the vector X which still is smaller

26 replies

1-Visitor
August 1, 2016

I assume the example shown is a simplification.  If not, a simple formula using Floor and max should work.

For a more complicated situation, you may want to use Mathcad's programming to cycle through your list of X's to find the closest value.

yhuang-31-VisitorAuthor
1-Visitor
August 1, 2016

Hi Mark, yes the example is a simplified one. Would you teach me how to (1) find the closest and smaller value (2) return the proper X?

1-Visitor
August 1, 2016

I'm sure there's a more elegant way, but this should do:

23-Emerald I
August 1, 2016

You can use a solve block:

1-Visitor
August 1, 2016

For the example given, yes.  Depending on the actual function Y(x), not necessarily.  If the function is not continuously increasing, then this may not produce the correct answer.

25-Diamond I
August 1, 2016
yhuang-31-VisitorAuthor
1-Visitor
August 1, 2016

Thank you Werner, are you able to help me regarding the complicated Y(X) function I posted in this thread at 2:32 PM?

25-Diamond I
August 1, 2016

Its not clear to me, what you are trying to achieve.

f1 should be a vector, not a range.

Furthermore match will not only give you an exact match but will also give you matches which are close concerning a certain tolerance.

As far as I see the min  is always found at index 0 and match will give you a vector consisting of 0, 1 and 2. Whats the reason for taking the absolute value (length) of that vector of indices?