Scientific Calculator
jimofadel/Jim3
By jimofadelay
EE functions
Tagged:
//Rstd(r) returns the closest standard resistor value to given r
//uses standard 1% (E96) values, but limited to 24 values per decade (10% intervals)
Rstd=function(r) {
r < 1 ?
(
error("not valid for r < 1");
):(r=r);
n=range(0,25);
Rval=10^(n/24);
m=1;
while (m < 27) -> (
rx=round(Rval[m]*100)/100; //round to 3 sig. digits
Rval[m]=rx;
m=m+1;
);
dec=ipart(log10(r));
Rvals=Rval*10^dec;
D = Rvals-r;
done=0;
xover=[0,0];
Rs=Rvals(1);
j = 1;
err="done";
while (( j < 24.5) and (done==0) ) -> (
(abs(D(1)) < .05*r)and(j=1) ?
(
Rs = Rvals(j);
done = 1;
):
(done = 0;
);
D(j+1) > 0 ?
(
xover=[j,j+1];
abs(D(j)) < abs(D(j+1)) ?
(
done=1;
Rs=Rvals(j);
) :
(
Rs=Rvals(j+1);
done=1;
) ;
) :
(
done=0;
) ;
j=j+1;
); // end while
output=[Rs];
output;
}; //end function
//vout returns the output voltage of a regulator given divider resistors and reference
vout=function(Rtop,Rbot,Vref) {
Vref+Rtop*(Vref/Rbot);
};
//Xc returns capacitive reactance given capacitance and frequency
Xc=function(c,f) {
1/(2*pi*f*c);
};
//Xl returns inductive reactance given inductance and frequency
Xl=function(l,f) {
2*pi*f*l;
};
//Cx returns capacitance required for given reactance and frequency
Cx=function(x,f) {
1/(2*pi*f*x);
};
//Lx returns inductance required for given reactance and frequency
Lx=function(x,f) {
x/(2*pi*f);
};
//divr returns ratio provided by given resistors of a simple divider
divr = function(Rtop,Rbot) {
Rbot/(Rbot+Rtop);
};
//par returns the resistance of a and b in parallel
par = function(a,b) {
a*b/(a+b);
};
//diss returns dissipation of a regulator with given output power and efficiency
diss=function(pout,eff) {
(pout/eff - pout);
};
//Cstd returns closest standard capacitor value to given c
Cstd=function(c) {
c<1 ? (c=c):(error("C must be < 1"));
Cval=[1,1.2,1.5,1.8,2.2,2.7,3.3,3.9,4.7,5.6,6.8,8.2,10];
dec=ipart(log10(c))-1; //c < 1
Cvals=Cval*10^dec;
D = Cvals-c;
done=0;
xover=[0,0];
Cs=Cvals(1);
j = 1;
err="done";
while (( j < 13.5) and (done==0) ) -> (
(abs(D(1)) < .05*c)and(j=1) ?
(
Cs = Cvals(j);
done = 1;
):
(done = 0;
);
D(j+1) > 0 ?
(
xover=[j,j+1];
abs(D(j)) < abs(D(j+1)) ?
(
done=1;
Cs=Cvals(j);
) :
(
Cs=Cvals(j+1);
done=1;
) ;
) :
(
done=0;
) ;
j=j+1;
); // end while
output=[Cs];
output;
}; //end function
0 Comments
Sign in to leave a comment