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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Wrong result in integral exp(-x)

DM_10127316
7-Bedrock

Wrong result in integral exp(-x)

Hi,

I have been updating a Mathcad sheet and noticed that there are slight discrepancies in the results on the order of 1e-6. I tracked the source of this error and I got to this integral (shown below).

 

There are two things I do not understand:

1.- Function A and B are the same but for some reason B throws an error "this value must be an integer".

2.- The integral should be equal to 1 when the upper limit is approx higher than 5. But for some reason the solution jumps from 1 to 5e-4 when the upper limit goes from 1.011e4 to 1.013e4, which is wrong. It should be 1.

 

I am using Prime 8.0

 

Regards,

 

 

DM_10127316_1-1719346204470.png

 

1 ACCEPTED SOLUTION

Accepted Solutions


@DM_10127316 wrote:

Hi,

I have been updating a Mathcad sheet and noticed that there are slight discrepancies in the results on the order of 1e-6. I tracked the source of this error and I got to this integral (shown below).

 

There are two things I do not understand:

1.- Function A and B are the same but for some reason B throws an error "this value must be an integer".

2.- The integral should be equal to 1 when the upper limit is approx higher than 5. But for some reason the solution jumps from 1 to 5e-4 when the upper limit goes from 1.011e4 to 1.013e4, which is wrong. It should be 1.

 

I am using Prime 8.0

 

Regards,


ad 1.)  You used the literal index when you typed B.ii but you should have used the matrix/vector index as you did in A[ii.

 

ad 2.) Numerical math approx algorithms always are good for strange effects. You can cope with that problem by decreasing the value of the system variable TOL from its default value 10^-3 to something like 10^-6

Werner_E_0-1719359153506.png

 

I won't call this a bug, its simply a a natural side effect of the algorithm used for numerical integration.
If its just this simple integral, I would suggest to replace it by the exact expression 1-e^-t.

We experience the same effect in real Mathcad when using the default tolerance setting of 10^-3. Here a screenshot of Mathcad 15:

Werner_E_3-1719360130821.png

View solution in original post

5 REPLIES 5
ttokoro
20-Turquoise
(To:DM_10127316)

Prime 10 also has this bug.

image.png

image.png

image.png


@DM_10127316 wrote:

Hi,

I have been updating a Mathcad sheet and noticed that there are slight discrepancies in the results on the order of 1e-6. I tracked the source of this error and I got to this integral (shown below).

 

There are two things I do not understand:

1.- Function A and B are the same but for some reason B throws an error "this value must be an integer".

2.- The integral should be equal to 1 when the upper limit is approx higher than 5. But for some reason the solution jumps from 1 to 5e-4 when the upper limit goes from 1.011e4 to 1.013e4, which is wrong. It should be 1.

 

I am using Prime 8.0

 

Regards,


ad 1.)  You used the literal index when you typed B.ii but you should have used the matrix/vector index as you did in A[ii.

 

ad 2.) Numerical math approx algorithms always are good for strange effects. You can cope with that problem by decreasing the value of the system variable TOL from its default value 10^-3 to something like 10^-6

Werner_E_0-1719359153506.png

 

I won't call this a bug, its simply a a natural side effect of the algorithm used for numerical integration.
If its just this simple integral, I would suggest to replace it by the exact expression 1-e^-t.

We experience the same effect in real Mathcad when using the default tolerance setting of 10^-3. Here a screenshot of Mathcad 15:

Werner_E_3-1719360130821.png

That was it! Thank you for your response, Extremely helpful.

Unfortunately, the integral is part of a bigger one and I cant replace with its exact expression. But changing TOL helps a lot.

OK, but keep in mind that the default value 10^-3 normally is well chosen. Setting TOL at a value too small may result in some numerical calculations like integrals, solve blocks, etc.  failing because "the calculation does not converge to a solution". So handle with care 😉

ttokoro
20-Turquoise
(To:DM_10127316)

 

Ans0 is TOL=1

Ans7 is TOL=10^-7.

 

image.png

Top Tags