cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Plot problem

Sergey
14-Alexandrite

Plot problem

Hello!

 

There is something wrong with the plot of the function (look at the attached file).

When "x" is defined from 0 to 10 the plot looks correct. But when I define "x" from -10 to 10 plot looks like a straight line.

Where did I make a mistake during the plot?

 

Best regards,

Sergey

1 ACCEPTED SOLUTION

Accepted Solutions
DJNewman
17-Peridot
(To:Sergey)

You should define x as -10, -9 ... 10 instead of -10, 1...10.

Edit: Alternatively just write it as -10 ... 10 if you want your step size to be 1.

 

https://support.ptc.com/help/mathcad/r8.0/en/index.html#page/PTC_Mathcad_Help/range_operators.html

I manage the Creo and PTC Mathcad YouTube channels for PTC, as well as all PTC Mathcad marketing in general.

View solution in original post

6 REPLIES 6
DJNewman
17-Peridot
(To:Sergey)

You should define x as -10, -9 ... 10 instead of -10, 1...10.

Edit: Alternatively just write it as -10 ... 10 if you want your step size to be 1.

 

https://support.ptc.com/help/mathcad/r8.0/en/index.html#page/PTC_Mathcad_Help/range_operators.html

I manage the Creo and PTC Mathcad YouTube channels for PTC, as well as all PTC Mathcad marketing in general.
StuartBruff
23-Emerald II
(To:Sergey)


@Sergey wrote:

Hello!

 

There is something wrong with the plot of the function (look at the attached file).

When "x" is defined from 0 to 10 the plot looks correct. But when I define "x" from -10 to 10 plot looks like a straight line.

Where did I make a mistake during the plot?

 

Best regards,

Sergey


Hi Sergey.

 

Your problem arises because you have (I think) used your intended step size in the range variable x's definition.

 

A range is defined as first_value,next_value..final_value. Mathcad uses the first and next values to calculate the step size.  You have x:=-10,1,10.  Consequently, Mathcad thinks you want x taking the values 10 and 1 (the next value after 1 would be 12, but the max range value you've give is 10).  What you want is x:= -10,-9..10.

 

2022 05 05 h.png

 

Revised Mathcad Prime 8 worksheet attached.

 

Stuart

Sergey
14-Alexandrite
(To:StuartBruff)

Hello Stuart.

 

It seems that you are right. I simply misunderstood how to define the step and the range.

Now it is clear.

 

Thanks a lot.

 

Best,

Sergey

StuartBruff
23-Emerald II
(To:Sergey)

No worries, Sergey.   It's a common Mathcad error, particularly when people have some familiarity with languages that use steps instead of the next value in the sequence.

 

Sometimes, it's useful to have the choice, so I have a library of sequence generation functions in my default worksheet.

 

2022 05 05 i.png

 

2022 05 05 j.png

 

 

You could even define a function - range, say - that generates a range using the first, next .. final specification:

 

2022 05 05 k.png

 

Mathcad Prime 7 worksheet attached - it should work in Mathcad Express 7 and Mathcad Prime/Express 8, as well.

 

Stuart

Sergey
14-Alexandrite
(To:StuartBruff)

Thank you, Stuart.

 

I will study your sheets.

 

I think that my "old" definition of the range and step, that originated in the original problem of this thread, came from Matlab. 

 

Sergey

 

StuartBruff
23-Emerald II
(To:Sergey)


@Sergey wrote:

Thank you, Stuart.

 

I will study your sheets.

 

I think that my "old" definition of the range and step, that originated in the original problem of this thread, came from Matlab. 

 

Sergey

 


Hi Sergey.

 

I wondered if Matlab's colon operator featured somehow - it's been a long time since I used it, though.   As noted in the description, the function linspace gives (or should give) the same results as Matlab's linspace.

 

An important point to note is that a range variable is a variable that contains a range (specification)- it does not contain the expanded definition and is *not* a vector (this causes a lot of confusion amongst new Mathcad users).   It's better to think of a range (first, next..last) as an implicit iterator rather than a vector.

 

Consequently, although linrange and range may look like they're doing the same thing, they are quite distinct.   linrange returns a vector, whilst range returns a range.

 

Stuart

Top Tags