# Why Plot does not work for a my function?

I wanted to make a simple plot as follows:

T=((2 + 1.5 y)^2 (0.8 + 4.5y^2) + 4.5 y^2 (0.8 + 12 y + 9. y^2)x + 40.5 y^4
x^2)/(4 ((2 + 1.5 y)^2 +4.5 y^2 x));

yy[z_]:= FindRoot[4 (y + (T /. x -> z)) y == 1, {y, 0}];

Plot[yy[z],{z,0,5}]


In words, there is a functional relation $f(x,y)=1$, and I defined function $yy:R_+ \rightarrow R_+$ as the mapping from value of $x$ to an implicitly determined $y$. This function works well: I tried to plug in any number into yy[z] and a reasonable value will be returned. However, the Plot does not give any result. Is this a bug, or is there any problem in my code?

• You need Plot[y /. yy[z], {z, 0, 5}]. Did you try to debug your code and see what yy[3] gives you? – Vitaliy Kaurov Aug 2 '17 at 22:45

As @Vitaly suggested, if you use

yy[z_] := FindRoot[4 (y + (T /. x -> z)) y == 1, {y, 0}];


you find

In[58]:= yy[3]

Out[58]= {y -> 0.294456}


and that cannot be plotted, unless you modify yy[z_] as:

yy[z_] := FindRoot[4 (y + (T /. x -> z)) y == 1, {y, 0}][[1, 2]];


which gives you:

In[63]:= yy[3]

Out[63]= 0.294456


and that can be plotted. Using

Plot[y /. yy[x], {x, 0, 5}]


is also fine, of course.

• Oh I got it. Thanks dude! – David Xiaoyu Xu Aug 3 '17 at 3:54

Solve can provide the complete solution

T = ((2 + 1.5 y)^2 (0.8 + 4.5 y^2) +
4.5 y^2 (0.8 + 12 y + 9. y^2) x +
40.5 y^4 x^2)/(4 ((2 + 1.5 y)^2 + 4.5 y^2 x)) // Rationalize //
FullSimplify

(*  (128 + 3*y*(64 + 3*y*(88 + 16*x +
120*(1 + 2*x)*y +
45*(y + 2*x*y)^2)))/
(40*(16 + 3*y*(8 + (3 + 6*x)*y)))  *)

yy2[x_] = y /. Solve[{4 (y + T) y == 1, 0 <= x <= 5}, y, Reals];

Plot[Evaluate@yy2[x], {x, 0, 5},
PlotStyle -> {Red, Green, Blue},
PlotLegends -> Automatic,
PlotRange -> All]