0
$\begingroup$

I'm using NDSolve to solve a set of ordinary differential equations. The output is something like.

{X[s] -> interpolating function <>[s], Z[s] -> interpolating function<>[s]}

What needs to be done so that I get variable X interms of Z, and no dependence on s. (X[Z])

PS: This might be a noob question, but I have been struggling to find a way

$\endgroup$
2
  • $\begingroup$ If you have two functions X[s] and Z[s] you want to eliminate s. This is easier said than done. Depending on the functions, this can be easy, but also extremely difficult if not impossible,e.g. when there is no closed form of X[Z] $\endgroup$ – Daniel Huber Sep 25 '20 at 14:26
  • $\begingroup$ Thanks for the information, I was under the impression that there is some command for this operation. no worries $\endgroup$ – Zain Ahmad Sep 25 '20 at 14:59
1
$\begingroup$
Clear["Global`*"]

soln = NDSolve[{x'[s] == -z[s] - x[s]^2, z'[s] == 2 x[s] - z[s]^3,
   x[0] == z[0] == 1}, {x, z}, {s, 0, 20}]

enter image description here

Plot[Evaluate[{z[s], x[s]} /. soln], {s, 0, 20},
 AxesLabel -> {Style[s, 14, Bold], None},
 PlotLegends -> Placed[
   (Style[#, 14, Bold] & /@ {z[s], x[s]}), {0.5, 0.1}]]

enter image description here

As in this case, x[s] would likely be multi-valued for many z[s] values. Consequently, the function would be a very complicated (and difficult to find) Piecewise expression to cover the many branches. However, a ParametricPlot can readily show the relationship.

ParametricPlot[{z[s], x[s]} /. soln, {s, 0, 20},
 AxesLabel -> (Style[#, 14, Bold] & /@ {z[s], x[s]}),
 ColorFunction -> Function[{z, x, s}, ColorData["Rainbow"][s]],
 PlotLegends -> BarLegend[{"Rainbow", {0, 20}},
   LabelStyle -> Directive[Gray, FontSize -> 14, Bold], 
   LegendLabel -> s]]

enter image description here

$\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.