## Contents

```% Skills Assessment - Chap 1
```

## P1.1 Series RLC circuit

```clear variables
syms I V Vs R L C real
syms s
%Cicruit equations in Laplace variable
eq1=(L*s+R)*I+V-Vs;
eq2=C*s*V-I;
[A,B]=equationsToMatrix([eq1,eq2],[I,V]);
S=linsolve(A,B);
disp('Circuit variables:')
disp('Inductor current (I):'), disp(S(1))
disp('Capacitor voltage (V):'), disp(S(2))
disp('State variable model:')
C=diff(A,s);
A=-C\limit(A,s,0)
B=C\diff(B,Vs)
```
```Circuit variables:
Inductor current (I):
(C*Vs*s)/(C*L*s^2 + C*R*s + 1)
Capacitor voltage (V):
Vs/(C*L*s^2 + C*R*s + 1)
State variable model:
A =
[ -R/L, -1/L]
[  1/C,    0]
B =
1/L
0
```

## P1.2 Parallel RLC circuit

```clear variables
syms I V Is R L C real
syms s
%Circuit equations in Laplace variable
eq1=(C*s+1/R)*V+I-Is;
eq2=L*s*I-V;
[A,B]=equationsToMatrix([eq1,eq2],[I,V]);
S=linsolve(A,B);
disp('Circuit variables:')
disp('Inductor current (I):'), disp(S(1))
disp('Capacitor voltage (V):'), disp(S(2))
disp('State variable model:')
C=diff(A,s);
A=-C\limit(A,s,0)
B=C\diff(B,Is)
```
```Circuit variables:
Inductor current (I):
(Is*R)/(C*L*R*s^2 + L*s + R)
Capacitor voltage (V):
(Is*L*R*s)/(C*L*R*s^2 + L*s + R)
State variable model:
A =
[    0,      1/L]
[ -1/C, -1/(C*R)]
B =
0
1/C
```

## P1.3 DC motor

```clear variables
syms V ia th om R L J b kt kb real
syms s
%Motor equations in Laplace variable
eq1=(L*s+R)*ia+kb*om-V;
eq2=(J*s+b)*om-kt*ia;
eq3=s*th-om;
[A,B]=equationsToMatrix([eq1,eq2,eq3],[ia,om,th]);
A=subs(A,[L,R,J,b,kt,kb],[.01,1,.01,.1,.02,.02]);
B=subs(B,[L,R,J,b,kt,kb],[.01,1,.01,.1,.02,.02]);
S=linsolve(A,B);
disp('Motor variables:')
disp('Motor current (I):'), disp(S(1))
disp('Motor speed (Omega):'), disp(S(2))
disp('Motor angle (theta):'), disp(S(3))
disp('State variable model:')
C=diff(A,s);
A=-C\limit(A,s,0)
B=C\diff(B,V)
```
```Motor variables:
Motor current (I):
(100*V*(s + 10))/(s^2 + 110*s + 1004)
Motor speed (Omega):
(200*V)/(s^2 + 110*s + 1004)
Motor angle (theta):
(200*V)/(s*(s^2 + 110*s + 1004))
State variable model:
A =
[ -100,  -2, 0]
[    2, -10, 0]
[    0,   1, 0]
B =
100
0
0
```

## P1.4 Human postural dynamics

```clear variables
syms m l I th Dth DDth T g real
eq=(I+m*l^2)*DDth-m*g*l*th-T;
DDth=solve(eq,DDth);
disp('State variable model:')
A=jacobian([Dth DDth],[th Dth]);
B=jacobian([Dth DDth],[T]);
A=subs(A,[m l I g],[80 1 4 9.8])
B=subs(B,[m l I g],[80 1 4 9.8])
```
```State variable model:
A =
[    0, 1]
[ 28/3, 0]
B =
0
1/84
```

## P1.5 Inverted pendulum over cart

```clear variables
syms M m l y th Dy Dth DDy DDth g f real
%solve for accelerations
eq1=(M+m)*DDy+m*l*DDth*cos(th)-m*l*Dth^2*sin(th)-f;
eq2=DDy*cos(th)+l*DDth-g*sin(th);
DD=solve(eq1,eq2, DDy, DDth);
disp('State variable model:')
A=jacobian([Dy Dth DD.DDy DD.DDth],[y,Dy,th,Dth]);
B=jacobian([Dy Dth DD.DDy DD.DDth],[f]);
A=subs(A,[y,th,Dy,Dth],[0,0,0,0])
B=subs(B,[y,th,Dy,Dth],[0,0,0,0])
```
```Warning: The solutions are valid under the following conditions: l ~= 0.
To include parameters and conditions in the solution, specify the
'ReturnConditions' option.
State variable model:
A =
[ 0, 1,                 0, 0]
[ 0, 0,                 0, 1]
[ 0, 0,          -(g*m)/M, 0]
[ 0, 0, (M*g + g*m)/(M*l), 0]
B =
0
0
1/M
-1/(M*l)
```