Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
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?
Thank you!
Solved! Go to Solution.
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
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.
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?
I'm sure there's a more elegant way, but this should do:
Hi Mark, this helps a lot. Currently, the problem comes from the description of Y(X), when using your code. If I have the same X array, but a complicated Y(X), which involves the matrix calculation. Would you teach me how to map each component in X to Y properly? I attached my worksheet. Thank you!
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.
Thank you Werner, are you able to help me regarding the complicated Y(X) function I posted in this thread at 2:32 PM?
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?
Sorry for the confusion. Yes f1 is a vector, not a range, and I am not looking for a perfect match.
This is what I am trying to achieve:
(1) X has four numbers, we can call them x1,x2,x3,x4
(2) for each number in X, we can have an array called Middle1
(3) using the match and min function, we can get a number Middle2 for a specific X
(4) I want to calculate f(Middle2) to return a number
(5) If we define Y as a 4X1 array as well (Y=(y1,y2,y3,y4)^T), y1 will be calculated from x1, and so do y2,y3 and y4.
(6) go back to the question in this thread, I want to evaluate y1 to y4 to see which one is closest to but small than 200. For example, y3 is this number.
(7) then the conclusion is, x3 is the number we want to find out from X array, because the y value calculated from this x3 can meet our creteria.
Thank you!
>> (2) for each number in X, we can have an array called Middle1
I see in your file how you would like to calculate that "middle1"
This should work that way
>> (3) using the match and min function, we can get a number Middle2 for a specific X
As I have already written, the match function unfortunately only works within a certain tolereance. You will not get just one value, but a vector of three in your case.
And I already asked WHY the absolute value of that vector?
>> (4) I want to calculate f(Middle2) to return a number
WHICH number??
Maybe its better to just use the first index in the vector ?
>> (5) If we define Y as a 4X1 array as well (Y=(y1,y2,y3,y4)^T), y1 will be calculated from x1, and so do y2,y3 and y4.
The array is not defined, its caluclated.
>> (6) go back to the question in this thread, I want to evaluate y1 to y4 to see which one is closest to but small than 200. For example, y3 is this number.
All are equal to 10 !!!!!?????
>> (7) then the conclusion is, x3 is the number we want to find out from X array, because the y value calculated from this x3 can meet our creteria.
Are you sure? Why?
I don't think I understand what you're trying to do. Is this anywhere close?
Hi Mark, your answer is very close to what I want. But there is an additional problem for me to solve my problem. Sorry for the confusion. I expanded my case in more details and attached the worksheet. The target is to find the cutoff frequency of the s-domain transfer function for each component in X, and return the proper component that can give us the maximum allowed cutoff frequency.
Thank you!
For this example, can you please clarify what you want the output/answer to be?
From the observation, when X=30, the cutoff frequency is closest to 50, but it is already greater than that. So the correct answer should be X=20. However, I do not require a very high precision. Thank you!
So you are not trying to limit Y, you are trying to limit f?
Like this?
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
Hi Werner, I am more and more close to solving the problem with the help from you and Mark. By using your method, I got a problem in Match function. I am using Mathcad 14, and it shows Match() is not defined. This is a snapshot of the worksheet you provided yesterday. I tried to match() function here, but it can only accept two inputs inside the parentheses. So match() and Match() are not same from my PC. Would you tell me how I can solve this?
The functions "Match" and "match" are different. As you noted, Match takes 3 inputs, and match takes 2. Maybe "Match" was new in version 15. Go to Insert, Function, and look for "Match" there (I can only seem to find it under the category "All").
"Match" is from the Data Analysis Extension Pack.
Hi Richard, does that mean I need to purchase the additional pack? If not, how can I install Data Analysis Extension Pack?
It's usually installed automatically with Mathcad 15. Maybe that's only for certain licenses though. You should check with PTC
As far as I recall the four extensions packs used to be part of most Mathcad distributions but was missing for some educational licenses. I think that the extensions packs are installed with every installation and you will see the accompanying E-Books in "Help"-"E-Books". But its the license file which decides if you should be able to use those extra functions.
I don't think that is possible to buy them nowadays and the features of those extension packs are now part of the regular Mathcad Prime.
The "Extension Pack's" for the program began to be delivered starting with Mathcad 12 version. For their work need a separate license option "Mathcad Add-On Collection" in the license file.
As Richard already stated - the Match, VLookup, etc. function are part of one of four so called Extrension Packs which usually were distributed along with Mathcad. As far as I remember this was the only difference to (at least some) educational licenses which were missing those packs.
Here are three variants which do not utilize those packs:
Some built-in function from "Data Analysis Extension Pack" as Mathcad programs can be found in attachment.