# Changing the dependent variable

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

• 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] – Daniel Huber Sep 25 '20 at 14:26
• Thanks for the information, I was under the impression that there is some command for this operation. no worries – Zain Ahmad Sep 25 '20 at 14:59

Clear["Global*"]

soln = NDSolve[{x'[s] == -z[s] - x[s]^2, z'[s] == 2 x[s] - z[s]^3,
x == z == 1}, {x, z}, {s, 0, 20}] 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}]] 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]]
` 