# Plotting a function involving an implicit function

The function I would like to plot is $$e=f(w,a;i,\lambda)$$ where $$w$$ is implicitly defined as $$w=g(a;i,\lambda)$$ such that $$w\geq 0$$. Hence $$e$$ is eventually a function of $$a$$, i.e. $$e=f(a;i,\lambda)$$.

Now, I would like to plot $$e$$ against $$a$$ with varying parameter values of $$i \in [0,1]$$ and $$\lambda \in [0,1]$$.

By referring to this, I came up with the following code:

eqn = Eliminate[{e == (w + a (-1 - a w + w^2) - \[Sqrt](a (a - (-1 + a^2) (i + lambda) w + a (i + lambda) w^2)))/(w + a w (-a + w)), -((a (-1 + a^2 - 2 a w) ((i + lambda) w - a^2 (i + lambda) w + a (2 + (i + lambda) w^2) + 2 \[Sqrt](a (a - (-1 + a^2) (i + lambda) w + a (i + lambda) w^2))))/(2 \[Sqrt](a (a - (-1 + a^2) (i + lambda) w + a (i + lambda) w^2)) (w + a w (-a + w))^2)) == 1/w ((w + a (-1 - a w + w^2) - \[Sqrt](a (a - (-1 + a^2) (i + lambda) w + a (i + lambda) w^2)))/(w + a w (-a + w)))}, w] // Simplify

Manipulate[ContourPlot[Evaluate@eqn, {a, 0, 1}, {e, 0, 1}, FrameLabel -> {"a", "e"}], {{i, 0.1}, 0, 1}, {{lambda, 0.1}, 0, 1}]


It runs forever without results.

I also tried an alternative way, incorporating eqn directly into Manipulate as follows:

Manipulate[ContourPlot[Evaluate@Eliminate[{e == (w + a (-1 - a w + w^2) - \[Sqrt](a (a - (-1 + a^2) (i + lambda) w + a (i + lambda) w^2)))/(w + a w (-a + w)), -((a (-1 + a^2 - 2 a w) ((i + lambda) w - a^2 (i + lambda) w + a (2 + (i + lambda) w^2) + 2 \[Sqrt](a (a - (-1 + a^2) (i + lambda) w + a (i + lambda) w^2))))/(2 \[Sqrt](a (a - (-1 + a^2) (i + lambda) w + a (i + lambda) w^2)) (w + a w (-a + w))^2)) == 1/w ((w + a (-1 - a w + w^2) - \[Sqrt](a (a - (-1 + a^2) (i + lambda) w + a (i + lambda) w^2)))/(w + a w (-a + w)))}, w], {a, 0, 1}, {e, 0, 1}, FrameLabel -> {"a", "e"}], {{i, 0.1}, 0, 1}, {{lambda, 0.1}, 0, 1}]


This time, I get a result quite quickly but the plot is empty like this:

• It runs forever How long did it take for just eqn to produce a result? for me, its been running for 2 mins now. This has nothing to do with Manipulate, only the eqn line itself. So is the problem with the eqn taking long time itself, or is the problem with Manipulate taking long time? Jan 11, 2023 at 23:29
• @Nasser: I've been running both eqn and Manipulate together, so I'm not sure which is causing the problem. I just tried running eqn alone and it is still running for 3 mins now.
– ppp
Jan 11, 2023 at 23:33
• I think you should try each command on its own to see where the problem is. If you run 10 commands together and it takes long time, how will you know which one of these 10 commands is the problem? I think this problem has nothing to do with Manipulate. It is your eqn itself which is the problem. This makes it easier to focus on the cause of the problem. Jan 11, 2023 at 23:36
• @Nasser: Yes, it makes sense. But I cannot see what is wrong with eqn as it is similar to the code in the link and each of the two functions in it has no problem. Can you please help me identify the problem in eqn? Thank you!
– ppp
Jan 11, 2023 at 23:41

Clear["Global*"]

eqns = {e == (w +
a (-1 - a w +
w^2) - √(a (a - (-1 + a^2) (i + lambda) w +
a (i + lambda) w^2)))/(w +
a w (-a +
w)), -((a (-1 + a^2 - 2 a w) ((i + lambda) w - a^2 (i + lambda) w +
a (2 + (i + lambda) w^2) +
2 √(a (a - (-1 + a^2) (i + lambda) w +
a (i + lambda) w^2))))/(2 √(a (a - (-1 + a^2) (i +
lambda) w + a (i + lambda) w^2)) (w + a w (-a + w))^2)) ==
1/w ((w +
a (-1 - a w +
w^2) - √(a (a - (-1 + a^2) (i + lambda) w +
a (i + lambda) w^2)))/(w + a w (-a + w))),
0 <= i <= 1, 0 <= lambda <= 1, 0 <= a <= 1, 0 <= e <= 1,
w >= 0};


Solving for e,

sol[i_, lambda_, a_] =
SolveValues[eqns, e, {w}, Reals] // Normal

(* {Root[-2 - 12 a^2 - 2 a^4 - i - 14 a^2 i - a^4 i - 4 a^2 i^2 - lambda -
14 a^2 lambda - a^4 lambda - 8 a^2 i lambda -
4 a^2 lambda^2 + (12 + 56 a^2 + 12 a^4 + 6 i + 60 a^2 i + 6 a^4 i +
16 a^2 i^2 + 6 lambda + 60 a^2 lambda + 6 a^4 lambda +
32 a^2 i lambda + 16 a^2 lambda^2) #1 + (-28 - 92 a^2 - 28 a^4 -
12 i - 80 a^2 i - 12 a^4 i - 16 a^2 i^2 - 12 lambda - 80 a^2 lambda -
12 a^4 lambda - 32 a^2 i lambda - 16 a^2 lambda^2) #1^2 + (32 +
56 a^2 + 32 a^4 + 10 i + 28 a^2 i + 10 a^4 i + 10 lambda +
28 a^2 lambda + 10 a^4 lambda) #1^3 + (-18 - 18 a^4 - 3 i + 6 a^2 i -
3 a^4 i - 3 lambda + 6 a^2 lambda - 3 a^4 lambda) #1^4 + (4 - 8 a^2 +
4 a^4) #1^5 &, 1]} *)


Plotting,

Manipulate[
Plot[Evaluate@sol[i, lambda, a], {a, 0, 1},
PlotRange -> {0.4, 0.7},
Frame -> True,
FrameLabel -> (Style[#, 14] & /@ {"a", "e"})],
{{i, 0.1}, 0, 1, 0.01, Appearance -> "Labeled"},
{{lambda, 0.1}, 0, 1, 0.01, Appearance -> "Labeled"}]


• Bob Hanlon, thank you so much! Do you know how to make the range of the vertical axis of the plot to be in $[0,1]$?
– ppp
Jan 12, 2023 at 1:37
• The small change in the curves when the parameters were changed was due to the plot range changing. Fixing the plot range lets you see the changes more clearly. Jan 12, 2023 at 1:39
• Bob, may I ask you once more on how to fix the range of the vertical axis to be in [0,1]? I tried to add {e,0,1} in Plot, but it doesn't work.
– ppp
Jan 12, 2023 at 1:46
• I added PlotRange -> {0.4, 0.7} to keep the range constant so you would see the movement more clearly. Change that to PlotRange -> {0, 1}` Jan 12, 2023 at 1:50
• You should ask a new question. Include all required info in the new question. Show what you have tried and explain the problem you are having. Link back to this question as background. Jan 12, 2023 at 2:19
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 11, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}