I was trying to make a plot of discrete set of data from two tables, the values in one table are fixed and the corresponding values in the other table are obtained from Mathematica itself by solving an equation using FindRoot command. I am having problems plotting the data from two tables. The code I wrote is as follows:

Table[x, {x, 0.1, 2, 0.1}]

y[_x] = Table[FindRoot[(Sqrt[1 + y[x]^2/x^2] +
    (y[x]/(2*x))^2*Log[(x/y[x])^2+Sqrt[1 + (x/y[x])^2]])*x/2 == 1, 
    {y[x], 1}], {x, 0.1, 2, 0.1}]
ListPlot[{y[x], x}]

The Problem being I am not getting the plot, it will be great if someone could help.Thanks.

  • $\begingroup$ forms of y[x] are used on both sides of the equals sign = which is confusing to the human reader and the computer. $\endgroup$ – Manuel --Moe-- G Nov 22 '16 at 20:02
xValues = Range[0.1, 2, 0.1];

yValues = y /. 
   Table[FindRoot[(Sqrt[1 + y^2/x^2] + (y/(2*x))^2*
          Log[(x/y)^2 + Sqrt[1 + (x/y)^2]])*x/2 == 1, {y, 1}], {x, 0.1, 2, 

ListPlot with either

ListPlot[Transpose[{xValues, yValues}]]

ListPlot[yValues, DataRange -> {0.1, 2}]

I believe this is what you are seeking:

ListPlot[#[[1, 2]] & /@ 
  Table[FindRoot[(Sqrt[1 + z^2/x^2] + (z/(2*x))^2*
         Log[(x/z)^2 + Sqrt[1 + (x/z)^2]])*x/2 == 1, {z, 1.}], {x, 
    0.1, 2., 0.1}]]

ListPlot Output

If you have questions about syntax, feel free to comment upon this answer.

  • $\begingroup$ Thanks, but what I am actually looking for is the plot of z vs x which satisfies the given equation. $\endgroup$ – Ajib Paudel Nov 22 '16 at 20:44
  • $\begingroup$ I think, I got it. The graph is showing correct z values but the corresponding x values should be from 0.1 to 2.0 in steps of 0.1, instead its showing serial number 0 to 20 for x values. $\endgroup$ – Ajib Paudel Nov 22 '16 at 21:03

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.