Skip to main content
12-Amethyst
December 27, 2024
Solved

Error message - These values cannot be compared

  • December 27, 2024
  • 3 replies
  • 2175 views

Hello

 

I have a written two programs which are very similar. However, when I am running the second program, I get an error message saying "these values cannot be compared".  Unfortunately, I can't figure out what is wrong with the script. How can I solve this error?

 

Thank you for your support! 

 

ksk_10594232_0-1735308854089.png

 

Best answer by Werner_E

I added a function to represent your expression using phi.p, which has no problems with the zeros.

As you can see, the difference is that the graph is move up and the jump occurs from positive to positive value. The zero is far to the left and can be calculated without problems.

That shifting of the graph is due to the difference in the values of phi.d(y) and phi.p(y). A smaller value moves the graph upwards.

Werner_E_1-1735577159442.png

 

The picture also shows the reason for that jump, which is present for all values of y and also in both function (the one using phi.d and the one using phi.p). Its the if-statement in the denominator. The jump occurs when the value goes over 0.45.

It looks like this

Werner_E_0-1735577027642.png

I am not sure if the jump here is really correct and intended, Normally I would expect a continous graph, like is the case in the if-statement in the nominator.

Here the graph is continuous at the position where the expression exceeds 0.2 (at 1104.5 kN).

Werner_E_2-1735577573044.png

 

Something which could be achieved in the other if-statement as well if you simply replace the 1.5 by 1.
But I have no experience whatsoever in your field of work so I can't say if this would make sense

Werner_E_3-1735577862363.png

Another option might be to multiply the 0.45 with 1.5 as well

Werner_E_4-1735577935662.png

 

EDIT: I just noticed that you had exactly that in an expression in the front of the sheet:

Werner_E_0-1735578611412.png

So probably the mistake was just that you forgot to type the parentheses ?

 

 

 

 

 

3 replies

23-Emerald IV
December 27, 2024

Your expression has a discontinuity, and this makes it hard for the root solver to find a solution.

Plot Np and the function versus the Np values and see for yourself:

LucMeekes_0-1735317085835.png

LucMeekes_2-1735317293020.png

LucMeekes_3-1735317310416.png

LucMeekes_4-1735317325424.png

(Putting an error message on the right spot was never a strong point of Mathcad/Prime.)

Success!
Luc

 

23-Emerald V
December 27, 2024

There is nothing wrong with your script.  The problem is that changing from fp to fd results in an expression that causes root to fail to find a solution.  The error message relates to root's attempt to find a solution ... possibly resulting in a complex value.   If you look at a Newton-Raphson approximation for the root then you can see that once y gets beyond a certain value, then the approximation oscillates (ie, the derivative is rather flat and therefore sensitive to small changes in Nproot's algorithms are more sophistiated than Newton-Raphson but they have their own limitations as well.

 

2024 12 27 A.png

 

2024 12 27 B.png

 

Stuart

25-Diamond I
December 27, 2024

I would say that the error message is misleading and showing the wrong position.

The only difference I see is that you use function Phi.d in the second calc instead of function Phi.p.

As a first quick workaround you can throw in a try and catch statement

Werner_E_3-1735317648419.png

So it can be seen that the last two values in vector y are throwing the error

 

I turned your calculation into a function of y and it can be seen that it works OK for values of y smaller than 58 mm and throws that error for y=58 mm or larger. It works again for y>108 mm.

The error message sure is misleading because the expression where the error is shown is independent from the value of y. Nonetheless the value of y and something in the function Phi.d seem to be responsible. Could not be tempted to further look in your function definitions with those nasty nested if functions.

Phi.d itself has no problems with values of y larger than 58 mm.

Werner_E_4-1735317884136.png

 

I defined the function g dependent on N.p you are looking for its zero and used y=60 mm (a value where the calculation would fail),

It can be seen that there is no zero of this function!! Because of the various if-statements in your definitions of the various functions involved we can clearly see a jump from negative to positive values somewhere between N.p=1242.562 kN and 1242.563 kN.

So root can't find a solution. My guess as of this misleading error message is that root in its desperation might try values for N.p which may return non-real results in some functions (possibly delta.0). Not sure about this, though.

So the solution is that you have to check your functions and make sure that they are continuous where you are looking for the zero of  a function.

Werner_E_5-1735318027754.png

 

Additional remark:

The aforementioned jump seems to be present for all values of y, but for values of y lower than 58 mm this jump is fro, one positive value to another and there is a normal point of zero before.

Here the plot for y=57 mm. The function is continuous in the range where the zero is and so root has no problems.

Werner_E_2-1735317095799.png

 

EDIT: Just noticed that you had a very similar problem here, too, where root could not find a solution because of a very similar discontinuity.

-> https://community.ptc.com/t5/Mathcad/Help-me-solve-this-differential-equation/m-p/990241/highlight/true#M215495

 

12-Amethyst
December 30, 2024

Thank you for your responses Luc, Stuart and Werner! Very appreciated!

 

As you already mentioned, the only difference between the first function (which is working) and the second function (which is not working) is Phi_p and Phi_d. I have investigated this further and can not see where the problem is. I have also solved this interation before in Excel, so I know it is solveable. 

 

Is there any workaround for this or any error that causes some roots to be missing for Phi_d? 

 

Thank you for your help!  

 

 

25-Diamond I
December 30, 2024

As I had shown the equation you are trying to solve simply has no zero for a certain range of values. This is due to the discontinuity which Luc mentioned i I showed in the pictures.

Prime can't find a zero which dos not exist, so I can't think of any "workaround" other than going back to the start and look where this jump comes from and fix the appropriate function definition, making it continuous.