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

Calculating slope in dataset

GvanBoven
Regular Member

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.

 

vraag mathcad.PNG

 

Thanks in advance

 

Gerwin

 

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

Tags (1)
22 REPLIES 22

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.

 

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.

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.

Re: Calculating slope in dataset

Here is the contents of the file.

 

Pic_1.png

 

 

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.

Re: Calculating slope in dataset

So?

Slope.png

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.

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

Re: Calculating slope in dataset

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

 

 

Re: Calculating slope in dataset

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

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:

  1. Smooth the data first if necessary.  (Might want to try without smoothing first to see how bad it is.)
  2. Define a function Y(x) using the vectors x and y.  (This allows Mathcad to interpolate between your points.)
  3. Define the function Slp(x) := dY(x)/dx.  (There's a derivative operator.)
  4. 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.

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

Bild1.PNG

 

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.

Bild2.PNG

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.

 

 

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.

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.

Bild.PNG

 

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.

 

 

Re: Calculating slope in dataset

The document for Prime 3.0 version is attached.

Re: Calculating slope in dataset

The document for Prime 3.0 version is attached.

Re: Calculating slope in dataset

Thanks a lot I will take a look at it.

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. 

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.

 

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? 

 

Re: Calculating slope in dataset


@adar wrote:

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? 

 

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.

B.png

Worksheet in MC15 format attached.

Re: Calculating slope in dataset

Many thanks! Much appreciated!

Announcements