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

Integration with if function

blu-2
1-Newbie

Integration with if function

I am trying to do some simple math to integrate a step change function using Mathcad 15.

The problem as simple as a capacitor has two values, at a threshold voltage.

When the voltage is below one value, say 20V, the capacitor is large, say 40pF

When the voltage is above the threshold, 20V, the capacitor is small, say 20pF.

To calculate the charge in the cap as a function of capacitor voltage, I can do it two ways.

1, Define the capacitor value as a function of voltage and describe it as if function. Then integrate the capacitor with voltage to get charge.

2. directly integrated capacitor with voltage and put the if function in the integration equation.

The two results are very similar, however, the method one has significant error comparing with second method. See the attachment.

Is there any thing wrong with the algorithms inside the Mathcad that having trouble to handling the if function inside integration? I am using the integration with if function a lot and really concerning on the accuracy of the math.

Thanks.

Bing

1 ACCEPTED SOLUTION

Accepted Solutions
Werner_E
24-Ruby IV
(To:blu-2)

This accuracy problem can be fixed by changing the default value for TOL (which is 10^-3) to a much lower value which fits the magnitude of your data.

Set TOL:=10^-12 or lower at the top of your sheet and you will get what you expect.

Anyway its a strange effect. I would have expected similar inaccuracies with both methods.

View solution in original post

3 REPLIES 3
Fred_Kohlhepp
23-Emerald I
(To:blu-2)

I'm not sure exactly what you're doing, but integrating over voltage is problematic--this is a time variant problem:

If you're integrating C dV, then the plot of q vs V should show a slope change when C changes (at 20 volts), and it does.  Why one of your functions shows a stepping plot I haven't figured out.

Werner_E
24-Ruby IV
(To:blu-2)

This accuracy problem can be fixed by changing the default value for TOL (which is 10^-3) to a much lower value which fits the magnitude of your data.

Set TOL:=10^-12 or lower at the top of your sheet and you will get what you expect.

Anyway its a strange effect. I would have expected similar inaccuracies with both methods.

blu-2
1-Newbie
(To:Werner_E)

Thanks. This makes sense.

It is interesting to observe that the tolerance can affect how the math goes. I'll make sure to adjust the tolerance in the future when I deal with small numbers.

Announcements
Check out the latest
Mathcad Tip
"PTC Mathcad 15 / Prime 1-6 Update."