summaryrefslogtreecommitdiff
path: root/libm/double/coil.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-05-10 00:40:28 +0000
committerEric Andersen <andersen@codepoet.org>2001-05-10 00:40:28 +0000
commit1077fa4d772832f77a677ce7fb7c2d513b959e3f (patch)
tree579bee13fb0b58d2800206366ec2caecbb15f3fc /libm/double/coil.c
parent22358dd7ce7bb49792204b698f01a6f69b9c8e08 (diff)
uClibc now has a math library. muahahahaha!
-Erik
Diffstat (limited to 'libm/double/coil.c')
-rw-r--r--libm/double/coil.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/libm/double/coil.c b/libm/double/coil.c
new file mode 100644
index 000000000..f7156497c
--- /dev/null
+++ b/libm/double/coil.c
@@ -0,0 +1,63 @@
+/* Program to calculate the inductance of a coil
+ *
+ * Reference: E. Jahnke and F. Emde, _Tables of Functions_,
+ * 4th edition, Dover, 1945, pp 86-89.
+ */
+
+double sin(), cos(), atan(), ellpe(), ellpk();
+
+double d;
+double l;
+double N;
+
+/* double PI = 3.14159265358979323846; */
+extern double PI;
+
+main()
+{
+double a, f, tana, sina, K, E, m, L, t;
+
+printf( "Self inductance of circular solenoidal coil\n" );
+
+loop:
+getnum( "diameter in centimeters", &d );
+if( d < 0.0 )
+ exit(0); /* escape gracefully */
+getnum( "length in centimeters", &l );
+if( d < 0.0 )
+ exit(0);
+getnum( "total number of turns", &N );
+if( d < 0.0 )
+ exit(0);
+tana = d/l; /* form factor */
+a = atan( tana );
+sina = sin(a); /* modulus of the elliptic functions (k) */
+m = cos(a); /* subroutine argument = 1 - k^2 */
+m = m * m;
+K = ellpk(m);
+E = ellpe(m);
+tana = tana * tana; /* square of tan(a) */
+
+f = ((K + (tana - 1.0) * E)/sina - tana)/3.0;
+L = 4.e-9 * PI * N * N * d * f;
+printf( "L = %.4e Henries\n", L );
+goto loop;
+}
+
+
+/* Get value entered on keyboard
+ */
+getnum( str, pd )
+char *str;
+double *pd;
+{
+char s[40];
+
+printf( "%s (%.10e) ? ", str, *pd );
+gets(s);
+if( s[0] != '\0' )
+ {
+ sscanf( s, "%lf", pd );
+ printf( "%.10e\n", *pd );
+ }
+}