Turn on suggestions

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

Showing results for

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

Showing results for

** Community Tip** - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page.
X

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

Jul 16, 2019
12:54 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 16, 2019
12:54 AM

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.

Solved! Go to Solution.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

Jul 16, 2019
01:55 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 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

Jul 16, 2019
01:10 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 16, 2019
01:10 AM

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

Jul 16, 2019
01:27 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 16, 2019
01:27 AM

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 ?

Jul 16, 2019
01:58 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 16, 2019
03:03 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 16, 2019
03:03 AM

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 ?

Jul 16, 2019
03:08 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 16, 2019
03:08 AM

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

Jul 16, 2019
03:53 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 16, 2019
03:53 AM

Yep, M045.

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

Jul 16, 2019
07:40 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 16, 2019
07:40 AM

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

Jul 16, 2019
01:05 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 16, 2019
01:05 PM

That was spot on !

Now it works 🙂

Jul 16, 2019
01:55 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

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

Jul 16, 2019
03:34 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 16, 2019
03:34 AM

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)

Jul 16, 2019
07:52 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 16, 2019
07:52 AM

@adnn wrote:

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.

Jul 16, 2019
09:21 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 16, 2019
09:21 AM

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

Still a bit cumbersome due to Mathcads limitations.

Jul 16, 2019
01:21 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 16, 2019
01:21 PM

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)

Jul 16, 2019
02:38 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 16, 2019
02:38 PM

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.

Jul 16, 2019
07:02 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator