2
$\begingroup$
Clear["Global`*"]
S1 = Inverse[{{0.5, 0}, {0, 0.2}}];
R1 = RotationMatrix[Pi/3];
p1 = {1, 1};

S2 = Inverse[{{1, 0}, {0, 0.5}}];
R2 = RotationMatrix[Pi/6];
p2 = {2, 2};

H1 = R1 . Transpose[S1] . S1 . Transpose[R1];
J1 = -(H1 . p1 + Transpose[H1] . p1);
C1 = p1 . H1 . p1 - 1;

H2 = R2 . Transpose[S2] . S2 . Transpose[R2];
J2 = -(H2 . p2 + Transpose[H2] . p2);
C2 = p2 . H2 . p2 - 1;

Show[Table[Graphics[{Red, Point[p]}], {p, {p1, p2}}],
 Table[ContourPlot[{x, y} . H . {x, y} + Transpose[J] . {x, y} + C == 
    0, {x, -5, 5}, {y, -5, 5}], {H, {H1, H2}}, {J, {J1, J2}}, {C, {C1,
     C2}}], Axes -> True, AxesOrigin -> {0,0}]

which gives me the eight ellipses because of Descarte product on three variables each which takes two values.

What I want is by using Table to generate an output where value of H , J and C start at the same time such as to get {{first value of H,first value of J,first value of C},{second value of H,second value of J,second value of C},{third value of H,third value of J,third value of C}}. In the example above, the output would be two ellipse.

There is one similar question which provides two methods.

One is adding Diagonal, but here is three variables not two variables. Diagonal would gives three results.

The other is using MapThread instead of Table, but ContourPlot is not a math function.

Thank you for any and all suggestions

$\endgroup$

1 Answer 1

3
$\begingroup$

In addition to what you have:

H = {H1, H2};
J = {J1, J2};
Cx = {C1, C2};
exprs = Table[{x, y} . H[[i]] . {x, y} + Transpose[J[[i]]] . {x, y} + 
   Cx[[i]], {i, 1, 2}]
{9.81347 - 21.3135 x + x (19.75 x - 9.09327 y) - 0.313467 y + 
  y (-9.09327 x + 9.25 y), 
 8.6077 - 1.80385 x + x (1.75 x - 1.29904 y) - 7.80385 y + 
  y (-1.29904 x + 3.25 y)}
Show[
 ContourPlot[exprs, {x, 0, 3}, {y, 0, 3}
  , Axes -> True
  , AxesOrigin -> {0,0}
  , Epilog -> {Red, AbsolutePointSize[5],
    Point@{p1, p2}}
  ]
 ]

enter image description here

$\endgroup$
3
  • $\begingroup$ Thanks for the accept. I just realized that Show is redundant, but let's keep it there in case another plot or something else has to be superimposed. $\endgroup$
    – Syed
    Mar 7, 2022 at 13:36
  • $\begingroup$ Thanks anyway. In fact, I have another question. How to plot this in 3D frame? $\endgroup$
    – eason
    Mar 7, 2022 at 13:40
  • 1
    $\begingroup$ There are many types of 3D plots available. I suggest you first try out Plot3D and ContourPlot3D` to see if those meet your requirements. Obviously you will need to have equations suitable for 3D plotting. You can start a fresh post when you have queries. The general idea on stack sites is to restrict discussion to one question per page. Regards. $\endgroup$
    – Syed
    Mar 7, 2022 at 13:50

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.