0
$\begingroup$

Using NDSolveValue, we can know the y coordinate of the function from an x coordinate. Is it possible to do the reverse, where the input is the y coordinate and the program will output the corresponding x coordinate?

Thank you.

$\endgroup$
1
  • $\begingroup$ If you know the solution is monotone, you can use InverseFunction[y] in the second argument of NDSolveValue. $\endgroup$ – kglr Dec 19 '20 at 5:45
2
$\begingroup$

In general, there may be multiple values of x for a given value of y. For example,

Clear["Global`*"]

ysol = NDSolveValue[
  {y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}];

Let the value of y of interest be 0.2

Plot[{ysol[x], 0.2}, {x, 0, 30},
 PlotRange -> {0, 0.45},
 AxesLabel -> {"x", "y"}]

enter image description here

Since the inverse is multi-valued, an estimate for x must be provided to indicate which solution should be found.

xval[y_?NumericQ, xEst_?NumericQ] := 
  FindRoot[ysol[x] == y, {x, xEst}]

To find all solutions,

xsol = x /. (xval[0.2, #] & /@ {3, 7, 9, 13, 15})

(* {3.03258, 6.20767, 8.80558, 13.1243, 14.6631} *)

Verifying that these values of x give the target value

And @@ (ysol[#] == 0.2 & /@ xsol)

(* True *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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