Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
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!
Solved! Go to Solution.
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.
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
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).
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
Another option might be to multiply the 0.45 with 1.5 as well
EDIT: I just noticed that you had exactly that in an expression in the front of the sheet:
So probably the mistake was just that you forgot to type the parentheses ?
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:
(Putting an error message on the right spot was never a strong point of Mathcad/Prime.)
Success!
Luc
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 Np. root's algorithms are more sophistiated than Newton-Raphson but they have their own limitations as well.
Stuart
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
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.
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.
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.
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.
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!
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.
Thank you
Could you please clarify what do you mean by "fix the appropriate function definition" and "making it continuous"? Aren't both Phi_p and Phi_d continuous?
See the last but one picture in this reply: https://community.ptc.com/t5/Mathcad/Error-message-These-values-cannot-be-compared/m-p/990961/highlight/true#M215566
Here I had chosen y=60 cm, a value where your calculation using the root function fails. The function g(N) represents the expression you use in your root function. This is the expression which you want to be zero and look for the appropriate value of N.
And the plot clearly shows that there is no value of N which makes this function to zero because there is a discontinuity at approx N=1242.562 kN
The root command can't find something which simply does not exists!
I have not investigated further which if statement is responsible for this jump - thats something you should be able to find much faster I guess.
The thing that I find strange is that the functions Phi_p(y) and Phi_d(y) are more or less identical except for the fact that y_p and y_d (constants) differ and there is no problem solving the roots for the Phi_p function only for Phi_d. I have a hard time understanding that.
Your task sure is to find out where the step, the jump in your expression stems from.
Its present for all values of y. depending on y the graph seems to be moved up or down. As long as the jump is completely in the area of negative or completely in the area of positive values, all is OK as the function (my function g() which is the expression you want to solve for) is continuous in the area of its zero. but when the graph is move so that the jump is from a negative to a positive value, not zero value exists.
Thanks. Unfortunately, I don’t know how I shall proceed from here. How can I find out what causes the jump in the expressions?
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.
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
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).
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
Another option might be to multiply the 0.45 with 1.5 as well
EDIT: I just noticed that you had exactly that in an expression in the front of the sheet:
So probably the mistake was just that you forgot to type the parentheses ?
Thank you Werner for your help! I hope this solve my problem. I am beyond greatful for your time !