0
$\begingroup$

I can use matrixplot for plotting basic functions but I am having problems with matrices. If I try to plot Z={{3 Cos[t], 2Sin[t]}, {-8 Cos[t], 5Sin[t]}} for -50<=t<=50 I get a strange narrow box and I am not sure if it's correct at all. I used the following plot commands:

MatrixPlot[Table[UnitStep[{3 Cos[t], 2 Sin[t]}] UnitStep[{-8 Cos[t],5 Sin[t]}], {t, -50, 50}], PlotTheme -> "Detailed"]

Is this the correct way to matrix plot what I mentioned?

$\endgroup$
4
  • $\begingroup$ The dimension of the table result is {101, 2} which is the reason for the narrow box. Not clear exactly what you are trying to achieve with MatrixPlot. $\endgroup$ – Rohit Namjoshi Aug 14 '20 at 13:16
  • $\begingroup$ I am just trying to plot this 3x3 matrix with MatrixPlot which according to wolfram generates a plot that gives a visual representation of the values of elements in a matrix. (1) But is what I did correct - was this command sufficient to plot what I wanted as mentioned in the beginning of my question? (2) Is there a better way to visualize Z with the mentioned range? $\endgroup$ – Kurapika Aug 14 '20 at 13:32
  • $\begingroup$ What are the elements of the 3x3 matrix? The function Z is a pair of ellipses in parametric form. Maybe you want ParametricPlot[{{3 Cos[t], 2 Sin[t]}, {-8 Cos[t], 5 Sin[t]}}, {t, -50, 50}]? Note that in WL the arguments to trig functions are specified in radians, so you probably don't want the range to be -50 to 50. $\endgroup$ – Rohit Namjoshi Aug 14 '20 at 13:41
  • $\begingroup$ I will try out what you mentioned. But I specifically want to try with MatrixPlot and maybe with ArrayPlot later. It should be possible right? I stated the matrix in my question and declared it randomly as Z. But it could be A or B or M. In mathematica, we state the elements of a matrix inside curly braces. I also made a mistake, Z is a 2x2 matrix as it can be evidently seen. Not a 3x3 one. $\endgroup$ – Kurapika Aug 14 '20 at 13:57
1
$\begingroup$

In such cases you can use Manipulate

Manipulate[ 
  MatrixPlot[{{3 Cos[t], 2 Sin[t]}, {-8 Cos[t], 5 Sin[t]}}, PlotLabel -> t]
, {t, -50, 50}]

enter image description here

$\endgroup$
4
  • $\begingroup$ This is more like what I expected to see but got that weird box instead. Can you point out though what's missing/wrong with my command? $\endgroup$ – Kurapika Aug 14 '20 at 14:25
  • $\begingroup$ I am not sure why you are using UnitStep here. Table[UnitStep[{3 Cos[t], 2 Sin[t]}] UnitStep[{-8 Cos[t],5 Sin[t]}], {t, -50, 50}] is not a list of 2x2 matrices. UnitStep[{3 Cos[t], 2 Sin[t]}] UnitStep[{-8 Cos[t], 5 Sin[t]}] gives you a 1x2 matrix. $\endgroup$ – Sumit Aug 14 '20 at 14:38
  • $\begingroup$ I wasn't sure how to include the given interval with the matrix inside MatrixPlot. I used some references from wolfram and gave UnitStep a shot but ig it was used incorrectly. How would UnitStep would then be used for a 2x2 matrix - ie if it's possible to do so with the case I've described? . $\endgroup$ – Kurapika Aug 14 '20 at 15:28
  • $\begingroup$ MatrixPlot shows the value of mat[i,j] in i,j box. UnitStep is a step function. UnitStep[t] {{a, b}, {c, d}} is {{a, b}, {c, d}} for t>0 and {{0, 0}, {0, 0}} for t<0. I don't thin you need UnitStep for your problem. Alternatively you can plot each element as a function of t, but you don't need UnitStep there as well. $\endgroup$ – Sumit Aug 14 '20 at 16:32
1
$\begingroup$
Clear["Global`*"]

As pointed out by Sumit, use Manipulate

Manipulate[
 MatrixPlot[{
   {3 Cos[t], 2 Sin[t]}, {-8 Cos[t], 5 Sin[t]}},
  PlotLegends -> Automatic],
 {{t, 1}, -50, 50, 1, Appearance -> "Labeled"}]

enter image description here

To use UnitStep

Attributes[UnitStep]

(* {Listable, NumericFunction, Orderless, Protected, ReadProtected} *)

Since UnitStep is Listable,

UnitStep[{{3 Cos[t], 2 Sin[t]}, {-8 Cos[t], 5 Sin[t]}}]

(* {{UnitStep[3 Cos[t]], UnitStep[2 Sin[t]]}, {UnitStep[-8 Cos[t]], 
  UnitStep[5 Sin[t]]}} *)

With UnitStep the array elements are either 0 or 1

Manipulate[
 MatrixPlot[
  UnitStep[{{3 Cos[t2], 2 Sin[t2]}, {-8 Cos[t2], 5 Sin[t2]}}],
  PlotLegends -> Automatic],
 {{t2, 1}, -50, 50, 1, Appearance -> "Labeled"}]

enter image description here

$\endgroup$

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.