I would like to put a dot on the point of a curve that has a specific y value but I don't know the x value.

A simple example of my code is

eqns = {y''[t] + y[t] == 3 a Sin[y[t]], y[0] == y'[0] == 1};
pfun = ParametricNDSolveValue[eqns, y[1] + y[2], {t, 0, 5}, {a}];
Plot[pfun[a], {a, -2, 2}]

enter image description here

So say I want to find the x at which y=3. How? Once I have the two coordinates I know how to add the dot. I guess I'm confused because the interpolating function gives you the y given the x, and I can't figure out how to do the inverse. Also any suggestions of tutorials on how to use interpolating functions would be great. Thanks!

  • 1
    $\begingroup$ One comment: the subject should reflect the intent of the question. This one seems to have reversed x and y. $\endgroup$ Jun 11, 2013 at 0:01

2 Answers 2


One way is to use FindRoot

FindRoot[pfun[x] == 3.0, {x, 0}]

Another way is InverseFunction which can be utilised like this

  • 1
    $\begingroup$ Thanks for responding so quickly. I tried the InverseFunction and it gave me InverseFunction[ParametricFunction[<>]][3] $\endgroup$
    – LiaChica
    Jun 8, 2013 at 12:01
  • 2
    $\begingroup$ @Lia, ah, that means ParametricFunction[] is not invertible. Stick with hal's first proposal, then. $\endgroup$ Jun 8, 2013 at 12:07
  • 1
    $\begingroup$ @LiaChica The initial x in FindRoot is sometimes crucial to find the correct solution. Always remember that FindRoot is a local method with stepsize approximations etc where all kinds of bad things can happen. E.g. FindRoot[Sin[x], {x, Pi/2}] gives -8.0*Pi here. So you should have a good understanding of your function. $\endgroup$
    – halirutan
    Jun 8, 2013 at 15:38
  • $\begingroup$ I managed to make FindRoot work once I gave it a specific domain to look in, e.g. FindRoot[pfun[x]==3.0,{x,0,5}] Many thanks! $\endgroup$
    – LiaChica
    Jun 9, 2013 at 9:37

If you do want to use InverseFunction you could make interpolating function via FunctionInterpolation:

f = FunctionInterpolation[pfun[a], {a, -2, 2}];


(* 0.206407 *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.