I try make, a simulation circuit with a resistor and a coil in !D area.

The assumptions are as follows:

-The behavior of the system after switching ON the voltage

-Show the operation of the circuit in a transient state

-transition to steady state

-The behavior of the system after switching OFF the voltage

Only the first point is well written (I think). During transition to steady state, flex reports an error.

I'm not sure the equations are well written. Comment in the code bellow.

I would be grateful for any suggestions.

- Code: Select all
`{`

Uklad RL

}

TITLE "5_D1"

COORDINATES cartesian1

VARIABLES

U,i, Ur, Ul

DEFINITIONS

Tstart = -1 ! zero value

T0 = 0 ! Voltage is turn ON

T1 = 15 !

T2 = 200 ! Long time after - transition to steady state

Tend = 250 ! Voltage is turn OFF

Tstep = 1

r = 3

L = 2

U1 = 10 U2 = 0

! ON and OFF Voltage - I`m not sure...

Um = if ( T < T0 ) then 0 else

if ( T >= T0 and T < T2 ) then u1 else u2

EQUATIONS

U : Um - Ur - Ul = 0 ! equation of Voltage

! Then:

! Ur=I*r -> UL = L* di / dt -> Um = I*r - L*di / dt -> Um - I*r = L * di / dt -> (Um - I*r) / L = di / dt -> di = ((Um - i*r)/L )*t

! But I not sure...

i : i = ( t * ( Um - i * r ) / L ) ! di/dt ?

ur : Ur = U - L * dx( i ) ! Resistor Voltage

ul : ul = U - i * r ! Coil Voltage

BOUNDARIES

REGION 1

START ( Tstart )

LINE TO ( T0 )

LINE TO ( T1 )

LINE TO ( T2 )

LINE TO ( Tend )

MONITORS

TIME tstart TO tend

PLOTS

FOR T=Tstart BY Tstep to Tend

!history( uz, um) at (1)

HISTORY( ur, ul ) AT ( 1 ) !window = 5

END