2
$\begingroup$

How can I plot this signal with DiscretePlot?

enter image description here

This mean:

x[-2] = 3, x[-1] = -1, x[0] = 0, etc

This doesn't produce the desired output.

DiscretePlot[{3, -1, 0, -2, 1, -2, -4, 0, 
  1}, {n, {-2, -1, 0, 1, 2, 3, 4, 5, 6}}]
$\endgroup$
1
  • 1
    $\begingroup$ ListPlot[ Transpose[{{-2, -1, 0, 1, 2, 3, 4, 5, 6}, {3, -1, 0, -2, 1, -2, -4, 0, 1}}], Filling -> Axis] $\endgroup$
    – cvgmt
    Commented Oct 31, 2022 at 1:31

3 Answers 3

5
$\begingroup$

DiscretePlot needs expression not list on the left side

enter image description here

Notice it says expression. i.e. some expression as function of n it it, which you do not have. You have list of numbers. If you can find a formula that represent your list of numbers, as function of n, then you can use DiscretePlot

You can use list plot with Filling->Axis. To get the origin to start where you wanted, one way is to build the {x,y} data yourself so it comes out automatically correct without needing to adjust Axes origin.

y = {3, -1, 0, -2, 1, -2, -4, 0, 1}
x = Range[-2, Length[y] - 3]
data = Transpose[{x, y}]
ListPlot[data, Mesh -> All, Filling -> Axis, PlotStyle -> Red]

Mathematica graphics

$\endgroup$
5
$\begingroup$

If you define your function as:

x[-2] = 3; x[-1] = -1; x[0] = 0; x[1] = -2; x[2] = 1; x[3] = -2; x[4] = -4; x[5] = 0;x[6] = 1;

You may then using DiscretePlot, writing:

DiscretePlot[x[i], {i, -2, 6}]

enter image description here

$\endgroup$
3
$\begingroup$

If you want to use DiscretePlot, you can make the function f have the values on those inputs:

Clear@f
(f[#1] = #2) & @@@ Transpose[{{-2, -1, 0, 1, 2, 3, 4, 5, 6}, {3, -1, 0, -2, 1, -2, -4, 0, 1}}];
DiscretePlot[f[x], {x, -2, 6}]

enter image description here

$\endgroup$

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.