3

I am having some problem while plotting the data being generated in for loop My aim is to plot the result of for loop while it is solving the equation for each value of w,i.e. plot between w and x

Here is the minimum working example

For[w = 0.9925, w < 1.0075, w += 0.0015, 
    Plot[Solve[{x^6 + x^4 + w*x^2 == 0 , x > 0}, x, Reals], {w}]
]
Bholu
  • 91
  • 5
  • Not clear what you are trying to plot there. But these are no solutions any way. If you do For[w = 0.9925, w < 1.0075, w += 0.0015, Print[Solve[{x^6 + x^4 + w*x^2 == 0, x > 0}, x, Reals]] ] then it gives no solution for all values. – Nasser Jul 29 '20 at 08:05
  • Sorry for confusion, I want to plot w vs x, where value of w are define by increment and x is the solution of the equation – Bholu Jul 29 '20 at 08:30
  • For & Do loops have no output. Perhaps Table is a better. See also https://mathematica.stackexchange.com/questions/134609/why-should-i-avoid-the-for-loop-in-mathematica -- I'll let the answer speak to how to use Solve and Plot. – Michael E2 Jul 29 '20 at 12:29

1 Answers1

3

ContourPlot has a bug! It missing some curves , for example the x=0 !

 ContourPlot[x^6 + x^4 + w*x^2 == 0, {w, -10, 10}, {x, -10, 10}, 
     PlotPoints -> 50, ContourStyle -> Red, FrameLabel -> {w, x}, 
     LabelStyle -> {FontFamily -> "Times", 16, Blue}]

enter image description here

Or

 Clear["`*"];
Solve[x^6 + x^4 + w*x^2 == 0 , x, Method -> Reduce]
Plot[x /. % // Evaluate, {w, -10, 10}, AxesLabel -> {w, x}, 
 LabelStyle -> {FontFamily -> "Times", 12, Blue}, 
 PlotStyle -> {Thickness[0.0125]}]

enter image description here

cvgmt
  • 72,231
  • 4
  • 75
  • 133
  • 1
    Thanks for answering but I need the value of x from the roots of above equation – Bholu Jul 29 '20 at 09:42
  • "Bug" is a little strong. See, for instance, https://mathematica.stackexchange.com/questions/32734/how-to-plot-the-contour-of-fx-y-0-if-always-fx-y-0 – Michael E2 Jul 29 '20 at 12:14
  • Here's a hack: ContourPlot[x^6 + x^4 + w*x^2 == $MachineEpsilon*w,...]. Pretty much requires a symmetric x domain {x, -a, a} – Michael E2 Jul 29 '20 at 12:24