Wednesday, October 20, 2021

Coupled inductors MAXIMA code


/* ------------------------------- CUT HERE -------------------------------- */
/* Current in Primary at time t
and coupling coefficient k */

m:float(1/1000);

i1_2nd_order(R1,R2,L1,L2,E,k,t):=block(
[
PrimCurrent:float(0.0),
A:float(0.0),
B:float(0.0),
C:float(0.0),
C1:float(0.0),C2:float(0.0),
Lamda1:float(0.0),Lamda2:float(0.0)],
A:L1*L2-k^2*L1*L2,
B:L1*R2+L2*R1,
C:R1*R2,
Lambda1:(-B+sqrt(B^2-4*A*C))/(2*A),
Lambda2:(-B-sqrt(B^2-4*A*C))/(2*A),
C2: -E*A*L2/((L2*L1-k^2*L1*L2)*sqrt(B^2-4*A*C))-Lambda1*E*A/(R1*sqrt(B^2-4*A*C)),
C1: -C2-E/R1,
PrimCurrent:C1*exp(t*Lambda1)+ C2*exp(t*Lambda2)+E/R1,
return (PrimCurrent)
);

/* example */
i1_2nd_order(0.3,12.5,1.5*m,0.8,12,0.95,1.2*m);

/* ------------------------------- CUT HERE -------------------------------- */