coil.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Program to calculate the inductance of a coil
  2. *
  3. * Reference: E. Jahnke and F. Emde, _Tables of Functions_,
  4. * 4th edition, Dover, 1945, pp 86-89.
  5. */
  6. double sin(), cos(), atan(), ellpe(), ellpk();
  7. double d;
  8. double l;
  9. double N;
  10. /* double PI = 3.14159265358979323846; */
  11. extern double PI;
  12. main()
  13. {
  14. double a, f, tana, sina, K, E, m, L, t;
  15. printf( "Self inductance of circular solenoidal coil\n" );
  16. loop:
  17. getnum( "diameter in centimeters", &d );
  18. if( d < 0.0 )
  19. exit(0); /* escape gracefully */
  20. getnum( "length in centimeters", &l );
  21. if( d < 0.0 )
  22. exit(0);
  23. getnum( "total number of turns", &N );
  24. if( d < 0.0 )
  25. exit(0);
  26. tana = d/l; /* form factor */
  27. a = atan( tana );
  28. sina = sin(a); /* modulus of the elliptic functions (k) */
  29. m = cos(a); /* subroutine argument = 1 - k^2 */
  30. m = m * m;
  31. K = ellpk(m);
  32. E = ellpe(m);
  33. tana = tana * tana; /* square of tan(a) */
  34. f = ((K + (tana - 1.0) * E)/sina - tana)/3.0;
  35. L = 4.e-9 * PI * N * N * d * f;
  36. printf( "L = %.4e Henries\n", L );
  37. goto loop;
  38. }
  39. /* Get value entered on keyboard
  40. */
  41. getnum( str, pd )
  42. char *str;
  43. double *pd;
  44. {
  45. char s[40];
  46. printf( "%s (%.10e) ? ", str, *pd );
  47. gets(s);
  48. if( s[0] != '\0' )
  49. {
  50. sscanf( s, "%lf", pd );
  51. printf( "%.10e\n", *pd );
  52. }
  53. }