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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

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

adnn
8-Gravel

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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Werner_E
24-Ruby V
(To:adnn)

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.

 

View solution in original post

15 REPLIES 15
LucMeekes
23-Emerald III
(To:adnn)

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

adnn
8-Gravel
(To:LucMeekes)

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 ?

 

LucMeekes
23-Emerald III
(To:adnn)

Like this:

LM_20170916_Plot.png

Success!
Luc

adnn
8-Gravel
(To:LucMeekes)

I tried the same thing earlier and my graph was blank. I opened your attached mathcad file and the graph was blank ! 

 

Am I having some wrong settings or something ?

LucMeekes
23-Emerald III
(To:adnn)

Language problem? (Are you using a Mathcad in an edition other than English?)

Are you up to the letest mathcad 15 (M045 I guess?)

 

Luc

adnn
8-Gravel
(To:LucMeekes)

Yep, M045. 

 

Weird. Werner_E also used a very similar code and I could see his graph (but not yours or mine).

 

Werner_E
24-Ruby V
(To:adnn)


@adnn wrote:

Yep, M045. 

 

Weird. Werner_E also used a very similar code and I could see his graph (but not yours or mine).

 


Luc usually has autocalculation set to "off", in my sheet its "on".

When you open Luc's sheet you have to explicitly let it calculate to see the plot (Ctrl-F9).

adnn
8-Gravel
(To:Werner_E)

That was spot on !

Now it works 🙂

Werner_E
24-Ruby V
(To:adnn)

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.

 

adnn
8-Gravel
(To:Werner_E)

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)

Werner_E
24-Ruby V
(To:adnn)


@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.

 

Werner_E
24-Ruby V
(To:adnn)

Here, as promised, a way to plot all graphs in just one plot.

Still a bit cumbersome due to Mathcads limitations.

adnn
8-Gravel
(To:Werner_E)

And here comes my upvote, as usual 🙂 

 

Thanks for the awesome code Werner (It's so suited, I hope you don't mind if I literally copy paste it into my sheet ! haha)

Werner_E
24-Ruby V
(To:adnn)

You are welcome!

Glad you got what you are looking for (apart from a plot function which sure would be a nice-to-have).

Attached is a modified program.

In the former one for every plotted function the same number of points (250) was calculated, no matter what the range was.

This can lead to the situation that function with a larger range appear a bit inaccurate.

The new function divides the whole maximum range into a given number of intervals and this spacing is used for every function. So for a function with a wide range more points are calculated than for one with a smaller range.

Most of the time you'll notice no difference, though.

Fred_Kohlhepp
23-Emerald I
(To:adnn)

You've discovered why you need range variables:

Top Tags