I have some rather complicated function (related to the capacitance of coplanar waveguides for specific geometric parameters, for those who are interested) which I've trimmed down to the following for simplicity:
SampleFun[w_, s_, g_, h2_] := Module[{a, b, c0, k2, k2p, k4, k4p, q2},
a = s/2;
b = s/2 + w;
c0 = g + w + s/2;
k2 = a/b*Sqrt[(1 - b^2/c0^2)/(1 - a^2/c0^2)];
k2p = Sqrt[1 - k2^2];
k4 = Sinh[Pi*a/2/h2]/Sinh[Pi*b/2/h2]*
Sqrt[(1 - Sinh[Pi*b/2/h2]^2/Sinh[Pi*c0/2/h2]^2)/(
1 - Sinh[Pi*a/2/h2]^2/Sinh[Pi*c0/2/h2]^2)];
k4p = Sqrt[1 - k4^2];
q2 = EllipticK[k4]/EllipticK[k4p]*1/2*EllipticK[k2p]/EllipticK[k2];
Return[q2]]
The source of the equation is a combination of theory found in Gevorgian et al (1995) (fairly legible) and Garg et al (1979) around p. 376. In its entire form it will give the capacitance per unit length of a coplanar waveguide resonator with finite ground planes and a double layered substrate of finite thicknesses.
Now, since this function depends sensitively on the geometric input parameters, lets say that we can always take w = 1500*10^-9
, s = 30*10^-6
, g = 50*10^-6
, and h2
is a number that goes from 0
(lets take 0.1*10^-9
as we can't divide by 0) to 400*10^-9
for the range that I am interested in.
If we look at the function in this range, then it behaves in a peculiar way; for low values there seems to be an error in the calculation, and it gives exactly 0.
Does anyone understand what is going on here, and how I could go about fixing it? I believe the problem stems from the EllipticK[k4p]
part, as the rest seems to evaluate nicely, but it might be a combination of factors so I didn't leave out more. It is quite problematic for my calculation, as h2
is approximately 100*10^-9
in the geometry I am considering, which falls exactly in this gap.
Note, this is for Mathematica 10.0.2, which now that I write it I should definitely update as it might be something that is fixed in future versions.
Re
. Nonetheless I find you've defined your function in a suboptimal way. $\endgroup$Plot[SampleFun[1500 10^-9, 30 10^-6, 100 10^-3, x 10^-9], {x, 1, 500}, WorkingPrecision -> 25]
$\endgroup$