0
$\begingroup$

I am sorry for such an easy question, but I am still not very good at Mathematica. I would like to plot the solution of

NSolve[(-p^2 v1^2 + (E1 - Ce) (E1 + gam1 - Ce)) (E1^2 - 
     p^2 v1^2 + Ce (gam1 + Ce) - 
     E1 (gam1 + 2 Ce)) == 
  0, E, {p, -10^-7, 10^-7, 0.0000001}]

on one figure. I would be grateful for the help.

$\endgroup$
7
  • 1
    $\begingroup$ NSolve is a numerical procedure and needs numerical input, i.e. you need to give values to the parameteres p, v1 etc. And I guess you meant the lonely E to be E1 - E is a built-in symbol being the basis of the natural logarithm $e\approx 2.72$. Also, how do you want to plot a solutions of an algebraic equation? It's not a function but a list of values E1 satisfying the eq. Like $x=\pm 1$ are solutions to x^2-1==0. $\endgroup$
    – corey979
    Nov 11, 2016 at 10:28
  • $\begingroup$ Your question is badly formulated. You have an equation that looks like an algebraic. However, you use a syntax that partially applies to algebraic, and partially - to differential equations. Second, you have a number of parameters. To plot the solution you have to fix most of them. Third, E is reserved in Mma for the exponential. I suggest that you might edit your question making clear all these points. $\endgroup$ Nov 11, 2016 at 10:31
  • $\begingroup$ OK, I am sorry I didn't provide full data the question is how to plot {{{E -> -0.413317}, {E-> -0.0233172}, {E -> 0.0233172}, {E -> 0.413317}}, {{E-> -0.39}, {E -> 0.}, {E-> 0.}, {E -> 0.39}}, {{E-> -0.413317}, {E -> \ -0.0233172}, {E -> 0.0233172}, {E -> 0.413317}}} as a function of {p, -10^-7, 10^-7, 0.0000001} $\endgroup$ Nov 11, 2016 at 10:44
  • 1
    $\begingroup$ How did you get that output? Please provide a full code; and see my previous comment. $\endgroup$
    – corey979
    Nov 11, 2016 at 10:50
  • $\begingroup$ Yes, exactly that is the output taking into the consideration all of data i do have. I know that this is a list of the value, the question is how to plot an list of the solutions as a function of some variable? I would be grateful for n answer $\endgroup$ Nov 11, 2016 at 11:12

1 Answer 1

1
$\begingroup$

To Solve the algebraic equation for E1:

sol = Solve[(-p^2 v1^2 + (E1 - Ce) (E1 + gam1 - Ce)) (E1^2 - 
      p^2 v1^2 + Ce (gam1 + Ce) - E1 (gam1 + 2 Ce)) == 0, E1]

enter image description here

Substitute given values of p:

sol2 = Table[sol /. p -> i, {i, -10^-7, 10^-7, 10^-7}]

enter image description here

Give numerical values to the parameters:

y = E1 /. sol2 /. {Ce -> 1, gam1 -> 1, v1 -> 1} // N // Chop

{{0, 1., 1., 2.}, {0, 1., 1., 2.}, {0, 1., 1., 2.}}

x = N@Table[i, {i, -10^-7, 10^-7, 10^-7}]

{-1.*10^-7, 0., 1.*10^-7}

Plot the pairs of points:

ListPlot[#, Frame -> True, PlotStyle -> {Red, PointSize[Large]}] &@
   Flatten[#, 1] &@Diagonal@Outer[List, x, y, 1, 2]
    (* or *)
ListPlot[#, Frame -> True, PlotStyle -> {Red, PointSize[Large]}] &@
   Flatten[#, 2] &@MapThread[Outer[List, {#1}, #2] &, {x, y}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Dear corey979 thank you for answer it is very helpful $\endgroup$ Nov 11, 2016 at 19:29
  • 2
    $\begingroup$ @ArthurAltman Glad it helped. If you find it useful, you might want to consider accepting/upvoting it. $\endgroup$
    – corey979
    Nov 11, 2016 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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