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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Translate the entire conversation x

Integral is not converging to a solution

OB_14322202
2-Explorer

Integral is not converging to a solution

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

ACCEPTED SOLUTION

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

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.

Werner_E_0-1766011992857.png

Werner_E_0-1766012884325.png

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.

Werner_E_0-1766014251274.png

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

Werner_E_0-1766014975821.png

 

 

 

 

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

Werner_E_1-1766016301575.png

 

 

Prime 11 sheet attached

View solution in original post

4 REPLIES 4
LucMeekes
23-Emerald IV
(To:OB_14322202)

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

Werner_E
25-Diamond I
(To:OB_14322202)

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.

Werner_E_0-1766011992857.png

Werner_E_0-1766012884325.png

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.

Werner_E_0-1766014251274.png

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

Werner_E_0-1766014975821.png

 

 

 

 

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

Werner_E_1-1766016301575.png

 

 

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)

 

2025 12 19 A.png

 

Stuart

Werner_E
25-Diamond I
(To:StuartBruff)


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

Announcements

Top Tags