Can someone tell me why I get an error (and how I get around it) from Solve while I try to Plot a function like:
In[119]:= z[y_] := Max[Solve[x^2 == y, {x}][[All]] /. Rule -> (#2 &)]
z[3]
Plot[Max[z[x]], {x, 0, 3}]
Out[120]= Sqrt[3]
During evaluation of In[119]:= Solve::ivar: 0.00006128571428571428` is not a valid variable. >>
During evaluation of In[119]:= Solve::ivar: 0.06128577551020408` is not a valid variable. >>
During evaluation of In[119]:= Solve::ivar: 0.12251026530612244` is not a valid variable. >>
During evaluation of In[119]:= General::stop: Further output of Solve::ivar will be suppressed during this calculation. >>
What I do: I solve an equation (x^2=y) where y is my variable. I store this in an array and take the maximum value as my function z. This works, as shown (z[3]=sqrt[3]). But I can't use this togther with the Plot function.
I can of course create a list and use ListPlot. But this isn't so useful in the real Problem that has poles and is thus not well described by an equidistant mesh or similar
:>. But, it works likeq[r,s] /. q -> fwhereqis replaced byfwhich in this case is a pure function, so it evaluates. Different, but effective. – rcollyer Oct 23 '14 at 12:58[[All]], though, is not necessary as that is what is returned by default. – rcollyer Oct 23 '14 at 13:02