# Plotting equations in Mathematica

I believe my question is rather simple, but I cannot find a way to do this. I dont know whether this has been asked anywhere else or not.

Let’s say that I have an equation

$$y^2=(20)+(40*x^2)$$

I would like to vary x from 0.1 to 1, pick up the corresponding x value and plot it in x-y plane The corresponding code is written as:

Plot[Sqrt[(20) + (40*x^2)], {x, 0.1, 1},
AxesLabel -> {HoldForm[x - axis], HoldForm[y - axis]}]


This will give a plot like this:

Now I have an equation which goes like this:

$$y^2/x^2=1-(20/y^2)((y^2-40)/(y^2-60))$$

How can I plot in the similar as in above?

• For your first example you were manually solving for y and plotting the result. For your second problem it wasn't so obvious how to do that by hand. Solve can do that for you. Study this Plot[Re[y/.Solve[y^2/x^2==1-(20/y^2)((y^2-40)/(y^2-60)),y]],{x,0,1}] and see what you can make of it. The Re[] is showing only the real solutions. The y/. is extracting the solutions from the form returned by Solve. – Bill Apr 10 at 6:31
• @Bill, neat, crisp and clear answer. Exactly what I am looking for. You could please put this as answer instead of comment. BTW, why is it showing the warning: Solve::ratnz: Solve was unable to solve the system with inexact coefficients. The answer was obtained by solving a corresponding exact system and numericizing the result. – sreeraj t Apr 10 at 7:09

As requested:

For your first example you were manually solving for y and plotting the result.

For your second problem it wasn't so obvious how to do that by hand.

Solve can do that for you.

Plot[Re[y/.Solve[y^2/x^2==1-(20/y^2)((y^2-40)/(y^2-60)),y]],{x,0,1}]


The Re[] is showing only the real solutions. The y/. is extracting the solutions from the form returned by Solve.

Now to answer the question about the ratnz warning. There are often multiple different algorithms inside of functions like Solve or Reduce. Some of those algorithms only work with exact rational or integer values, some work with decimal approximations. Plot is using decimal values to show your graphs. So it is passing decimal values to Solve. To find the solutions you are looking for it appears that Solve thinks using exact values would be the best approach. So it warns you that it is turning approximate decimal values back to exact rationals, finding the solution and then passing that back to Plot which then turns those back into decimals and displays your curves.

We can avoid that warning with this change

solutions=Re[y/.Solve[y^2/x^2==1-(20/y^2)((y^2-40)/(y^2-60)),y]];
Plot[solutions,{x,0,1}]


which first finds the exact solutions and then hands those solutions to Plot.

Does that explain enough?

• "Does that explain enough?" More that what I anticipated. Thanks a lot. – sreeraj t Apr 10 at 8:30

You can use ContourPlot

ContourPlot[
y^2/x^2 == 1 - (20/y^2) ((y^2 - 40)/(y^2 - 60)), {x, -30, 30}, {y, -30, 30},
MaxRecursion -> 5]


• I would like to vary x and then find value of y. But here both x and y is varying. – sreeraj t Apr 10 at 7:12

Try the following: Step1: express x=x(y):

sl = Solve[y^2/x^2 == 1 - (20/y^2) ((y^2 - 40)/(y^2 - 60)), x][[2, 1]]

(*  x -> Sqrt[-60 y^4 + y^6]/Sqrt[800 - 80 y^2 + y^4]  *)


Step 2: Define the domain

Reduce[-60 y^4 + y^6 >= 0 && 800 - 80 y^2 + y^4 >= 0, y] // ToRadicals

(*  y <= -2 Sqrt[5 (2 + Sqrt[2])] || y == 0 ||
y >= 2 Sqrt[5 (2 + Sqrt[2])]  *)


Step 3: plot

ParametricPlot[{x /. sl, y}, {y, 2 Sqrt[5 (2 + Sqrt[2])] + 0.1,
2 Sqrt[5 (2 + Sqrt[2])] + 3}, PlotRange -> All, AspectRatio -> 0.7]


yielding

you should further play with the plot limits and try out the second solution for x=x(y) that I did not use here.

Have fun!

• thanks for the effort you have put in to check my problem. But, this is not the plot that I should get. – sreeraj t Apr 10 at 8:32
• It is. You simply did not play as I suggested. – Alexei Boulbitch Apr 10 at 9:31