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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Translate the entire conversation x

Passing equation array function into Matrix

JK_9391805
5-Regular Member

Passing equation array function into Matrix

hi @LucMeekes 

 

I am passing array of equations into an Array

JK_9391805_0-1741263839804.png

And then want to get this function in the form of matrix like below wherein A is the Matrix, which I want to pass to reference calculation worksheet, which is called within main worksheet.

JK_9391805_4-1741264145698.png

It gives the error to check label.

Can anyone help me to understand and solve this.

I could do this in Mathcad 15 and now struggling in Prime.

 

Regards,

JK_9391805

 

 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:JK_9391805)

You are right that the behaviour of evaluating combined Boolean expression unfortunately has changed in Prime.

 

Mathcad used "short-circuit evaluation". This means that when three Boolean expressions are combined with OR, the first one is checked and if the result is "true" the others are not evaluated anymore because its clear that the whole expression must be "true".

 

Prime evaluates every single boolean and decides afterward about the result.

As you already noticed, the error occurs when the limit is a string because its not allowed to compare a string  with a numeric value.

 

So given that this is the expression which throws the error

Werner_E_0-1741523442283.png

on way to avoid the error is to split it

Werner_E_1-1741523482723.png

another is to wrap the last Boolean expression which could throw the error in a try and catch

Werner_E_2-1741523523043.png

Guess the first way is better readable.

EDIT: It just came to my mind that there may be a problem with both suggestions if "min_limit" is a string but neither "-" nor "NA".
The first workaround would throw an error in this case which is the same behaviour as MC15 would show

The second suggestion would return "true" in this case. Change the "1" to "0" and it always will return "false" in this case.

 

Of course you would also have to apply similar changes for the other combined Booleans wherever this error could be thrown as well.

 

See here for a thorough explanation of short-circuit evaluation and also some pros and cons of using it. It does not help as there is no way to turn this feature on in Prime but the article may give a hint why PTC might have decided against using short-circuit eval (in case they really did this on purpose).

Short-circuit evaluation - Wikipedia

View solution in original post

19 REPLIES 19
Werner_E
25-Diamond I
(To:JK_9391805)

Please attach your sheet. How should we see how the variables are actually labelled just from a picture?

We also don't see how you defined your ArrayOfEqns and the functions used therein.

If something worked in Mathcad (15), that doesn't mean it will work in Prime - unfortunately.

It may help if you also post a Mathcad 15 worksheet demonstrating that what you did worked in that version.

General advice: Global assignments should be used very sparely and with great care. Whenever possible (and its possible most of the time) avoid using them.

As Werner says, Mathcad Global Definitions should be used with great care, especially in Mathcad Prime which is not as permissive as the prior Mathsoft Mathcad.

 

However, I’d guess that your problem arises because you’re trying to define PassFunction with Global Definition whilst you define SymbFun using a standard Definition.

 

Mathcad looks at Global Definitions before standard Definitions.  Consequently, Mathcad will attempt to create PassFunction without knowing what SymbFun is.

 

Stuart

Werner_E
25-Diamond I
(To:StuartBruff)

Well spotted, but then this would also not work in MC15 and fail with the very same error message.

JK_9391805
5-Regular Member
(To:JK_9391805)

Attached is the Prime file, 

Werner_E
25-Diamond I
(To:JK_9391805)

And you really claim that doing so worked in Mathcad 15? It doesn't !!

 

Don't use global definitions and it works OK

Werner_E_0-1741342916237.png

 

And then, why not simply

Werner_E_1-1741343537129.png

 

or

 

Werner_E_2-1741344087418.png

?

 

Was there any specific reason for using the global assignments?

 

 

 

Werner_E
25-Diamond I
(To:Werner_E)

For completeness sake here to show that what you tried does not work in Mathcad 15 either

Werner_E_0-1741345041867.png

 

JK_9391805
5-Regular Member
(To:Werner_E)

thanks for the response.

We need to pass the equation array to another worksheet for further calculations which is called within same worksheet,

thats the only reason of using global operator

LucMeekes
23-Emerald IV
(To:JK_9391805)

If you include the 'another worksheet' past the definition, you shouldn't need a global definition.

Success!

Luc

Werner_E
25-Diamond I
(To:JK_9391805)


@JK_9391805 wrote:

thanks for the response.

We need to pass the equation array to another worksheet for further calculations which is called within same worksheet,

thats the only reason of using global operator


I am not quite sure about the workflow you have in mind and why you think global assignments are necessary. It might be a matter of where in the worksheet the external file is referenced..

Of course your approach would also work if you use global assignment throughout. Not sure if this would be of help.

Werner_E_0-1741346511435.png

 

JK_9391805
5-Regular Member
(To:Werner_E)

I tried to club both the worksheet into single maintaining the flow of functions, all with only definition operator not a single global operator.

Now I get error as "These values cannot be compared" for next main function, I apologies that I couldn't share that worksheet here due to NDA but can someone tell me how can I debug this issue. The variables within the parenthesis of a function all has the values evaluated but something is not matching with function definition. The return value from the main function is matrix

LucMeekes
23-Emerald IV
(To:JK_9391805)

Are you comparing a scalar to a vector, or a united variable with a non-united value?

Note that when you want to see if a distance is larger than 0, you may need to compare with 0m, not with just 0.

Success!

Luc

Werner_E
25-Diamond I
(To:JK_9391805)

Can you duplicate that error in a demo worksheet like the one you used here initially?

In what kind of region/expression you experience this error? Are you using the comparison equal (big fat equal sign) or a greater sign (>).

What kind of values do you compare?

JK_9391805
5-Regular Member
(To:Werner_E)

I am sharing only the function where i face the error, although it doesnt work in demo worksheet, its working at my clubbed sheet but I cant share 😞 see below snap for evaluation of all passed variables in PerformAnalysis function

As shared earlier, again this was working in MC15 and converted to prime 10 using XMCT converter. which didnt throw any error messages after conversion. maybe some syntax is not as per prime demand.

JK_9391805_0-1741368181360.png

 

Werner_E
25-Diamond I
(To:JK_9391805)

Can't say much.

Only expression in my opinion which may throw this error in the function you posted is the comparison in the if -statement

Werner_E_0-1741374378650.png

So you may check the result of the function "GetStepValueConfigInfo" and see if the element is a scalar.

On the other hand the error may also be thrown in one of the functions which are called in "PerformAnalysis".

You may try if Primes error trace facility is able to tell you where the error exactly occurs. Put the cursor at the error and then press "First".

Werner_E_1-1741374639386.png

 

JK_9391805
5-Regular Member
(To:Werner_E)

I tried to narrow down the way you have directed, attached is demo copy of same, now i can see the err is at comparison in if statement 

Pls note again this was functional in MC15, something is different in prime which i m not sure abt.

JK_9391805
5-Regular Member
(To:JK_9391805)

When the values to be compared are integers not "-" and "NA" there persists the comparison error, if we pass integers its not there. is there any special way of comparing in matrix with int and string 

LucMeekes
23-Emerald IV
(To:JK_9391805)

You may need to split your if statement(s):

LucMeekes_0-1741522059444.png

As you don't know in which order Prime is going to evaluate the test.

If it first tries to compare min-val with min-limit, nad min-limit is "-" then you get such error message.

First test if min-limit is "-" or "NA", then if that is not true, can you compare numeric values.

 

Success!
Luc

Werner_E
25-Diamond I
(To:JK_9391805)

You are right that the behaviour of evaluating combined Boolean expression unfortunately has changed in Prime.

 

Mathcad used "short-circuit evaluation". This means that when three Boolean expressions are combined with OR, the first one is checked and if the result is "true" the others are not evaluated anymore because its clear that the whole expression must be "true".

 

Prime evaluates every single boolean and decides afterward about the result.

As you already noticed, the error occurs when the limit is a string because its not allowed to compare a string  with a numeric value.

 

So given that this is the expression which throws the error

Werner_E_0-1741523442283.png

on way to avoid the error is to split it

Werner_E_1-1741523482723.png

another is to wrap the last Boolean expression which could throw the error in a try and catch

Werner_E_2-1741523523043.png

Guess the first way is better readable.

EDIT: It just came to my mind that there may be a problem with both suggestions if "min_limit" is a string but neither "-" nor "NA".
The first workaround would throw an error in this case which is the same behaviour as MC15 would show

The second suggestion would return "true" in this case. Change the "1" to "0" and it always will return "false" in this case.

 

Of course you would also have to apply similar changes for the other combined Booleans wherever this error could be thrown as well.

 

See here for a thorough explanation of short-circuit evaluation and also some pros and cons of using it. It does not help as there is no way to turn this feature on in Prime but the article may give a hint why PTC might have decided against using short-circuit eval (in case they really did this on purpose).

Short-circuit evaluation - Wikipedia

JK_9391805
5-Regular Member
(To:Werner_E)

Thanks @Werner_E ,  @LucMeekes and @StuartBruff : Your valuable inputs really helped 

I could trace the issue in less time, although it give EXCEL BUSY issue here and there 🙂 i think it's with all Prime community

Announcements

Top Tags