Skip to main content
1-Visitor
July 16, 2019
Solved

Help: Regarding plotting multiple tracers in a single graph with different ranges (mathcad 15)

  • July 16, 2019
  • 3 replies
  • 7684 views

Dear all,

 

I need to plot multiple functions in a singe graph but ideally would like to plot each of them in their own range. For example,

x = 1 to 10, y(x) = sin(x)

x = 5 to 15 g(x) = cos(x)

x = 50 to 65 k(x) = (sin(x))^2

 

But if I try to plot all 3 graphs in a plot (x ranging from 1 to 100), I get 3 long curves (basically all 3 plots from 1 to 100). Is there any way I can curtail them ? I can do it using 

 

plot_(x) := | plot(x)   if x > 1 (ctrl+&) x < 10

                 | NaN otherwise 

 

But is there a faster / smarter way to do this ?

 

Also, does mathcad have a plot function command (for ex; like matlab) ? I also have a variable for the number of graphs I need to show in a plot (for example, it need not be 3 like shown above, but 4 or 5 or 2 depending on user input). Currently I am planning to put 20 (safe estimate) graphs and setting the values to "NaN" if the value does not exist (not input by user). 

 

For example, if the user inputs 5 graphs (i = 5)

 

plot1_(x) := | plot1(x)   if x > 1 (ctrl+&) x < 10 (ctrl+&) 1 < i

                   | NaN otherwise 

 

Doing this manually 20 times will automatically plot only the first 5 graphs, but it looks very amateurish and is there a smarter way to do it (less code) ?

 

Please advice 🙂

Many thanks in advance,

Aravind.

Best answer by Werner_E

You could use a different range variable, for each function its own.

But I would stick to the approach with NaN. You could define an utility function to do this more comfortable.

See attached.

Unfortunately there is no plot function available in Mathcad.

There would be a little bit more elegant solutions available if you would not mind all plots being the same color (in fact it would be one single plot created by a function).

Furthermore we all wished Mathcad would allow for arrays of functions, which would make things easier, too.

 

3 replies

23-Emerald IV
July 16, 2019

Define xy, xg and xk respectively with their appropriate ranges and then plot y(xy) versus xy, g(xg) and k(xk) versus xk in the same plot.

Mathcad does not have a Plot function.
The maximum number of traces in a plot is 16. 20 will not work.

Success!
Luc

adnn1-VisitorAuthor
1-Visitor
July 16, 2019

Thanks a lot for the very prompt response LucMeekes,

 

I know how to add multiple tracers (Y axis) in a plot, but

How can I plot multiple X axis variables like xy, xg and xx in the same axis ? When I try to do so by using comma, my plot goes blank. 

 

Could you please give me a quick sample of 2 plots of different ranges (xy and xg) like your example ?

 

23-Emerald IV
July 16, 2019

Like this:

LM_20170916_Plot.png

Success!
Luc

Werner_E25-Diamond IAnswer
25-Diamond I
July 16, 2019

You could use a different range variable, for each function its own.

But I would stick to the approach with NaN. You could define an utility function to do this more comfortable.

See attached.

Unfortunately there is no plot function available in Mathcad.

There would be a little bit more elegant solutions available if you would not mind all plots being the same color (in fact it would be one single plot created by a function).

Furthermore we all wished Mathcad would allow for arrays of functions, which would make things easier, too.

 

adnn1-VisitorAuthor
1-Visitor
July 16, 2019

Hi Werner !

Thanks a lot for the awesome answer. I would in-fact prefer if all the plots would be the same color. Could you please (sorry for the bother) give me a sample of how you could do so ? (Define a function which can plot overlapping curves in a single trace)

25-Diamond I
July 16, 2019

@adnn wrote:

Hi Werner !

Thanks a lot for the awesome answer. I would in-fact prefer if all the plots would be the same color. Could you please (sorry for the bother) give me a sample of how you could do so ? (Define a function which can plot overlapping curves in a single trace)


What I had in mind was creating a two column matrix with x- and y-values of the plots at certain distances (maybe 100 points per function?), separate the various plots by NaN's and then simply plot the y-values over the x-values.

As, as already mentioned, Mathcad does not support vectors of functions, a little bit of overhead is needed to do so.

Maybe later I'll post an example of what I am talking about.

Nevertheless your user would be forced to input the function terms an the range similar to what I did in the second example.

The difference would only be that the plot does not consist of 5 or 16 different plots but of just one single plot. So the number of function graphs is not limited that way but all are the same color.

 

23-Emerald I
July 16, 2019

You've discovered why you need range variables: