Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
I have two similar integrals, one with sin function and one with cos function, but for some reason integral with cos causes an error, but with a sin does not. I would be very grateful for help. Integrals are at the end of the attached worksheet. I'm using MathCad Prime 11 if it matter
Solved! Go to Solution.
The error stems from the numeric algorithm used for the integration.
If fails for k=15 We have often seen this behavior in non-continuous integrands.
In your case it helps to change the value of the system variable TOL (default is 10-3).
Interestingly the calculation does not only converge if we set it to a larger value like 10-2 but it also works with TOL = 10-4.
You can set the value via the menu or simply write TOL:=10-4 somewhere at the top of the sheet (at least in front of the integral),
Now you can define the FOURIER approximation of the periodic signal and compare the results with the original signal.
Or even better make advantage of the symmetry of the signal (no sine wave components.
Just for demonstration I turned A into a function of k. While this may be more compact, needs no range variable and does not limit N, its less efficient and much more time consuming because A has to be calculated from anew every time f(t,..) is called.
You may also increase the accuracy of the numerical integration if you use ti as upper integral limit instead of T/2 (the integrand is now continuous).
The approach of using symmetry and to integrate from 0 to T/2 or ti works OK even with the default value for TOL.
Now that we have limited the signal to one simple linear function only, we can also use Prime's symbolics (would not work using the "if" statement in the definition of the signal).
Prime 11 sheet attached
Note that B[k=0 for all your k.
For some reason Prime has a problem with calculating A[15 (that is, A for k=15).
If you limit k to 14, you'll get a result.
You may also get a result if you set t.i to 14.999...
Probably a numerical error.
Success!
Luc
The error stems from the numeric algorithm used for the integration.
If fails for k=15 We have often seen this behavior in non-continuous integrands.
In your case it helps to change the value of the system variable TOL (default is 10-3).
Interestingly the calculation does not only converge if we set it to a larger value like 10-2 but it also works with TOL = 10-4.
You can set the value via the menu or simply write TOL:=10-4 somewhere at the top of the sheet (at least in front of the integral),
Now you can define the FOURIER approximation of the periodic signal and compare the results with the original signal.
Or even better make advantage of the symmetry of the signal (no sine wave components.
Just for demonstration I turned A into a function of k. While this may be more compact, needs no range variable and does not limit N, its less efficient and much more time consuming because A has to be calculated from anew every time f(t,..) is called.
You may also increase the accuracy of the numerical integration if you use ti as upper integral limit instead of T/2 (the integrand is now continuous).
The approach of using symmetry and to integrate from 0 to T/2 or ti works OK even with the default value for TOL.
Now that we have limited the signal to one simple linear function only, we can also use Prime's symbolics (would not work using the "if" statement in the definition of the signal).
Prime 11 sheet attached
What happens if you choose an alternative integration method (I've only got Mathcad Express, so can't check)?
(right-click on integral to bring up the context menu)
Stuart
@StuartBruff wrote:
What happens if you choose an alternative integration method (I've only got Mathcad Express, so can't check)?
Unfortunately none of the options would do the trick. As explained above, changing TOL from 10^-3 to another value (either larger or smaller - the latter was a surprise!) cures that problem. We have seen it quite often here when dealing with discontinuities in the integrand. In combination with the quite small abscissa values involved inaccuracies and nasty round-offs are to expected anyway.
