Mathematica Asked on March 16, 2021
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.
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"}]
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 *)
Correct answer by Bob Hanlon on March 16, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP