Skip to main content
1-Visitor
December 17, 2025
Solved

Integral is not converging to a solution

  • December 17, 2025
  • 3 replies
  • 332 views

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

Best answer by Werner_E

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

3 replies

23-Emerald IV
December 17, 2025

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_E25-Diamond IAnswer
25-Diamond I
December 17, 2025

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

23-Emerald V
December 18, 2025

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

25-Diamond I
December 18, 2025

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