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
- :
- Calculating slope in dataset

Options

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

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

Showing results for

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

01-23-2018
10:01 AM

01-23-2018
10:01 AM

Calculating slope in dataset

Hello everyone,

I have lots of datasets with different embankment profiles, see picture for example. Each embankment contains 1 or 2 slopes.

Is it possible to calculate the slope (in this case 2) within the profile. How do I select my boundaries for each slope on the x axis. I can connect my data trough excel as import or make x-y tables/matrixes in mathcad.

I use mathcad prime version 3.

Thanks in advance

Gerwin

ps seems I posted in wrong forum section. Can a moderater move my post to a more apropriate place?

Labels:

22 REPLIES 22

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

01-23-2018
10:45 AM

01-23-2018
10:45 AM

Re: Calculating slope in dataset

How would you define a "slope" in your case?

It would be a good idea to attach a worksheet (you may have to zip it frst to be able to do so because of a nasty bug in the forum software here) with some more example curves.

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

01-24-2018
06:09 AM

01-24-2018
06:09 AM

Re: Calculating slope in dataset

Let me try to clarify a little bit more and add a file with the data of the profile.

In the profile you can see 2 slopes

-1 small one in between 2-12

-2 and a large one in between 72-130.

I would like to calclate the slope of both. I started out with 1. Can mathcad predict the begin and endpoints of slope locations if the data would change a little and what happens if there is like a gap in my data(or is this going to be user input in my sheet). The data in this case is a geometric profile of an embankment.

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

01-24-2018
07:59 AM

01-24-2018
07:59 AM

Re: Calculating slope in dataset

Unfortunately I can't open Prime files from versions greater than 3.0 at the time.

But to make it clear:

You are interested in the regions where your signal has a slop (a first derivative) different from zero.

And you want Mathcad to determine those sections (Mathcad sure can't __predict__ anything which will change if you change your data in an unspecified way).

It may be possible to do. You may create a spline interpolation function (maybe smoothing the data first), define its derivative and look for the regions where the absolute value of the derivative is grater than a specified threshold. The range from 135 to 450 sure has a slightly positive, non-zero slope but obviously not big enough for you to be interested in.

A second idea would be to simply look for positions where the derivative changes sharply. Maybe looking at the second derivative.

In any case its sort of playing around to find a suitable algorithm and it sure would be necessary to have access to more than just one set of data.

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

01-25-2018
08:53 AM

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

01-25-2018
09:22 AM

01-25-2018
09:22 AM

Re: Calculating slope in dataset

Your slope function calculates the slope of a straight line fit to the entire vector set; I believe what's needed is the local slope of selected sections.

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

01-25-2018
10:37 AM

01-25-2018
10:37 AM

Re: Calculating slope in dataset

So?

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

01-25-2018
10:55 AM

01-25-2018
10:55 AM

Re: Calculating slope in dataset

Valery,

OP noted in a reply yesterday that they are looking for the slope between 2-12 and between 72-130.

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

01-24-2018
08:54 AM

01-24-2018
08:54 AM

Re: Calculating slope in dataset

I couldn't open your Prime (3.1 or 4.0) file--I've got Prime 3.0. So I digitized your original picture to get a data set for this example. It's rough, and I haven't tried to automate the detection of slope changes, but it should give you and idea or two. . .

Newer versions can read Prime 3.0

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

01-25-2018
07:00 AM

01-25-2018
07:00 AM

Re: Calculating slope in dataset

In case you are still interested - here is the data from the sheet in Excel format.

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

01-25-2018
08:29 AM

01-25-2018
08:29 AM

Re: Calculating slope in dataset

Thanks! The real data set can be processed without the need for smoothing . . .

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

01-23-2018
11:03 AM

01-23-2018
11:03 AM

Re: Calculating slope in dataset

You have a set of data pairs, (x,y). There are a number of curve fitting possibilities, looking at your example I'd be inclined to look at fitting a spline. The steps are these:

- Smooth the data first if necessary. (Might want to try without smoothing first to see how bad it is.)
- Define a function Y(x) using the vectors x and y. (This allows Mathcad to interpolate between your points.)
- Define the function Slp(x) := dY(x)/dx. (There's a derivative operator.)
- Plot your result.

You may want to split your data up into pieces and fit straight lines to the segments; that's doable but would be challenging to automate.

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

01-25-2018
03:02 PM

01-25-2018
03:02 PM

Re: Calculating slope in dataset

Here are some attempts to automate the finding of the segments with a higher (speaking of the absolute value) slope than a given threshold which does not use an interpolating function and its derivative.

The first approach would need a different kind of smoothing function, I guess

The second approach might be useful. You may have to play around with the parameters and I can't tell if one set of parameters would be appropriate for all your data sets - you had just provided one.

The sheet was created in Mathcad 15 (what else) and I attach the original MC 15 sheet along with a pdf print as well as a converted Prime 4.0 sheet.

Guess there sure are people out there able to provide a file converted to Prime 3.0 if necessary.

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

01-26-2018
10:35 AM

01-26-2018
10:35 AM

Re: Calculating slope in dataset

Thanks all for the responses. Ive been busy with another project that had to be done quick so I did not have time to respond or check any of the solutions. Ive seen a couple of interesting pictures and will take some time soon to see if there is anything in here that can help me.

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

01-26-2018
12:15 PM

01-26-2018
12:15 PM

Re: Calculating slope in dataset

Here are two more attempts, using a numeric discrete derivative but again no interpolating function.

You'll have to give it a try with some others of your data sets.

Sorry, can't attach a Prime 3.0 sheet at the moment. If you ask I am sure someone will be able to convert the MC15 file to Prime 3.

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

01-26-2018
03:14 PM

01-26-2018
03:14 PM

Re: Calculating slope in dataset

The document for Prime **3.0** version is attached.

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

01-26-2018
03:14 PM

01-26-2018
03:14 PM

Re: Calculating slope in dataset

The document for Prime **3.0** version is attached.

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

01-29-2018
04:30 AM

01-29-2018
04:30 AM

Re: Calculating slope in dataset

Thanks a lot I will take a look at it.

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

10-30-2019
03:34 AM

10-30-2019
03:34 AM

Re: Calculating slope in dataset

Thanks. This might help. In the worksheet you sent, the vector Ysm was missing. Hence I did not see the blue lines in the mathcad charts. I would appreciate if you could please resend the worksheet with Ysm.

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

10-30-2019
04:26 AM

10-30-2019
04:26 AM

Re: Calculating slope in dataset

Y.sm is not missing, its "hidden" in the collapsed area above.

Just click the plus sign to the left . In case you are using the version for real Mathcad (MC15) you have to double click the arrow to the left of the line. You can also see whats inside this collapsed area in the pdf print I attached.

In the region the smoothing is done and the user can use one out of a couple of smoothing methods by chnaging the value of idx. In real Mathcad we would create a dropdown list to chose from but in limited Prime this option is not available.

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

10-30-2019
07:35 AM

10-30-2019
07:35 AM

Re: Calculating slope in dataset

yes, sorry, I realized it later. However, in my version the extension pack is not installed. Hence I cannot use medfilt1d. Regardless, I used Ysm=Y and it workded but in the second function (attempt2), trim(L,killer) could not be used too (due to the same reason about the extension pack). Is there any alternative to it?

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

10-30-2019
08:21 AM

10-30-2019
08:21 AM

Re: Calculating slope in dataset

@adar wrote:

Yes "medfilt1d" is part of the Data Analysis Extension pack and "trim" is part of that pack, too.

But some filters like medsmooth are part of the "normal" Mathcad distribution and should work in your version, too. As far as I remember in very old versions of Mathcad this extension pack was distributed in the form of normal Mathcad functions which you could read and modify. So if you by chance (and Googles help) you can find an old version ... I also think some routines were posted here in the forum, too, now and then (but I wasn't able to find an appropriate thread when I gave it a quick try now).

If you know what the functions are supposed to do you may write your own equivalent Mathcad functions (in fact I am not sure about the differences in medfilt1d vs medsmooth).

In case of "trim" here is a quick hack which should do the job without the DAE pack, too.

Worksheet in MC15 format attached.

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

10-31-2019
07:00 AM

10-31-2019
07:00 AM

Re: Calculating slope in dataset

Many thanks! Much appreciated!