2
$\begingroup$

Suppose I am given an equation of the following form: $f(x,y)=0$. I would like to find $y$ as a function of $x$. i.e. find the function $y=y(x)$. In general, it is impossible to find a closed-form solution. I can use ContourPlot to visualize the solution. Now, suppose I would like to plot a function $z=g(y(x))$ in terms of $x$. How can I do this in Mathematica?

$\endgroup$
1
  • 1
    $\begingroup$ Is $y$ a function of $x$ in general? Or can $f$ be something like $f(x,y)=x^2+y^2-1$? People here generally like users to post a minimal working example in Mathematica code. It makes it convenient for them to copy-paste it and test their ideas. It's more likely you will get someone to help you. $\endgroup$
    – Michael E2
    Commented Apr 29, 2021 at 21:42

2 Answers 2

1
$\begingroup$

Here's generic approach, if you can pick a initial point:

Block[{f, g, a, b, x0, y0 ics},
 (* set up problem *)
 f[x_, y_] := x^2 + y^2 - 1;
 g[y_] := Sin[Pi y];
 a = -1;
 b = 1;
 {x0, y0} = {0, 1};
 
 (* generic solution *)
 ics = {y[x0] == y0, z[x0] == g[y0]};
 ListLinePlot@
  NDSolveValue[{D[z[x] == g[y[x]], x], D[f[x, y[x]] == 0, x], ics}, 
   z, {x, a, b}]
 ]

enter image description here

$\endgroup$
1
$\begingroup$

Thanks @Michael E2 provide an example.

f[x_, y_] := x^2 + y^2 - 1;
g[t_] := Sin[Pi*t];
ParametricPlot[{x, g[y]}, {x, -1, 1}, {y, -1, 1}, 
 MeshFunctions -> Function[{x, y, u, v}, f[u, v]], Mesh -> {{0}}, 
 MeshStyle -> Red, PlotStyle -> Opacity[.01], PlotPoints -> 80, 
 BoundaryStyle -> None]

enter image description here

Another way is use ParametricRegion.

f[x_, y_] := x^2 + y^2 - 1;
g[t_] := Sin[Pi*t];
RegionPlot[
 DiscretizeRegion[ParametricRegion[{{x, g[y]}, f[x, y] == 0}, {x, y}],
   MaxCellMeasure -> {Length -> 0.01}]]

enter image description here

$\endgroup$

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.