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

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

Find result sometimes has wrong sign

akelly
11-Garnet

Find result sometimes has wrong sign

I'm using a Given ... Find solve block in a function.

When I call the function with an argument, sometimes the result has a positive sign, sometimes negative.  Mathematically it is correct, but I can't figure out why it's giving sign changes, and I only want positive results.

The seeded guess value is positive.  If I seed the guess value to high to try to sneak in to the solution from the high side, the function fails frequently.

I tried adding an inequality inside the solve block (R_guess>0 in) to try to force a positive result.  The function fails all the time.

Looking for suggestions to get only a positive result from the Given ... Find function.


Capture.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
Werner_E
24-Ruby V
(To:akelly)

Change R.guess to 0.01 in

You may also take the absolute value of all results.

Are you aware that R.reduced(R1) simply returns R1 ?

View solution in original post

13 REPLIES 13
MikeArmstrong
5-Regular Member
(To:akelly)

Please provide a worksheet as the image does not show all the variables.

Mike

Fred_Kohlhepp
23-Emerald I
(To:akelly)

Andrew Kelly wrote:

I'm using a Given ... Find solve block in a function.

When I call the function with an argument, sometimes the result has a positive sign, sometimes negative.  Mathematically it is correct, but I can't figure out why it's giving sign changes, and I only want positive results.

The seeded guess value is positive.  If I seed the guess value to high to try to sneak in to the solution from the high side, the function fails frequently.

I tried adding an inequality inside the solve block (R_guess>0 in) to try to force a positive result.  The function fails all the time.

Looking for suggestions to get only a positive result from the Given ... Find function.


Capture.PNG

Mike has asked for your sheet.  Some of the questions that jump out:

      In the first line, what is R2?

      In the second line, what is Ereduced?

      What value do you have for scriterion?

At first look, a(R,P) is a cube root, so can be negative or positive, your solve block uses a (R,P) squared, so Pmax is forced positive whether R is positive or negative.

Hello

These are the formulas for the Hertz contacts, it is the area between two spheres.

The E is young's modulus of each sphere.

See attached in French, but you'll probably find the same thing in English.

Kind regards.

Denis.

Contact de Hertz — Wikipédia

Fred Kohlhepp wrote:

At first look, a(R,P) is a cube root, so can be negative or positive, your solve block uses a (R,P) squared, so Pmax is forced positive whether R is positive or negative.

Exactly.  That's why I said that the result is mathematically correct, but "wrong" for my needs.

There's a behavior inside the solve block that allows it to choose sometimes the positive result or sometimes the negative result.

Why?

How do I stop it?

akelly
11-Garnet
(To:akelly)

Here is the full worksheet.  It's an attempt to find the recommended spherical radius for an arbitrary force, such that a specific contact pressure is obtained.

Note: V15 M040.

Werner_E
24-Ruby V
(To:akelly)

Change R.guess to 0.01 in

You may also take the absolute value of all results.

Are you aware that R.reduced(R1) simply returns R1 ?

akelly
11-Garnet
(To:Werner_E)

Werner Exinger wrote:

Change R.guess to 0.01 in

Can someone explain how/why the seed value affects the results?

I understand the layman's concept that when multiple answers are possible, the seed value should be close to the answer.  But what I'm seeing is that it isn't always picking the solution that is closest to the seed value.

R.guess = 0.01 in --> all results are positive

R.guess = 10 in --> results are sometimes positive, sometimes negative

R.guess = 10000 in --> all results are negative

RichardJ
19-Tanzanite
(To:akelly)

Like most non-linear solvers, the non-linear solver used by Find heads downhill on the error surface until it reaches a minimum, and then stops. Note that downhill on the error surface (i.e. smaller error) does not necessarily mean that the value of the parameter you are solving for is smaller. It does also not necessarily find the closest minimum to the starting point, or the deepest minimum (i.e. it may find a local minimum rather than the global minimum). Once it has found a minimum Find checks the error, and if it is sufficiently close to zero gives the result. This is the only difference to minerr, which simply gives the value(s) of the parameter(s) at the minimum, regardless of how small the error is.

One thing you may do is also pass R.guess as a parameter to the function. That allows you to change the guess value each time you call it. Then you can find a guess value that works for the first force value, and subsequently use the last found radius as the guess for the next force value.

Werner_E
24-Ruby V
(To:akelly)

As Richard already explained, thats the behavior of the numeric algorithm used. Hard to guess which guess would yield which result. I am not sure why the constraint R.guess does not work, but it seems that when the algorithm was heading downhill, as Richard had put, and its trapped in a valley with all negative values, it wont climb up again to run down the neighbor valley. BTW, if you right click at the command "find" you get the option to change the algorithm used. The other two non-linear algorithms offered have options to play with, but they will not yield any solutions at all. LM usually is a good (automatic) choice for the algorithm.

I am not sure if your variable R.2 which is set to infinity has negative effects, too. But I would tend to avoid having a variable set to infinity. As stated above R.reduced will simply return the argument R1, but I guess you intend use your sheet to play around with different values for R.2, too.

But the equations in use in your solve block can easily solved symbolically, too, so you don't have to cope with the solve block problems at all:

If we rewrite the symbolic the function definition by hand to use the reciprocal value of R.2, even the value infiinity is accepted:

akelly
11-Garnet
(To:Werner_E)

Great examples.  Thanks.

Werner_E
24-Ruby V
(To:akelly)

Maybe you like that way to define your radius function even more

MikeArmstrong
5-Regular Member
(To:Werner_E)

Excellent work by by you and Richard.

Fred_Kohlhepp
23-Emerald I
(To:akelly)

Attached find an excerpt from Roark that I have used with success.  I can find common threads in your sheet.

Top Tags