# Re: formulas (fwd)

```

---------- Forwarded message ----------
Date: Sun, 12 Jul 98 20:46:30 EDT
From: Jim Monte <JDM95003-at-UCONNVM.UCONN.EDU>
To: tesla-at-pupman-dot-com
Subject: Re: formulas

>Date: Sat, 11 Jul 1998 00:19:55 -0500
>From: Shaun <shaunobrien-at-geocities-dot-com>
>To: Tesla List <tesla-at-pupman-dot-com>
>Subject: Formula's
>
>
>    Anyone happen to have the formula for finding the inductance
>of a cone primary? I saw it once before but I don't remember where.
I can't seem to find that one.
>Also I can't remember how to find the length of a sprial. I also need
>to find the length for the primary.
>
Here is a short C program that compares the exact length of wire to
an approximate value (underestimate) using the mean diameter*pi*#turns.
The input and output aren't the prettiest, but there is some built-in
help and good argument checking.  The program had to tolerate an ASCII ->
EBCIDIC translation.  If you try to compile the program and get errors,
check braces and brackets, which don't always translate well.

Jim Monte
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
/**/
#include <math.h>
#include <stdio.h>
#include <errno.h>
#define f(x) sqrt((x)*(x)+k*k+A*A)
#define A (H/(2*pi*N))
#define k ((Ro-Ri)/(2*pi*N))
int main(int argc, char *argv›!);

int main(int argc, char *argv›!){
int rc;
const double pi=3.141592653589793238462643383279502884197169;
double H,L,La,N,Ro,Ri,log_term;

/* Input and check line arguments.  Exit on error */
if(argc|=5){
rc=4;
goto output_format;
}
if(sscanf(argv›1!,"%lf",&N)|=1){
(void)fprintf(stderr,"Error:  the number of turns \"%s\" is invalid\n",
argv›1!);
rc=8;
goto output_format;
}
if(N<0){
(void)fprintf(stderr,"Error:  the number of turns must be nonnegative"n");
rc=8;
goto output_format;
}
if(sscanf(argv›2!,"%lf",&Ri)|=1){
(void)fprintf(stderr,"Error:  the inner radius \"%s\" is invalid\n",
argv›2!);
rc=8;
goto output_format;
}
if(Ri<0){
(void)fprintf(stderr,"Error:  the inner radius must be nonnegative"n");
rc=8;
goto output_format;
}
if(sscanf(argv›3!,"%lf",&Ro)|=1){
(void)fprintf(stderr,"Error:  the outer radius \"%s\" is invalid\n",
argv›3!);
rc=8;
goto output_format;
}
if(Ro<=0){
(void)fprintf(stderr,"Error:  the outer radius must be positive"n");
rc=8;
goto output_format;
}
if(Ro<Ri){
(void)fprintf(stderr,
rc=8;
goto output_format;
}
if(sscanf(argv›4!,"%lf",&H)|=1){
(void)fprintf(stderr,"Error:  the coil height \"%s\" is invalid\n",
argv›4!);
rc=8;
goto output_format;
}
if(H<0){
(void)fprintf(stderr,"Error:  the coil height must be nonnegative\n");
rc=8;
goto output_format;
}

/* Echo inputs */
(void)fprintf(stdout,
N,Ri,Ro,H);

/* Calculate wire length */
if(N>0.0) /* if # turns >0 */
errno = 0; /* clear error flag before call to log */
log_term=log((f(Ro)+Ro)/(f(Ri)+Ri));
if(errno) /* error raised indicates log argument too close to 0 */
L=2*pi*N*sqrt(Ri*Ri+A*A); /* treat as Ro = Ri */
else /* log calculated OK */
L=(Ro*f(Ro)-Ri*f(Ri))/(2*k) + (k*k+A*A)/(2*k)*log_term;
}
L=2*pi*N*sqrt(Ri*Ri+A*A);
else
L=sqrt((Ro-Ri)*(Ro-Ri)+H*H); /* 0 turn case */
La=(Ri+Ro)*N*pi;
(void)fprintf(stdout,
"Exact wire length=      %lf\n"
"Approximate wire length=%lf\n"
"%% error=                %lf\n",
L,La,100.0*fabs(L-La)/L);
return 0;

output_format:
(void)fprintf(stderr,
"Function:  Determine the length of wire or tubing needed to "
"wind a coil\n"
"Format:  %s <number turns> <inner radius>"