Skip to main content
1-Visitor
August 11, 2020
Question

Trying to replicate matlab cumtrapz() function

  • August 11, 2020
  • 2 replies
  • 3916 views

Hello all,

 

I am trying to recreate a matlab program in mathcad and the only part I'm struggling with is finding a simple replacement for the matlab cumtrapz() function. It is explained in detail here and here.

 

So what I have are 2 vectors containing x and y plot points for a shear forces graph. I'd like to generate the moment plot points which involves getting the cumulative integral from one plot point to the next. I'm looking for the simplest way to do this.

 

A method I've found that appears to work but is a little overly complex is the following:

a := cspline(x, y)

b(x) := interp (a, x, y, c)

c := 0,1..150

f(x) := ∫-b(x) dx   (integrate from 0 to x)

 

and then I can plot f(c) against c

 

Any help in simplifying is greatly appreciated. Thanks!

 

* I should note that I am using Prime 4.0 but don't currently have access, so screenshots will work better than files at the moment

2 replies

23-Emerald I
August 11, 2020

Looks about right!  You could combine lines a bit:

FredKohlhepp_0-1597150716589.png

Note that your answers may shift slightly depending on your choice of spline function.  And you can use units (shear force and position to get moments.)

24-Ruby IV
August 11, 2020

Mathcad + Matlab = Mathlab

25-Diamond I
August 11, 2020

As you are looking for a replacement for Matlabs "cumtrapz()" function - wouldn't simple linear interpolation do the job as well?

https://support.ptc.com/help/mathcad/r6.0/en/index.html#page/PTC_Mathcad_Help%2Flinear_interpolation.html%23

It looks like you are not looking for the vector result of cumtrapz() but rather for a continuous function. Using linear interpolation you might do it like that:

Werner_E_0-1597153321763.png

Remark: You shouldn't use the same variable as integration limit AND integration variable, therefore the xi - you may replace it by c or anything you like.

 

jwalk1-VisitorAuthor
1-Visitor
August 11, 2020

Thanks, I think linterp is simpler and achieves the same thing in this case.

 

I don't know if this is due to the difference between how matlabs cumtrapz() and mathcads linterp() work, but I'm having an issue with my plot matching the output from the matlab program.

 

ptc.png

21-Topaz II
August 11, 2020

Hi,

Your Moment plot has vertical components at each support point where it should be equal each side of support.

This means you are not allowing for unequal reaction at each support left or right.  this accounts for the value on the right hand end not being zero.

 

Moments are usually plotted on tension side so you should plot -m to show this,

Cheers

Terry