Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Help: Regarding plotting multiple tracers in a sin...

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-16-2019
12:54 AM

07-16-2019
12:54 AM

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.

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-16-2019
01:55 AM

07-16-2019
01:55 AM

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.

15 REPLIES 15

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-16-2019
01:10 AM

07-16-2019
01:10 AM

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

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

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-16-2019
01:27 AM

07-16-2019
01:27 AM

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

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 ?

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-16-2019
01:55 AM

07-16-2019
01:55 AM

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.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-16-2019
01:58 AM

07-16-2019
01:58 AM

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

Like this:

Success!

Luc

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-16-2019
03:03 AM

07-16-2019
03:03 AM

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

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 ?

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-16-2019
03:08 AM

07-16-2019
03:08 AM

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

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

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-16-2019
03:34 AM

07-16-2019
03:34 AM

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

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)

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-16-2019
03:53 AM

07-16-2019
03:53 AM

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

Yep, M045.

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

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-16-2019
07:02 AM

07-16-2019
07:02 AM

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

You've discovered why you need range variables: