cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
  • New JMP features coming to desktops everywhere this September. Sign up to learn more at jmp.com/launch.
Choose Language Hide Translation Bar

How can I calculate the intersection point of two functions in JMP?

I am graphing two functions in JMP using the YFunction command in JSL. I would like to calculate the point where they intersect. How should I do this either manually or in JSL?

Thanks for the help!

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: How can I calculate the intersection point of two functions in JMP?

The minimize function might do what you need if your functions are well behaved.  In this example, the black reference line is automatically placed at the intersection of the red and green curves.


f1 = Function( {a}, Abs( a ) ^ 1.5);


f2 = Function( {a}, 10 / a );




intersect_X = 1;// guess a value


Minimize( Abs( f1( intersect_X ) - f2( intersect_X ) ), {intersect_X}, <<tolerance(1e-3) );




New Window( "Example",


   Graph Box(


      xaxis( Add Ref Line( intersect_X, "Solid", "Black", "", 1 ) ),


      X Scale( -5, 5 ), Y Scale( -20, 20 ),


      Pen Color( "red" ); Y Function( f1( a ), a );


      Pen Color( "green" ); Y Function( f2( a ), a );


   )


);





8850_intersect.PNG

Craige

View solution in original post

10 REPLIES 10
Craige_Hales
Super User

Re: How can I calculate the intersection point of two functions in JMP?

The minimize function might do what you need if your functions are well behaved.  In this example, the black reference line is automatically placed at the intersection of the red and green curves.


f1 = Function( {a}, Abs( a ) ^ 1.5);


f2 = Function( {a}, 10 / a );




intersect_X = 1;// guess a value


Minimize( Abs( f1( intersect_X ) - f2( intersect_X ) ), {intersect_X}, <<tolerance(1e-3) );




New Window( "Example",


   Graph Box(


      xaxis( Add Ref Line( intersect_X, "Solid", "Black", "", 1 ) ),


      X Scale( -5, 5 ), Y Scale( -20, 20 ),


      Pen Color( "red" ); Y Function( f1( a ), a );


      Pen Color( "green" ); Y Function( f2( a ), a );


   )


);





8850_intersect.PNG

Craige

Re: How can I calculate the intersection point of two functions in JMP?

That works great, thanks! Do you know how I can output the x-coordinate of the intersection using that? The black line shows up perfectly but I cannot see the x-value.

Craige_Hales
Super User

Re: How can I calculate the intersection point of two functions in JMP?

the JSL variable, intersect_X, holds the result of the minimize function.  (minimize uses it for an initial guess, then modifies it.)  You should check if F1(intersect_X) is close enough to F2(intersect_X) to meet your requirements.  A bad initial guess might prevent it from working.

Craige

Re: How can I calculate the intersection point of two functions in JMP?

Exactly what i needed, thanks! It works perfectly.

Craige_Hales
Super User

Re: How can I calculate the intersection point of two functions in JMP?

Or, if you just want it on the graph,

xaxis( Add Ref Line( intersect_X, "Solid", "Black", char(intersect_x,6,4), 1 ) ),

8845_intersect2.PNG

6,4 is the field width and number of decimal digits after formatting the number to characters.

Craige
UntamedKoala
Level I

Re: How can I calculate the intersection point of two functions in JMP?

Dear Craige,

 

Sorry to bother you almost after a decade here. I guess that is what happens with the timeless functions.

I am getting this error while running your script. Would you happen to know what thisi could be?

 

UntamedKoala_0-1739945088807.png

 

Craige_Hales
Super User

Re: How can I calculate the intersection point of two functions in JMP?

Not sure why; two ideas:

  • close any date tables that have columns of the same names used in the JSL
  • check the spelling of the variable names (perhaps use copy-paste the same name to each)...I can't be positive from the picture, but one of the underscores might be a look-alike character.

I copied and pasted the code into JMP 16, 17, 18, and JMP 19 EA and it still works. Maybe the JMP log window will tell you a bit more. What version of JMP are you using? Be great to hear what the answer is, let us know.

Craige_Hales_0-1739966109180.png

 

Craige
mpb
mpb
Level VII

Re: How can I calculate the intersection point of two functions in JMP?

You can interactively find the intersection in this example using a slightly higher level of JMP machinery by using the Profiler.

1. New table with columns X and Y, 2 rows with values -5 and 5 for x.

2. Formula for Y: abs(x)^1.5 - x/10

3. Invoke standalone profiler

4. Specify Y as the prediction formula

5. Specify the desirability function to be Target = 0.

6. Maximize desireability

You will then get the solution X value spelled out on the X-axis.

Re: How can I calculate the intersection point of two functions in JMP?

How do I specify desirability to be Target = 0? I keep getting stuck on that part. This seems to be exactly what i need.

Recommended Articles