4
$\begingroup$

Hand computation

I have a transfer function defined as $\frac{0.6p+1}{0.6p^2+2.2p+8}$ which was derived from a circuit. Solving this by hand gives the equation, $$i(t)=Ce^{-1.83t}\cos(3.16t + \phi)$$

We can find $C$ and $\phi$ by using the initial conditions of $i(0)=1$ and $\frac{di}{dt}(0)=-8$. This gives us the equation, $$i(t)=2.194e^{-1.83t}\cos(3.16t + 63^{\circ})$$

Mathematica

To solve this transfer function I do,

tf = TransferFunctionModel[(0.6 p + 1)/(0.6 p^2 + 2.2 p + 8), p];
out = OutputResponse[tf, UnitStep[t], t]

Plot[{out, 2.194 Exp[-1.83 t] Cos[3.16 t + 63 \[Degree]]}, {t, 0, 5}, 
 PlotRange -> All]

I know I need to input the aforementioned initial conditions but where in the code does this go? I'm assuming the UnitStep is where I'm going wrong.

output of plot function

$\endgroup$
1
$\begingroup$

You can calculate the output response with litteral initial states c1 and c2 and then resolve c1 and c2 only at end :

tf = TransferFunctionModel[(0.6 p + 1)/(0.6 p^2 + 2.2 p + 8), p]
ss = StateSpaceModel[tf]
y[t_] = OutputResponse[{ss, {c1, c2}}, 0, t][[1]] // Chop

enter image description here

enter image description here

  1. E^(-1.83333 t) (1. c2 Cos[3.15788 t] - 4.22224 c1 Sin[3.15788 t] - 0.580558 c2 Sin[3.15788 t]) + 1.66667 E^(-1.83333 t) (1. c1 Cos[3.15788 t] + 0.580558 c1 Sin[3.15788 t] + 0.316668 c2 Sin[3.15788 t])
constantsListRule = Solve[{y[0] == 1, y'[0] == 8}, {c1, c2}][[1]]
yy[t_] = y[t] /. constantsListRule
Plot[yy[t], {t, 0, 5}, PlotRange -> All]

{c1 -> -1., c2 -> 2.66667}

1.66667 E^(-1.83333 t) (-1. Cos[3.15788 t] + 0.26389 Sin[3.15788 t]) + 1. E^(-1.83333 t) (2.66667 Cos[3.15788 t] + 2.67408 Sin[3.15788 t])

enter image description here

$\endgroup$
3
$\begingroup$

There are no states $i(t)$ and $i'(t)$ in the transfer function. Moreover, the usual assumption in transfer functions is zero initial conditions. So first, the problem has to be translated to a state-space representation with the desired states.

ioEq = Control`DEqns`ioEqnsForm[
       TransferFunctionModel[(0.6 p + 1)/(0.6 p^2 + 2.2 p + 8), p]]; 
states = Flatten@{ioEq[[1, 2]], D[ioEq[[1, 2]], ioEq[[-1]]]};
ssm = StateSpaceModel[ioEq[[1, 1]], states, ioEq[[-3]], ioEq[[1, 2]], ioEq[[-1]]];

enter image description here

Then set the desired initial conditions and simulate.

ssm = StateSpaceModel[ssm, Thread[states -> {1, 8}]];
or = OutputResponse[ssm, 0, {t, 0, 5}];
Plot[or, {t, 0, 5}, PlotRange -> All]

enter image description here

(The result here is what is expected when $i'(0)==8$. The result you have with the hand calculation is with $i'(0)==-8$.)

$\endgroup$
2
  • $\begingroup$ are you able to explain this code? I understand the second block you submitted, but the first I have very little idea what it means. What would I change in order to have i'(0)=-8? $\endgroup$ May 5 '16 at 17:41
  • 1
    $\begingroup$ For $i'(0)==-8$, do ssm = StateSpaceModel[ssm, Thread[states -> {1, -8}]]. The first part is converting the transfer function to ODEs and assembling them as a state space model with states $i(t)$ and $i'(t)$. $\endgroup$ May 5 '16 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.