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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Pulse function

mlernst
7-Bedrock

Pulse function

I need a "forcing function" that will be continuous (not piece wise). It needs to be a rectangular function with amplitude "A", Period "P", and duty cycle "D" (40%) that is a function of y(t) for some time period "t".

 

Can anyone help me out with this? 

 

Thanks,

Mike

 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:LucMeekes)


@LucMeekes wrote:

Worksheet(s) please...!

 

Luc


Here you are

I did no exact timing but it looks to me like calculations need much more time in Prime than in MC15

 

BTW, omitting the vertical line segments in a step function would be perfectly correct from a mathematical point of view but I understand that its undesirable for an engineer.

There is a simple cure, though.

My suggestion of a step width of 0,01 ms in the range was far too low. It should read 0.01 s which is good enough for the plots.

The range 0s, 0.01ms .. 4.2s forces the plot to be evaluated at 4.2 * 10^5 positions. Mathcad could handle that many points (nearly half a million) but Prime seems to have different limits and it falls back to this strange looking plot where you could not change anything (line style, thickness, .. ) other than the colour.

B1.png

Changing the range to read 0s,0.01 s .. 4.2 s gives us 421 points which is more than enough for this simple rectangular function. Changing the step width to 1 ms for 4201 points should be OK, too, of course.

B2.png

 

Even simple 2D plots always were one of the many drawbacks in Prime and PTC was not able or willing to improve it. You may have noticed that there are not axis labels, no grid lines, the possibilities to customize the plot are much more limited and simple things like changing the axis limits are much more cumbersome.

In Prime 5 PTC has introduced a third party diagram component (look at the "calculate" ribbon for it). I don't like this add-on as its very slow and laborious to handle, does not scale correctly when used with a high resolution 4K display (making it nearly unusable) and does not support units (a no-go in a program like Mathcad/Prime).

Nonetheless, if you decide that you like Prime despite its drawbacks, you may give this plot component a try, too.

 

 

View solution in original post

38 REPLIES 38
LucMeekes
23-Emerald III
(To:mlernst)

How about:

LM_20191116_Pulse.png

Success!
Luc

Luc,

 

Thank you for the solution. I see it works. I need it to be in the form of y(t)=. I tired to set y(t):= Pulse(t,A,T,d)

 

But that did not work. How can I accomplish this?

 

Thanks,

Mike

LucMeekes
23-Emerald III
(To:mlernst)

You need to fill in values for A, T and d.

Like

y(t):=Pulse(t,1.5,2,0.4)

if your amplitude is 1.5, your pulse duration is 2 and the duty cycle is 40 %.

There are several alternatives to the definition above. You could also define A, T and d with these or other values and - subsequently - define:

y(t):=Pulse(t,A,T,d)

You could define:

Grootte:=1.5

Pulsduur:=2

Werkingsfractie:=40*%

and then define:

y(t):=Pulse(Grootte,Pulsduur,Werkingsfractie)

 

I hope you get the point now. If you're still unsuccessful: post your worksheet.

 

Success!

Luc

Luc,

 

I had defined those values above and it was still not working. However, I did discover that the values for the time variable t, must come before the Pulse function. I had t after and it was not working. I moved Pulse down below where I set values for t and now it works.

 

I still have one issue though. In my worksheet I am using this function to describe a road surface, which is artificially created by having wooden boards 1: high by 12" wide placed on the surface of the road at a spacing of 30" center to center. So in this case A=1 inch, T= 30 inch, d= 2.5 (unitless). However, when I add the units, the Pulse no longer works. Am I doing something wrong or must Pulse have unitless variables?

 

Thanks again,

Mike

mlernst
7-Bedrock
(To:mlernst)

Luc,

 

I had two typos:

Boards are 1" high (not 1:)

d is 0.4 (not 2.5)

 

Period is 2.5 ft, peak width (top of pulse) is 1 ft

so 1 ft / 2.5 ft = 0.4, which is duty cycle

Werner_E
25-Diamond I
(To:mlernst)

I guess you could get help more to the point if you post your worksheet and also show what you are going to use your pulse-function for.

BTW, I only glanced over this thread but it could be that Luc's function should read pulse(t,A,T,d):=A* (mod(t,T)<d*T)

 

LucMeekes
23-Emerald III
(To:Werner_E)

You are right Werner. The example is ok only because I set T to 1.

Luc

Here is the worksheet I am trying to use. It is attached. I hope all can see it.

Werner_E
25-Diamond I
(To:mlernst)

I don't see where you implemented Luc's function. I just see an attempt to approximate the pulse via a partial sum of a fourier series.

What I noticed is this:

1) It seems that you wanted to define a range for t, but the region t:=0s,0.3s .. 4.2s is not a math region but is mere text. If you create a true range you should use a much smaller step size, like t:=0s,0.3 ms .. 4.2 s

2) If you define t as a range with the correct time unit, the plot "Road Contour as a Function of Distance" will fail because you used  "Displacement(X(t))" on the abscissa. I guess it should just be "Displacement(t)".

 

The name T for the period in distance is a bit misleading. As you want to define y as a function of time, the correct period seems to be T/speed.

Take a look at the attachment if it is what you are looking for.

B.png

 

 

mernst
2-Explorer
(To:Werner_E)

Werner_E,

 

When I was asked to post the worksheet, I had tried several different things suggested by both Luc and by -MFRa-. I guess I had deleted part of Luc's equation when I posted the worksheet here. But I had it in there at one time and it was not working with the units on the fixed value variables (A,T, etc.)

 

What I am trying to accomplish is this:

 

1) I want two equations one that describes the vertical displacement (amplitude, measured in length units) of a rectangular wave as a function of time and another as a function of distance (speed in mph times time in seconds, giving length)

 

2) In this problem I am "driving" the pictured Baja vehicle suspension over a road that has a washboard surface, created by a series of boards 1" high by 12" wide, spaced 30" apart when measured center to center. This essentially would a rectangular wave, right? I could ultimately create this road surface by placing these boards over a flat surface on the road. If you follow on down the worksheet you can see what I am ultimately doing with this.

 

I originally had the attached worksheet to describe the road surface, but wanted to change it to a "constructed" sinusoidal input that we are creating by the board surface. So that sinusoidal surface becomes a rectangular wave surface when created the way I describe. So to accomplish this I wanted to replace the y(t) function in the attached worksheet with a rectangular function and have the rest of the worksheet still be correct. I hope this now all makes sense.

 

Thanks,

Mike

 
 

 

mernst
2-Explorer
(To:Werner_E)

Werner_E,

 

That is awesome, and it does exactly what I want as far as I can tell.

 

Just out of curiosity, I noticed your comment near the bottom that says we need to use a larger time step there otherwise there would be too many points to plot. And you used 0.1, but suggested I could use 0.01, but that you were not patient enough for that to run. What version of Mathcad are you running? And are you using 32 or 64 bit? Reason I ask, we currently have version 15, but I have an 8 core processor running 64-bit Windows 10. I am wondering how much speed I would gain by upgrading to the current version 6 Prime.

LucMeekes
23-Emerald III
(To:mernst)

Mathcad 15 (and versions back to 4 or so)  is a 32-bit application. It is limited to using a single core, no matter how many cores your computer may have. If you run two instances of Mathcad 15 side by side, they can each use their own core though.

Prime versions 1 through 4 came in two flavours: 32 and 64-bit. Since Prime 5 it's only 64-bit (you cannot install Prime 5 or 6 on a 32-bit OS).

Regarding speed the story is complicated. Starting up the application, entering equations and especially number of mouse clicks to accomplish tasks, takes more in Prime than it does with Mathcad 15, as does closing the program. Once equations are entered, when it comes to actually calculating the same problem, it depends on whether or not the application can make use of multiple cores. There you might see Prime outperform Mathcad.

You can give it a try. Download and install Prime 6 and take (up to) 30 days to find out for yourself if it is an improvement for you. Note that using Prime is definitely a change with respect to Mathcad 15.

Note also that there is a migration path for mathcad sheets. You can convert a Mathcad .mcd or .xmcd sheet to a Prime .mcdx sheet, but there's no way back. Also there's no way from Prime 6 to save as a Prime 5 or less sheet.

 

Success!
Luc

 

Werner_E
25-Diamond I
(To:mernst)

I missed one error in the definition of your displacement function.

See the picture below or the attached sheet.

With this change its quite correct to use "Displacement(X(t))" in the second plot. But "Displacement(X(t))" should give you the very same result as "y(t)" 🙂

In the attached sheet I changed the displayed units to inch instead of feet as you give the measurement of the boards in inches. Not sure if this makes sense.

 

According the speed. Its the numerical integrations that take that much time. Every calculation of an integral means a lot of iterations to be done and this is done for every single point which is plotted. Thats the reason I suggested less values in the range variable t used for plotting. Prime should (not sure if it really does as we would like it to do) take advantage of more cores by multithreading and can use more RAM. But in my opinion "upgrading" to Prime would rather mean downgrading, considering the many missing features compared to Mathcad 15. I remember some threads here in the forum where multithreading was the cause for some troubles and it was suggested to turn it off. Can't remember the details, though.

But I suggest that you give it a try yourself. Download the trial version of Prime 6 (it will run in full mode for 30 days), convert your worksheet to Prime and see if the speed increases significantly.

Here the screen shot with the necessary change in the definition of "Displacement":

B.png

I am doing as both Luc and Werner_E suggested. I have a trial version of 6 Prime, and I have the worksheet converted. I have the exact some model of the road surface (rectangular wave) as in the file that Werner_E provided. However, for some strange reason - even though it plots fine in Mathcad 15, when it plots in 6 Prime, it only shows the horizontal parts of the graph. The vertical parts are gone. Any idea how to get them to plot?

LucMeekes
23-Emerald III
(To:mlernst)

Worksheet(s) please...!

 

Luc

Werner_E
25-Diamond I
(To:LucMeekes)


@LucMeekes wrote:

Worksheet(s) please...!

 

Luc


Here you are

I did no exact timing but it looks to me like calculations need much more time in Prime than in MC15

 

BTW, omitting the vertical line segments in a step function would be perfectly correct from a mathematical point of view but I understand that its undesirable for an engineer.

There is a simple cure, though.

My suggestion of a step width of 0,01 ms in the range was far too low. It should read 0.01 s which is good enough for the plots.

The range 0s, 0.01ms .. 4.2s forces the plot to be evaluated at 4.2 * 10^5 positions. Mathcad could handle that many points (nearly half a million) but Prime seems to have different limits and it falls back to this strange looking plot where you could not change anything (line style, thickness, .. ) other than the colour.

B1.png

Changing the range to read 0s,0.01 s .. 4.2 s gives us 421 points which is more than enough for this simple rectangular function. Changing the step width to 1 ms for 4201 points should be OK, too, of course.

B2.png

 

Even simple 2D plots always were one of the many drawbacks in Prime and PTC was not able or willing to improve it. You may have noticed that there are not axis labels, no grid lines, the possibilities to customize the plot are much more limited and simple things like changing the axis limits are much more cumbersome.

In Prime 5 PTC has introduced a third party diagram component (look at the "calculate" ribbon for it). I don't like this add-on as its very slow and laborious to handle, does not scale correctly when used with a high resolution 4K display (making it nearly unusable) and does not support units (a no-go in a program like Mathcad/Prime).

Nonetheless, if you decide that you like Prime despite its drawbacks, you may give this plot component a try, too.

 

 

I am good with the solution that was proposed. However, the ultimate goal was to get a plot of the acceleration of b(t). And with the pulse function, I kept getting discontinuities. And it took 3 or more hours to calculate.

 

So i tried to generate a Fourier series, and I found one that worked, although it is an even function, and I needed an odd one. But for now, I went ahead and used it. I was trying to use an odesolve but I am having trouble understanding it. Take a look at my attached worksheet. Keep in mind that the goal is a plot of the second derivative of v(t) - that is v''(t). Can someone help me with the remainder of the worksheet to get me there?

 

Thanks,

Mike

Werner_E
25-Diamond I
(To:mlernst)

OK, where should I begin

 

.) For the equations in a solve block you have to use the (fat) boolean equal sign

.) y(t) is an already defined function you do not solve for. So you can't demand y(0)=0

.) The syntax for a system of ODEs is wrong. You have TWO functions to solve for (v and w) and so you have to use the syntax appropriate for a system of ODEs which you can easily look up in the help and the quicksheets provided.

.) Two typos (I guess): 1) c(x) which maybe should be v(x) ? and 2) k1 which sure should have been k.1

.) The bad news: A solve block with "odesolve" must be used unitless. Thats a real bad drawback of Mathcad and is one of the few improvements in Prime wher you can use units. So you may consider stripping off all units in the expressions in the solve block by dividing by the appropriate unit and later add the correct units to the solved for function. As this was too much hassle for me I simply stripped all the units from the very beginning 😉

.) With the initial conditions you provide both solution functions will be constant zero. So I changed one of them arbitrarily to w(0)=5 so you can see that the solve block is really working.

 

MC15 sheet attached.

Werner_E,

 

Thank you again for all your help. As always, you make it easy for me to understand. I tried to figure this out with the help but it was not obvious to me what was wrong. I do now see the fat equal signs, but unless you are looking for them they are easy to overlook. And I do not see anywhere that it is pointed out to use them. Did I miss it somewhere?

 

I still have on final question. Ultimately, what I need is v''(t) - acceleration. Do I just solve for that with odesolve instead of v(t), or do I need another solveblock, or what?

 

Thanks again,

Mike

mlernst
7-Bedrock
(To:mlernst)

Werner_E,

 

Thanks, I think I figured it out. I just added an additional graph below your two and made it a plot of the second derivative of v(t) vs. t and it plots fine. So I guess it is already calculated in the Odesolve block, and plotting it shows me the results.

 

Thanks again do much for your time.

 

Mike

Werner_E
25-Diamond I
(To:mlernst)

v'' or any other function is not explicitely calculated in the solve block, but what a solve block with odesolve delivers basically is a number of points and the function simply interpolates between those points.

A derivative is only done numerically based on the points calculated. You can also integrate the function if you like - all done just numerically.

Its a pity that Mathcad can't solve ODEs symbolically, but of course numeric solutions often are good enough for our needs.

Werner,

 

I am attaching another model I have been working on (basically the latest one you posted, I have just modified some of the initial constants). I have a procedural question. Near the top of the worksheet is a variable named c2.

 

It is the value of a typical shock absorber like would be on a car. Currently I have it as a fixed value. However, in reality a shock absorber's damping value is a function of velocity (in my case, v(t). Since it is being used to calculate v(t), I assume I cannot make it a function of v(t)? If not, then can I at least make it one value if v(t) is positive and a different value if v(t) is negative? If so, how would I do that? Would I set it's as a matrix with one value for v(t)>0 and another for v(t)<0?


Thanks again for all your help.

 

Mike

 

mlernst
7-Bedrock
(To:mlernst)

In my previous post I misspoke. It is a function of velocity, and of the sign of the velocity. So if velocity is positive (increasing), it is one range of values, and if velocity is negative (decreasing), it is a different range of values.


If I cannot do that, then can I set it so that if the v(t) - w(t) is increasing (in other words if the shock is being compressed) it is one constant value, and if v(t) - w(t) is decreasing (shock is being extended) , then it is a different value.

 

Thanks,

Mike

Werner_E
25-Diamond I
(To:mlernst)

You may make c2(t) a third function of your solve block if you can formulate an equation how c2 is dependent on v.

 

Another way (not sure if thats applicable) could be to make the solve block a function of c2, so you can solve it for different values of c2.

But you can't decide which value c2 should have after you calculated v(t) as the calculation of v(t) uses the value of c2.

So you either

.) use a constant value throughout the solve block

.) or you define c2 as a function of t

.) or you set up c2 as an unknown function of t, provide an equation showing the relationship between c2 and v and use odesolve to solve for v, w and c2.

 

Werner_E
25-Diamond I
(To:Werner_E)

here is an attempt to do what I think you are looking for. You sure have to change the function c2(v) to your needs.

 

Werner,

 

Is there a way to have c2(t) be one of 2 values, as follows:

 

If v(t) - w(t) > v(t-delta t) - w(t-delta t) then c2(t) = 412.7

Otherwise c2(t) = 1615

 

 

Thanks,
Mike

LucMeekes
23-Emerald III
(To:mlernst)

Sure,

use the 'if' function: if( <condition> , <value if true> , value if false> )

In your case:

 

LM_20191127_Condition.png

 

Success!
Luc

Luc,

 

When I put that in the previously posted worksheet, the v(t) turns red and tells me it is undefined.

Werner_E
25-Diamond I
(To:mlernst)

You would have to provide a value for delta_t.

I am not sure if the numeric algorithm used in the odesolve-block will be able to handle a function with that discontinuity, jumping all of a sudden from 400 to 1600.

You may give it a try and if it does not work you may try using a function with a steep slope instead.

Furthermore ... how should Mathcad know v(t-delta_t) at the start, when t=0 ??

Maybe you can try to formulate the condition differently. In a previous post you said the trigger would be just the sign of v(t).

Maybe you can use v'(t) > w'(t) to achieve what you are looking for? See below

B.png

MC sheet in version 11 attached (for Luc to be able to join in 🙂

Announcements

Top Tags