4
$\begingroup$

I have the following code that finds the critical points of the function enAll[v1,vTotal] and there is a plot of those points as shown below. However, I need each point on the plot to be colored according to the stability of the point. How can I make a color function such that for each v1, it checks the corresponding value of mat[v1,vTotal], and it chooses the color of the point depending on whether mat[v1,vTotal] is positive or negative?

p1[x_] := InterpolatingPolynomial[{{0, 0}, {1 + 0.1, 5, 0}, {2 + 0.1, 3, 0}, {6, 6}}, x]; 
p2[x_] := InterpolatingPolynomial[{{0, 0}, {1, 5, 0}, {2, 3, 0}, {6, 6}}, x]; 
en1[v_] := FullSimplify[Integrate[p1[x], {x, 0, v}]];
en2[v_] := FullSimplify[Integrate[p2[x], {x, 0, v}]];
enAll[v1_, vTotal_] := en1[v1] + en2[vTotal - v1]
vec[v1_, vTotal_] := FullSimplify[D[enAll[v1, vTotal], v1]]; 
mat[v1_, vTotal_] := FullSimplify[D[enAll[v1, vTotal], v1, v1]]; 
spliceThread = Splice @* Thread;

Graphics[Point[Table[spliceThread[{v1 /. NSolve[vec[v1, vTotal] == 0 && v1 > 0 && vTotal >= v1, v1, 
        Reals], vTotal - v1 /. NSolve[vec[v1, vTotal] == 0 && v1 > 0 && vTotal >= v1, v1, Reals]}], 
    {vTotal, 1, 6, 0.01}]]]

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ You need to provide complete code that runs. That includes the definitions of all involved functions, like en1, en2, spliceThread. $\endgroup$
    – MarcoB
    Jul 11, 2023 at 16:51
  • $\begingroup$ I just edited it to include en1,en2, and spliceThread $\endgroup$
    – juv95
    Jul 11, 2023 at 17:41

1 Answer 1

6
$\begingroup$

Perhaps something like

vc[vTotal_?NumericQ] := v1 /. 
  NSolve[vec[v1, vTotal] == 0 && v1 > 0 && vTotal >= v1, v1, Reals]

coords = Table[spliceThread[{vc[vt], vt - vc[vt]}],  {vt, 1, 6, 0.01}];


ht = Flatten@Table[mat[vc[vt], vt] /. vt -> vT, {vT, 1, 6, .01}];

vertexColors = If[# >= 0, Red, Blue] & /@ ht;

Graphics[
 GraphicsComplex[coords, 
  Point[Range @ Length @ coords, VertexColors -> Automatic], 
  VertexColors -> vertexColors]]

enter image description here

Also

ListPlot[List /@ coords, 
 PlotStyle -> vertexColors, AspectRatio -> 1, Axes -> False]

enter image description here

$\endgroup$
2
  • $\begingroup$ That's exactly what I'm looking for. Thank you! $\endgroup$
    – juv95
    Jul 11, 2023 at 17:44
  • $\begingroup$ @juv95, you are most welcome. $\endgroup$
    – kglr
    Jul 11, 2023 at 17:46

Your Answer

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

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