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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Trying to replicate matlab cumtrapz() function

jwalk
4-Participant

Trying to replicate matlab cumtrapz() function

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

7 REPLIES 7
Fred_Kohlhepp
23-Emerald I
(To:jwalk)

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

Mathcad + Matlab = Mathlab

Werner_E
24-Ruby V
(To:jwalk)

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.

 

jwalk
4-Participant
(To:Werner_E)

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

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

jwalk
4-Participant
(To:jwalk)

I'm still bumbling my way through this and trying to understand how some of these functions work. For now, I've gotten a bit closer by writing a program that replicates matlabs trapezoidal approximation method. Still a work in progress.

 

ptc.png

 

If anyone is curious, this is the program I'm trying to replicate. This post references line 149 specifically. Just for the sake of experimentation, I'm trying to use the same methods used in the matlab program but I'm certain this can be simplified a bit with mathcad functions and programming.

Werner_E
24-Ruby V
(To:jwalk)

It may help if you post your worksheet here.

But it looks you could duplicate the plot of Matlab. Primes ugly autoscaling of the axis is a drawback but you can manually scale each axis by editing the first, second and last value of the axis. To do this you will need a good eye and a steady hand 😉

Top Tags