0
$\begingroup$

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?

$\endgroup$
1
  • 1
    $\begingroup$ You need Plot[y /. yy[z], {z, 0, 5}]. Did you try to debug your code and see what yy[3] gives you? $\endgroup$ Commented Aug 2, 2017 at 22:45

2 Answers 2

4
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Oh I got it. Thanks dude! $\endgroup$ Commented Aug 3, 2017 at 3:54
3
$\begingroup$

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] 

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.