0
$\begingroup$

I'd like to plot the solutions of a function f(y)=k, when f(y) is non polynomial. This is the Mathematica script I have produced so far:

P = 1; a = 1;
f[y_] = ArcCos[P*Sin[Sqrt[y]*a]/(Sqrt[y]*a) + Cos[Sqrt[y]*a]]/a ;

roots[k_?NumericQ] := FindRoot[f[y] == k, {y, 0.1, 0.5}];

dataRoots = {roots[#], #} & /@ Range[0.01, \[Pi]/a, 0.01];

Show[ListPlot[dataRoots, PlotStyle -> {Red, PointSize[0.02]}]]

Where I have provided two starting (trial) values for y, 0.1 and 0.5. The problem is that the resulting plot is empty. Is there any smarter way to easily find and plot the roots?

$\endgroup$
  • $\begingroup$ Your function has complex values in that interval. $\endgroup$ – b.gates.you.know.what Jun 5 at 12:45
2
$\begingroup$

Try ContourPlot

ContourPlot[k == f[y], {y, 0, 4}, {k, -1, 1}, FrameLabel -> {y,k}]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you! It works although it does not plot the negative k part... $\endgroup$ – cipper Jun 5 at 13:47
  • $\begingroup$ @ cipper: Because f[y]>0 there exists no negative solution k! $\endgroup$ – Ulrich Neumann Jun 5 at 13:56
  • $\begingroup$ you are right (duh!), I must put f[y] == Abs[k] to show the full plot. Thank you again. $\endgroup$ – cipper Jun 5 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.