cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Logic based results

sshastry
6-Contributor

Logic based results

Hi

I'm a novice with Mathcad. Attached is a Mathcad file Ive been working on. If you scroll to the end of the file you will notice that there is ratio called Mp/Mn. I want to program this in such a way that "If Mp/Mn is greater than or equal to 0.3 then the result should be OK. If it is less than 0.3 the result should be reported as "FAIL". How do I have program this. Kindly advice.

Regards

Sriprakash

20 REPLIES 20

May be so

sshastry
6-Contributor
(To:ValeryOchkov)

Hi

Thanks for your response. But how do you create this in the first place. Where do you get the "if"parameter from. Is it from the math tab > programming. I'm unable to figure out how to do this. Besides I don't want it to be visible as part of the calculation that everyone can see. It should be hidden. How do I achieve this. I would be great if you can explain this on my mcdx file.

Thanks

Sriprakash

You can just type the "if" condition together with the brackets from the keyboard. To hide the condition, use the pre-inserted Area block, and then close it (in Prime 4.0 you can set a password on this Area block).

Pic_1.png

sshastry
6-Contributor
(To:VladimirN)

Thanks Vladimir for the response. The issue is that if the variable is "a" or "b" then there is no issue, but if the variable is "Mn/Mp" the program does not let me use the comma. Please see attachment (page 4 of 5). What do I do in such a case.

Kind Regards,

Sriprakash

Please attach a PDF version of this worksheet.

You mean your variable name is Mn/Mp? It has the slash in that name created with the quote trick?

How about placing the commas first and then copy the variable name in the place holder?

You type the expression normally as seen.

Valery used the if-function (which is available in Prime Express, too). There also is the programming "if"-statement which looks differently and programming is offered only in the paid for version.

In Mathcad 15 and below there were some nice ways to hide the calculations and just show colored text boxes with the result using scripted components. Prime in version 4 still does not offer that.

So all you could do is to hide the calculation in a collapsed region.

I can't open your worksheet (just have Prime 3.0 here) so find attached an example of what I was talking about.

This is what is may look collapsed:

and here opened up:

sshastry
6-Contributor
(To:Werner_E)

Thanks WE

Please refer page 4 of 5 of the attached RTF file. My argument should be only if Cur is greater or lesser than 0.3. If it is greater then it is OK. If it lesser then it should report the result as fail. What am I doing wrong here. Kindly let me know.

Regards

Sriprakash

OK, you could copy the if statetment from my sheet to yours and change the variables.

Note, that you can also use the if-function which Valery showed first (status1 in my sheet).

Here the if is NOT taken from the programming menu but just normally typed, the same way as you would type sin(...) or ln(...).

You simply type in the boolean expression, a comma, the "yes" answer, a comma and then the "no" answer.

I guess the problem was, that you erranously took the programming if (my status2).

Of you like the programming if more, here is how to do it:

1) Type status := and then, from the programming menu chose "program"

2) Again from the programming menu chose "if" (most shown keyboard shortcuts don't work on my German keyboard)

3) Fill in the condition in the first placeholder

4) in the second placeholder type the return value for "true"

5) Now comes the tricky part, as editing and seeing where the insert cursor is is really hard in that silly Prime
press the right arrow key twice to go to the end of the if-statement and then press Return. This should get you a placeholder in the exact position as shown below

6) Now chose "else" from the programming menu, insert "FAIL" in the placeholder and click outside that math region.

You are done and can use the variable status as you like.

BTW: Instead of using the menu for if and else you also may simply manually type the word "else" (without the quotes) and immediately press Strg+J simultaneously. This will turn your text into a program statement. A very convenient method.

sshastry
6-Contributor
(To:Werner_E)

Dear We

You are genius my friend. Thank you very much. It worked perfectly and I'm going ahead with the rest of the worksheet.

Many Thanks

Sriprakash

Better use he function if not the operator if.

Why?

The function if works in Prime Express - free version pf Mathcad. The operator - not!

sshastry
6-Contributor
(To:ValeryOchkov)

Hi

Here is a new problem. I tried using another instance of the if operator and it tells me that the value should be scalar. I don't know what I'm doing wrong. Please guide me. Ive attached an rtf file of the worksheet.

Sriprakash

You can work with p[0

sshastry
6-Contributor
(To:ValeryOchkov)

Valery

I'm sorry. I'm a bit dumb. Can you please explain in detail what I need to do. I didn't quite understand when you said "You can work with p[0". What should I do to my worksheet.

Kind Regards

Sriprakash

If you have the answer as [123] not 123 you must find how you get matrix (vector) not scalar

or do so

p=[123] not correct

p[0=123 correct

[ - is the numer of element in vector

one example

sshastry
6-Contributor
(To:ValeryOchkov)

So for me it should be Pu1[0=

Is my assumption correct. Further I'm not able to enter "[" in Mathcad directly. Any idea why?

Sriprakash Shastry написал(а):

So for me it should be Pu1[0=

Is my assumption correct. Further I'm not able to enter "[" in Mathcad directly. Any idea why?

Find where you get matrix

The problem already occurs on page 2 when you define f.ctkfl.

Note the square brackets around the first expression? This means you had used "Insert Matrix" from the menu or typed Strg-M and created inadvertently a 1 x 1 matrix.

You shoud have typed normal parentheses instead.

Based on that variable you calculated a few other variables and those all are 1 x 1 matrices, too. You can see that at the result value which are in parentheses.

As you can see now, P.u1 is a matrix, P.d is a scalar (as it should be) and you cannot ask if a matrix is greater than a scalar.

Change the definition of f.ctkfl. on page 2 and the comparison should work OK.

sshastry
6-Contributor
(To:Werner_E)

Werner,

Many thanks. It works now. Another question. As you can see from my worksheet there are several instances where I calculate a factor called a/l or aequiv/l etc. Now suppose, for the sake of calculation I need to tell the program to assume a value of lets say "0.2"to a/l how do I do it. Lets say I create another factor called a3/l for which I need the program to assume a value of 0.2, how do I do this. Please help.

Sriprakash

I am not sure if I understand what you intend.

If you want a variable to have a specific value you simply assign it via := as you have done quite often in your sheet.

If you want the value of a fraction a/l to become a specific value you have to change the values of nominator and/or denominator accordingly.

If you want Mathcad to tell you in which way you should change, say, a to get the result you want, you may use a solve block.

VERY simple example:

For simple things you may also use the root command to do to the job

Top Tags