Skip to main content
10-Marble
November 22, 2018
Solved

Plotting steps

  • November 22, 2018
  • 6 replies
  • 10379 views

How do I create a plot that looks like "steps", based on a table like shown in attached table and graph?table.PNG

 

graph.PNG

 

Best answer by Werner_E

As an addendum here is an approach which similarly to Luc's creates two vectors which can be plotted one over the other and also adds the vertical line at the beginning and the horizontal line at the and.

B.jpg

Worksheet in Prime 5 format attached.

 

6 replies

19-Tanzanite
November 22, 2018

Try  time=(0.1 0.2 0.2 0.5 0.5 1 1 1.3)^T.   y=(1.2 1.2 1.1 1.1 0.9 0.9 0.5 0.5)^T

 

(Note: the “^T” means take the transpose. Alternatively, enter the data directly as column vectors)

 

 

Alan

23-Emerald I
November 22, 2018

The function "linterp" is great for drawing straight lines between points.  As Alan points out to get steps you need the abcissa (y) to be double valued and the ordinate (x) to match.  (For linterp you need x to be lncreasing (no values the same), so

 

x ;= (0.1  0.1999  0.2  0.2999

and

y:=(1.2    1.2   1.1   1.1   

 

then

Fn(xx):=linterp(x,y,xx)

23-Emerald IV
November 22, 2018

Here's another way:

LM_20181122_PlottingSteps.png

 

Prime 3.1 file attached. Runs in Express!

Success!
Luc

23-Emerald IV
November 25, 2018

For a logarithmic horizontal axis:

 

LM_20181126_PlotPoints.png

25-Diamond I
November 22, 2018

Here are two alternatives for creating the desired step function using just the two vectors you defined.

B.PNG

vyerokhin10-MarbleAuthor
10-Marble
November 22, 2018

Thank you so so much, everyone!!! I especially love the last 2 posts which use only the given table and do everything else automatically. 

Werner_E, (or anyone else) could you please explain how to get those 2 vertical parallel lines that come right after you define stepfun1 and stepfun2?

 

23-Emerald IV
November 22, 2018

To Define a Program:

On the Math tab, in the Operators and Symbols group, click Programming, and then click the Program operator, shown as a symbol with two vertical bars. A program with an empty placeholder appears.

Unless you don't have a full Prime license, but use Prime Express.

 

Success!

Luc

vyerokhin10-MarbleAuthor
10-Marble
November 25, 2018

A few more questions:

Q1) Is there any way to plot a vertical line up, as shown in red, from the first point, using the given data? or would I need to manually enter another point to be the first point?

graph2.PNG

 

Q2) If my first point starts with time=0, and I want to use a log scale - Do I need to manually change the "0" to something like "0.001", or does Mathcad have a way to do this automatically?

 

Q3) Using the method that "@Werner_E" showed, the curve gets distorted when using a log scale. Is there a way around this?

graph3.PNG

23-Emerald IV
November 25, 2018

Q1: "or would I need to manually enter another point to be the first point?"
Yes, that would be a better idea. Using that you are in control of how large the vertical axis should become.

Q2:
Time on a logarithmic scale?
Unusual, but possible. Mathcad does NOT have a way to do this automatically. When a value can be zero, it might just as easily go negative. Where should it go?
So: If you know you're going to plot on a logartithmic scale, make sure no negative or zero values are present.

Q3:
Is there a way around distorted curves using the autoplot feature?
Yes: Use Luc's method. It does not make use of autoplot, and has the advantage that you do NOT need to add trace expressions to include plot points (symbols) when you want to show them:

LM_20181126_PlottingSteps.png

 (Put a star on every corner)

{On the other side of the coin: If you want to plot something else against time in the same plot and want to have the curves aligned, you need time1 as a separate expression for the x-axis.}

 

Success!

Luc

vyerokhin10-MarbleAuthor
10-Marble
November 26, 2018

Thank you again, Luc and Werner_E!!!

Luc - can you please explain your statement a little more:

"{On the other side of the coin: If you want to plot something else against time in the same plot and want to have the curves aligned, you need time1 as a separate expression for the x-axis.}"

I do want to add more curves to this plot - but I'm not understanding what issue you are talking about.

 

21-Topaz II
June 22, 2019

Hi,

Use of the Heaviside step function:

staircase.jpg