3
$\begingroup$

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}]
]
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Nasser Jul 29 '20 at 8:05
  • $\begingroup$ 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 $\endgroup$ – Shelender Kumar Jul 29 '20 at 8:30
  • $\begingroup$ For & Do loops have no output. Perhaps Table is a better. See also mathematica.stackexchange.com/questions/134609/… -- I'll let the answer speak to how to use Solve and Plot. $\endgroup$ – Michael E2 Jul 29 '20 at 12:29
3
$\begingroup$

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

$\endgroup$
  • 1
    $\begingroup$ Thanks for answering but I need the value of x from the roots of above equation $\endgroup$ – Shelender Kumar Jul 29 '20 at 9:42
  • $\begingroup$ "Bug" is a little strong. See, for instance, mathematica.stackexchange.com/questions/32734/… $\endgroup$ – Michael E2 Jul 29 '20 at 12:14
  • $\begingroup$ Here's a hack: ContourPlot[x^6 + x^4 + w*x^2 == $MachineEpsilon*w,...]. Pretty much requires a symmetric x domain {x, -a, a} $\endgroup$ – Michael E2 Jul 29 '20 at 12:24

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.