Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X
Hello,
????
How can I extend the above x(t,...) signal which is defined from -pi to pi to a periodic one so that I can display more periods of the signal, as it is shown below?
Mathcad Prime 8 file attached.
Thank you.
Solved! Go to Solution.
How can I extend the above x(t,...) signal which is defined from -pi to pi to a periodic one so that I can display more periods of the signal, as it is shown below?
If its just for displaying the graph, here are a few ways to turn a piece of a function periodic.
I created utility functions which expect a function with just one argument.
The first way uses the floor function
Another possibility would be to use the mod function. Because its implemented in Prime in a way to return negative values for negative arguments (which is undesirable here), I used it twice, adding the period for the second time to be sure to avoid negative values.
You may also use a recursive approach, but I would not suggest doing so
You could achieve the same effect as in the recursive approach by using a while loop
Attached sheet is in Prime 9 format
In the attached pdf, from page 12 onwards, there are numerous examples:
Ok. Thank you. But now I am interested in the extension of the periodicity to start from my function defined above (x(t,...)) and adapted in order to be able to display 2 periods, or 3 periods, etc.
Hi,
To plot the periodic function try this:
To plot one or more periods restrict the variable t to a given range.
How can I extend the above x(t,...) signal which is defined from -pi to pi to a periodic one so that I can display more periods of the signal, as it is shown below?
If its just for displaying the graph, here are a few ways to turn a piece of a function periodic.
I created utility functions which expect a function with just one argument.
The first way uses the floor function
Another possibility would be to use the mod function. Because its implemented in Prime in a way to return negative values for negative arguments (which is undesirable here), I used it twice, adding the period for the second time to be sure to avoid negative values.
You may also use a recursive approach, but I would not suggest doing so
You could achieve the same effect as in the recursive approach by using a while loop
Attached sheet is in Prime 9 format
I do not have at this moment Mathcad Prime 9, but just Mathcad Prime 8. So, I cannot open Mathcad Prime 9 file. But I inserted the mkPer1 function you wrote.
a)
Here I do not know why signalp(t) shows these discontinuities.
b)
c)
Mathcad Prime 8 file attached.
@Cornel wrote:
I do not have at this moment Mathcad Prime 9, but just Mathcad Prime 8.
That was the reason for the pictures I attached 😉
Here I do not know why signalp(t) shows these discontinuities.
Actually the signal IS NOT continuous. The vertical line segments which you seem to be missing would be incorrect from a mathematical point of view. But Prime omits these lines not because its so clever as we can see in the other examples.
Actually I don't know how plotting is implemented, so we can tell when vertical lines would be plotted and when not.
In my original file the verticals were missing when I used the quickplot feature but, as you could see in the picture, they were plotted when I defined a range for the abscissa values t.
When I opened your sheet and defined a range, nothing changed - the vertical lines still were not plotted.
I also tried modifying your function definition, but as you can see in the next pic, the vertical lines are still missing partially for the periodic signalp(t), but it IS drawn in the plot of signal(t), The verticals are now drawn to connect the periodic parts, but not in the parts themselves. Can't explain why.
But then, the 2D plots in Prime have also other disadvantages and strange bugs (one is mentioned in my last picture). It sure isn't a masterpiece of programming.
OK, if you really need the verticals, you may play around with the step width of the range.
It looks the when the t-value for the verticals is part of the range, a vertical is drawn.
Is it necessary that NaN? I tried also without this NaN in the x(t,...) function and it works.
If you try my approach without the NaN by simply deleting it you will get an error.
In your approach with the local variable x which you return at the end, you return zero if t is not in the range a..c.
My intention was to just plot the original function within the range a..c and I did not want to have the zero line otherwise. So I return NaN in hat case which avoids plotting anything.
You can achieve the same effect as in your approach if you return 0 instead of NaN at the end
I mean this:
The two above implementations return the same result, but one implementation is with NaN and the other without NaN at the end of the function.
Yes, omitting NaN returns an error if you evaluate is at a position outside of the range a..c
But these errors are ignored by the plot region (similar to the NaN's).
Nonetheless a function using "if" should always return values for all possible input values.
Ok. Now I understand this.
Which is better to use further between the two implementations: x1 or x2? I mean the type of programming...with which it is better to stay with? Or does not matter?
Personally I would prefer x1 for some reasons:
1) its more efficient to leave the program immediately after a condition is fulfilled (which return is doing) and not checking all the subsequent conditions. I would use a normal "if" instead of the "if else".
2) We spare the local variable x
3) We have better control as to which value should be returned if t is not in [a; c]. Of course you could put x <-- Nan (or whatever) as first line in x2 to achieve the same effect.
But at the end, I guess its just a matter of personal preference.
Solved: Total Harmonic Distortion of AC current using Four... - PTC Community
This is the one with your waveform.
It seems to me that you are looking for something like this (see photo) and open the attached file (for M15):