summaryrefslogtreecommitdiff
path: root/Linear_Control_Systems_by_B_S_Manke/12-CLASSIFIED_SOLVED_EXAMPLES.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'Linear_Control_Systems_by_B_S_Manke/12-CLASSIFIED_SOLVED_EXAMPLES.ipynb')
-rw-r--r--Linear_Control_Systems_by_B_S_Manke/12-CLASSIFIED_SOLVED_EXAMPLES.ipynb1667
1 files changed, 1667 insertions, 0 deletions
diff --git a/Linear_Control_Systems_by_B_S_Manke/12-CLASSIFIED_SOLVED_EXAMPLES.ipynb b/Linear_Control_Systems_by_B_S_Manke/12-CLASSIFIED_SOLVED_EXAMPLES.ipynb
new file mode 100644
index 0000000..2821b89
--- /dev/null
+++ b/Linear_Control_Systems_by_B_S_Manke/12-CLASSIFIED_SOLVED_EXAMPLES.ipynb
@@ -0,0 +1,1667 @@
+{
+"cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 12: CLASSIFIED SOLVED EXAMPLES"
+ ]
+ },
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.10: Determine_Unit_Step_Response.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Caption:determine_unit_step_response\n",
+"//example 12.10\n",
+"//page 524\n",
+"s=%s;\n",
+"syms t;\n",
+"CL=sym('1/((s+1)*(s^2+1))')\n",
+"disp(CL,'C(s)/R(s)=');\n",
+"//for unit step response R(s)=1/s; \n",
+"d=CL*(1/s);\n",
+"a=s*d;\n",
+"c=ilaplace(d,s,t);\n",
+"disp(c,'c(t)=');"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.11: Determine_Unit_Step_and_Unit_Impulse_Response.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Caption:determine_unit_step_and_unit_impulse_response\n",
+"//example 12.11\n",
+"//page 524\n",
+"s=%s;\n",
+"syms t;\n",
+"G=sym('8/(s+1)');\n",
+"H=sym('(1/2*s)');\n",
+"CL=G/(1+G*H);\n",
+"disp(CL,'C(s)/R(s)=');\n",
+"//for unit step response R(s)=1/s; \n",
+"d=CL*(1/s);\n",
+"disp(d,'C(s)=');\n",
+"c=ilaplace(d,s,t);\n",
+"disp(c,'unit step response,c(t)=');\n",
+"//for unit impulse response R(s)=1; \n",
+"e=CL*(1);\n",
+"disp(e,'C(s)=');\n",
+"ct=ilaplace(e,s,t);\n",
+"disp(ct,'unit impulse response,c(t)=');"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.12: Determine_Wn_Wd_zeta_and_steady_state_error.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:determine_Wn,Wd,zeta_and_steady_state_error\n",
+"//example 12_12\n",
+"//page 526\n",
+"s=%s;\n",
+"G=sym('20/(s*(s^2+6*s+6))');\n",
+"H=0.25;\n",
+"CL=G/(1+G*H);\n",
+"CL=simple(CL);\n",
+"disp(CL,'C(s)/R(s)=');\n",
+"printf('the char. eq is:')\n",
+"disp('s^2+s+1=0')\n",
+"Wn=sqrt(1)//natural_frequency\n",
+"//2*zeta*Wn=1\n",
+"zeta=1/(2*Wn);//damping ratio\n",
+"d=zeta*Wn;//damping_factor\n",
+"z=sqrt(1-zeta^2);\n",
+"Wd=Wn*z;//damped_frequency_of_oscillation\n",
+"Mp=exp((-zeta*%pi)/z)*100;//%_max.peak_overshoot\n",
+"ts=4/(zeta*Wn);//settling_time\n",
+"tp=%pi/(Wn*sqrt(1-zeta^2));//peak_time\n",
+"tu=2*%pi/(Wn*sqrt(1-zeta^2));//first under shoot\n",
+"ti=tu-tp;//time interval between max. and min. values\n",
+"disp(Wn,'natural_frequency=');\n",
+"disp(zeta,'damping ratio=');\n",
+"disp(Wd,'damped_frequency_of_oscillation=');\n",
+"disp(Mp,'%_max.peak_overshoot=');\n",
+"disp(ts,'settling_time=');\n",
+"disp(tp,'peak_time=');\n",
+"disp(ti,'time_interval_between_max_and_min_values=');"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.13: Determine_Wn_Wd_zeta_and_steady_state_error.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:determine_Wn,Wd,zeta_and_steady_state_error\n",
+"//example 12_13\n",
+"//page 527\n",
+"syms Kp K Kd T \n",
+"s=%s;\n",
+"//exec series.sce;\n",
+"//exec parallel.sce;\n",
+"a=(Kp+s*Kd)*K\n",
+"b=1/(s*(s*T+1))\n",
+"G=series(a,b)\n",
+"H=1;\n",
+"er=1/(1+G*H)\n",
+"disp(er,'E(s)/R(s)=');\n",
+"R=1/s^2\n",
+"E=R*er\n",
+"ess=limit(s*E,s,0)\n",
+"disp(ess,'steady state error,ess=')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.15: Stability_Using_Routh_Hurwitz_Criterion.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:stability_using_Routh-hurwitz_criterion\n",
+"//example 12.15\n",
+"//page 529\n",
+"s=%s;\n",
+"syms K\n",
+"G=sym('K/(s*(s^2+s+1)*(s+5)');\n",
+"H=1;\n",
+"CH=(s*(s^2+s+1)*(s+5)+K)\n",
+"disp('=0',CH,'characterstics_eq,CH=')\n",
+"c0=coeffs(CH,'s',0);\n",
+"c1=coeffs(CH,'s',1);\n",
+"c2=coeffs(CH,'s',2);\n",
+"c3=coeffs(CH,'s',3);\n",
+"c4=coeffs(CH,'s',4);\n",
+"b=[c0 c1 c2 c3 c4 ]\n",
+"routh=[b([5,3,1]);b([4,2]),0]\n",
+"routh=[routh;-det(routh(1:2,1:2)/routh(2,1)),K,0]\n",
+"t=routh(2:3,1:2)\n",
+"routh=[routh;-det(t)/t(2,1),0,0]\n",
+"routh=[routh;K,0,0]\n",
+"disp(routh,'routh=')\n",
+"disp('for given system to be stable:');\n",
+"disp('((5.1*5-6*K)/5.1)>0 and K>0');\n",
+"disp('which gives:');\n",
+"disp('0<K<4.25');"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.16: Stability_Using_Routh_Hurwitz_Criterion.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:stability_using_Routh-hurwitz_criterion\n",
+"//example 12.16\n",
+"//page 530\n",
+"s=%s;\n",
+"syms K\n",
+"CH=s^4+2*s^3+10*s^2+(K-10)*s+K\n",
+"disp('=0',CH,'characterstics_eq,CH=')\n",
+"c0=coeffs(CH,'s',0);\n",
+"c1=coeffs(CH,'s',1);\n",
+"c2=coeffs(CH,'s',2);\n",
+"c3=coeffs(CH,'s',3);\n",
+"c4=coeffs(CH,'s',4);\n",
+"b=[c0 c1 c2 c3 c4 ]\n",
+"routh=[b([5,3,1]);b([4,2]),0]\n",
+"routh=[routh;-det(routh(1:2,1:2)/routh(2,1)),K,0]\n",
+"routh(3,1)=simple(routh(3,1))\n",
+"t=routh(2:3,1:2)\n",
+"l=simple(-det(t)/t(2,1))\n",
+"routh=[routh;l,0,0]\n",
+"//routh=[routh;K,0,0]\n",
+"disp(routh,'routh=')\n",
+"disp('for given system to be stable,following condition should be satisfied');\n",
+"disp('K<30,K<22.9 and K>13.1,K>0')\n",
+"disp('which gives,')\n",
+"disp('13.1<K<22.9');"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.17: Stability_Using_Routh_Hurwitz_Criterion.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:stability_using_Routh-hurwitz_criterion\n",
+"//example 12.17\n",
+"//page 530\n",
+"s=%s;\n",
+"syms K\n",
+"G=sym('K/((s^3+3*s+2)*(s^2+6*s+24))');\n",
+"H=1;\n",
+"CH=((s^3+3*s+2)*(s^2+6*s+24)+K)\n",
+"disp('=0',CH,'characterstics_eq,CH=')\n",
+"c0=coeffs(CH,'s',0);\n",
+"c1=coeffs(CH,'s',1);\n",
+"c2=coeffs(CH,'s',2);\n",
+"c3=coeffs(CH,'s',3);\n",
+"c4=coeffs(CH,'s',4);\n",
+"b=[c0 c1 c2 c3 c4 ]\n",
+"routh=[b([5,3,1]);b([4,2]),0]\n",
+"routh=[routh;-det(routh(1:2,1:2))/routh(2,1),routh(1,3),0]\n",
+"routh(3,1)=simple(routh(3,1))\n",
+"t=routh(2:3,1:2)\n",
+"l=simple(-det(t)/t(2,1))\n",
+"routh=[routh;l,0,0]\n",
+"//routh=[routh;K,0,0]\n",
+"disp(routh,'routh=')\n",
+"disp('for given system to be stable,following condition should be satisfied');\n",
+"disp('78.84-0.259K>0')\n",
+"disp('which gives limiting value of K')\n",
+"disp('K<288.9');"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.18: Stability_Using_Routh_Hurwitz_Criterion.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:stability_using_Routh-hurwitz_criterion\n",
+"//example 12.18\n",
+"//page 531\n",
+"s=%s;\n",
+"A=s^5+s^4+4*s^3+4*s^2+s+1;\n",
+"b=coeff(A)\n",
+"n=length(b)\n",
+"routh=[b([6 4 2]);b([5 3 1])]\n",
+"routh1=routh;\n",
+"c=[routh(1,1),routh(1,3);routh(2,1),routh(2,3)]\n",
+"routh=[routh;-det(routh(1:2,1:2))/routh(2,1),-det(c)/routh(2,1),0]\n",
+"disp('since all elements of third row are zero, so we make auxiliary equation')\n",
+"A=sym('s^4+4*s^2+1')//auxiliary equation\n",
+"B=diff(A,s)\n",
+"routh=[routh1;4,8,0]\n",
+"d=[routh(2,1),routh(2,3);routh(3,1),routh(3,3)]\n",
+"routh=[routh;-det(routh(2:3,1:2))/routh(3,1),-det(d)/routh(3,1),0]\n",
+"routh2=routh\n",
+"routh=[routh;-det(routh(3:4,1:2))/routh(4,1),0,0]\n",
+"routh=[routh;-det(routh(4:5,1:2))/routh(5,1),0,0];\n",
+"disp(routh,'routh=')\n",
+"disp('stability is examined as below . since roots of auxiliary eq are also roots of characterstics eq')\n",
+"A=s^4+4*s^2+1\n",
+"b=roots(A)\n",
+"disp('since the equation has non repeating roots on s plane imaginary axis.hence system are unstable' )\n",
+"\n",
+""
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.19: Stability_Using_Routh_Hurwitz_Criterion.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:stability_using_Routh-hurwitz_criterion\n",
+"//example 12.19\n",
+"//page 531\n",
+"s=%s;\n",
+"A=s^5+s^4+4*s^3+4*s^2+4*s+4;\n",
+"b=coeff(A)\n",
+"n=length(b)\n",
+"routh=[b([6,4,2]);b([5 3 1])]\n",
+"routh1=routh;\n",
+"c=[routh(1,1),routh(1,3);routh(2,1),routh(2,3)]\n",
+"routh=[routh;-det(routh(1:2,1:2))/routh(2,1),-det(c)/routh(2,1),0]\n",
+"disp('since all elements of third row are zero, so we make auxiliary equation')\n",
+"A=sym('s^4+4*s^2+4')//auxiliary equation\n",
+"B=diff(A,s)\n",
+"routh=[routh1;4,8,0]\n",
+"d=[routh(2,1),routh(2,3);routh(3,1),routh(3,3)]\n",
+"routh=[routh;-det(routh(2:3,1:2))/routh(3,1),-det(d)/routh(3,1),0]\n",
+"routh2=routh\n",
+"routh=[routh;-det(routh(3:4,1:2))/routh(4,1),0,0]\n",
+"disp('since all elements of fifth row are zero, so we make auxiliary equation')\n",
+"A=sym('2*s^2+4')//auxiliary equation\n",
+"B=diff(A,s)\n",
+"routh=[routh2;4,0,0]\n",
+"routh=[routh;-det(routh(4:5,1:2))/routh(5,1),0,0];\n",
+"disp(routh,'routh=')\n",
+"disp('stability is examined as below . since roots of auxiliary eq are also roots of characterstics eq')\n",
+"A=s^4+4*s^2+4\n",
+"b=roots(A)\n",
+"disp('since the equation has multiple roots on s plane imaginary axis.hence system are unstable' )\n",
+""
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.1: Transfer_Function.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Caption:transfer_function\n",
+"// example 12.1\n",
+"//page 515\n",
+"// we are solving this problem from signal flow graph approach\n",
+"syms G H;\n",
+"// forward path denoted by P1,P2 and so on and loop by L1,L2 and so on \n",
+"//path factor by D1,D2 and so on and graph determinant by D\n",
+"P1=1*G*1\n",
+"P2=1;\n",
+"L1=-G;\n",
+"L2=-G*H;\n",
+"L3=G*H;\n",
+"D1=1;\n",
+"D2=1;\n",
+"D=1-(L1+L2+L3);\n",
+"D=simple(D)\n",
+"Y=(P1*D1+P2*D2)/D;\n",
+"Y=simple(Y);\n",
+"disp(Y,'C(s)/R(s)=');"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.21: Determine_Frequency_of_Oscillations.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:determine_frequency_of_oscillations\n",
+"//example 12.21\n",
+"//page 533\n",
+"s=%s;\n",
+"syms K\n",
+"G=sym('K*(s*(2*s+1))/(s^3+3*s+20)');\n",
+"H=1;\n",
+"CH=((s^3+3*s+20)+K*(s*(2*s+1)))\n",
+"disp('=0',CH,'characterstics_eq,CH=')\n",
+"c0=coeffs(CH,'s',0);\n",
+"c1=coeffs(CH,'s',1);\n",
+"c2=coeffs(CH,'s',2);\n",
+"c3=coeffs(CH,'s',3);\n",
+"b=[c0 c1 c2 c3]\n",
+"routh=[b([4,2]);b([3,1])]\n",
+"routh=[routh;-det(routh(1:2,1:2)/routh(2,1)),0]\n",
+"routh(3,1)=simple(routh(3,1))\n",
+"t=routh(2:3,1:2)\n",
+"l=simple(-det(t)/t(2,1))\n",
+"routh=[routh;l,0]\n",
+"disp(routh,'routh=')\n",
+"disp('for sustained oscillations:');\n",
+"disp('2*K^2+6*K-20=0')\n",
+"disp('which gives K')\n",
+"disp('K=2');\n",
+"disp('freq of oscillations is calculated by solving equation formed by s^2 row of the routh table')\n",
+"K=2\n",
+"k=2\n",
+"A=2*k*s^2+20\n",
+"r=roots(A)\n",
+"disp(%i*r(2),'frequency of oscillations=' )\n",
+""
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.23_iii: Stability_Using_Nyquist_Criterion.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:stability_using_Nyquist_criterion\n",
+"//example 12_23_iii\n",
+"//page 535\n",
+"disp('for K=10')\n",
+"g=(10*(s+10)*(s+40))/(s*(s+1)*(s+4));\n",
+"g1=(10*(s1+10)*(s1+40))/(s1*(s1+1)*(s1+4));\n",
+"GH=syslin('c',g);\n",
+"GH1=syslin('c',g1);\n",
+"nyquist(GH);\n",
+"nyquist(GH1);\n",
+"//mtlb_axis([-1.5 0.2 -0.3 0.3]);\n",
+"xtitle('Nyquist plot of (0.1*(s+10)*(s+40))/(s*(s+1)*(s+4))')\n",
+"figure;\n",
+"show_margins(GH,'nyquist')\n",
+"disp('since the point(-1+%i0) is encircled once in clockwise and once in anti clockwise direction by Nyquist plot ,so N=0 and P=0')\n",
+"N=0;//no. of encirclement of -1+%i0 by G(s)H(s) plot anticlockwise\n",
+"P=0;//no. of poles of G(s)H(s) with positive real part\n",
+"Z=P-N;//np.of zeros of 1+G(s)H(s)=0 with positive real part\n",
+"disp(Z,'Z=')\n",
+"disp('as Z=0,there are no roots of closed loop characterstics eq having positive real part, hence system is stable.')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.23_ii: Stability_Using_Nyquist_Criterion.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:stability_using_Nyquist_criterion\n",
+"//example 12_23_ii\n",
+"//page 535\n",
+"disp('for K=1')\n",
+"g=(0.1*(s+10)*(s+40))/(s*(s+1)*(s+4));\n",
+"g1=(0.1*(s1+10)*(s1+40))/(s1*(s1+1)*(s1+4));\n",
+"GH=syslin('c',g);\n",
+"GH1=syslin('c',g1);\n",
+"nyquist(GH);\n",
+"nyquist(GH1);\n",
+"//mtlb_axis([-3 0.5 -0.6 0.6]);\n",
+"xtitle('Nyquist plot of (0.1*(s+10)*(s+40))/(s*(s+1)*(s+4))')\n",
+"figure;\n",
+"show_margins(GH,'nyquist')\n",
+"disp('since the point(-1+%i0) is encircled twice clockwise by Nyquist plot ,so N=2 and P=0(given)')\n",
+"N=-2;//no. of encirclement of -1+%i0 by G(s)H(s) plot anticlockwise\n",
+"P=0;//no. of poles of G(s)H(s) with positive real part\n",
+"Z=P-N;//np.of zeros of 1+G(s)H(s)=0 with positive real part\n",
+"disp(Z,'Z=')\n",
+"disp('as Z=2,there are two roots of closed loop characterstics eq having positive real part, hence system is unstable.')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.23_i: Stability_Using_Nyquist_Criterion.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:stability_using_Nyquist_criterion\n",
+"//example 12_23_i\n",
+"//page 535\n",
+"clf();\n",
+"s=%s;\n",
+"s1=-s;\n",
+"disp('for K=0.1')\n",
+"g=(0.1*(s+10)*(s+40))/(s*(s+1)*(s+4));\n",
+"g1=(0.1*(s1+10)*(s1+40))/(s1*(s1+1)*(s1+4));\n",
+"GH=syslin('c',g);\n",
+"GH1=syslin('c',g1);\n",
+"nyquist(GH);\n",
+"nyquist(GH1);\n",
+"//mtlb_axis([-1.5 0.2 -0.3 0.3]);\n",
+"xtitle('Nyquist plot of (0.1*(s+10)*(s+40))/(s*(s+1)*(s+4))')\n",
+"figure;\n",
+"show_margins(GH,'nyquist')\n",
+"disp('since the point(-1+%i0) is not encircled clockwise by Nyquist plot ,so N=0 and P=0')\n",
+"N=0;//no. of encirclement of -1+%i0 by G(s)H(s) plot anticlockwise\n",
+"P=0;//no. of poles of G(s)H(s) with positive real part\n",
+"Z=P-N;//np.of zeros of 1+G(s)H(s)=0 with positive real part\n",
+"disp(Z,'Z=')\n",
+"disp('as Z=0,there are no roots of closed loop characterstics eq having positive real part, hence system is stable.')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.27: Gain_and_Phase_Margin.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:gain_and_phase_margin\n",
+"//example 12_27\n",
+"//page543\n",
+"clf();\n",
+"s=%s;\n",
+"s1=-s;\n",
+"disp('for K=0.5')\n",
+"g=(0.5)/(s*(s+1)^2);\n",
+"GH=syslin('c',g);\n",
+"nyquist(GH);\n",
+"//mtlb_axis([-5 1 -500 500]);\n",
+"xtitle('Nyquist plot of (2.5*3)/(s*(0.4*s+1)*(0.2*s+1))')\n",
+"pm=p_margin(GH)\n",
+"disp(pm,'phase margin=')\n",
+"gm=g_margin(GH)\n",
+"disp(gm,'gain margin=')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.2: Transfer_Function.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Caption:transfer_function\n",
+"// example 12.2\n",
+"//page 516\n",
+"// we are solving this problem from signal flow graph approach\n",
+"syms G1 G2 G3 G4\n",
+"// forward path denoted by P1,P2 and so on and loop by L1,L2 and so on \n",
+"//path factor by D1,D2 and so on and graph determinant by D\n",
+"P1=G1;\n",
+"P2=G2;\n",
+"P3=-G1*G2*G3;\n",
+"P4=G1*G2*G4;\n",
+"L1=-G1*G2*G3*G4;\n",
+"D1=1;\n",
+"D2=1;\n",
+"D3=1;\n",
+"D4=1;\n",
+"D=1-(L1);\n",
+"Y=(P1*D1+P2*D2+P3*D3+P4*D4)/D;\n",
+"Y=simple(Y);\n",
+"disp(Y,'C(s)/R(s)=');"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.33: Determine_Close_Loop_Stability.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:determine_close_loop_stability\n",
+"//example 12_33\n",
+"//page 550\n",
+"s=%s;\n",
+"g=(720*(s+1.25))/(s*(s+10)*(s^2+2*s+9));\n",
+"G=syslin('c',g)\n",
+"fmin=0.1; \n",
+"fmax=100; \n",
+"bode(G, fmin, fmax) \n",
+"[gm,freqGM]=g_margin(G);\n",
+"[pm,freqPM]=p_margin(G);\n",
+"show_margins(G);\n",
+"disp(gm,'gain_margin=');\n",
+"disp((freqGM*2*%pi),'gain_margin_freq=');\n",
+"disp(pm,'phase_margin=');\n",
+"disp((freqPM*2*%pi),'phase_margin_freq=');\n",
+"show_margins(G);\n",
+"disp('since gain and phase margin are both negative so system is unstable')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.3: Transfer_Function.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Caption:transfer_function\n",
+"// example 12.3\n",
+"//page 517\n",
+"// we are solving this problem from signal flow graph approach\n",
+"syms G1 G2 G3 G4 H2 H1 H3\n",
+"// forward path denoted by P1,P2 and so on and loop by L1,L2 and so on \n",
+"//path factor by D1,D2 and so on and graph determinant by D\n",
+"P1=G2*G4;\n",
+"P2=G2*G3*G4;\n",
+"P3=G1*G3*G4;\n",
+"L1=-G4*H1;\n",
+"L2=-G3*G4*H1*H2;\n",
+"L3=-G1*G3*G4*H1*H2*H3\n",
+"D1=1;\n",
+"D2=1;\n",
+"D3=1;\n",
+"D=1-(L1+L2+L3);\n",
+"Y=(P1*D1+P2*D2+P3*D3)/D;\n",
+"Y=simple(Y);\n",
+"disp(Y,'C(s)/R(s)=');"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.42: Root_Locus.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:root_locus\n",
+"//example 12_42\n",
+"//page 562\n",
+"s=%s;\n",
+"syms K;\n",
+"GH=K/(s*(s+2)*(s+4))\n",
+"//since Mp=40%, so .4=exp((-zeta*%pi)/(sqrt(1-zeta^2))\n",
+"zeta=0.3\n",
+"//from given data \n",
+"disp('the characterstics eq. is determined as:')\n",
+"CH=(s*(s+2)*(s+4))+K\n",
+"K=sym('-(s^3+6*s^2+8*s)')\n",
+"d=diff(K,s)\n",
+"e=-3*s^2-12*s-8 \n",
+"r1=roots(e)\n",
+"disp(r1,'roots=')\n",
+"disp('-0.842 is break away point sinc it lies on root locus')\n",
+"CH=sym('s^3+6*s^2+8*s+K');\n",
+"disp('=0',CH,'characterstics_eq,CH=')\n",
+"c0=coeffs(CH,'s',0);\n",
+"c1=coeffs(CH,'s',1);\n",
+"c2=coeffs(CH,'s',2);\n",
+"c3=coeffs(CH,'s',3);\n",
+"b=[c0 c1 c2 c3]\n",
+"n=4;\n",
+"routh=[b([4,2]);b([3,1])];\n",
+"routh=[routh;-det(routh)/routh(2,1),0]\n",
+"t=routh(2:3,1:2)\n",
+"routh=[routh;-det(t)/t(2,1),0]\n",
+"disp(routh,'routh=')\n",
+"disp('for given system to be marginally stable:');\n",
+"disp('(48-K)=0 ');\n",
+"disp('which gives:');\n",
+"disp('K=48');\n",
+"K=48;\n",
+"k=48\n",
+"a=6*s^2+48//intersection of root locus with imaginary plane\n",
+"r=roots(a)\n",
+"g=k/(s*(s+2)*(s+4))\n",
+"G=syslin('c',g)\n",
+"evans(g,8)\n",
+"xgrid(2)\n",
+"disp('the line theta=acos(zeta)=72.5 intersects root locus at sa=(-0.5+i1.65)')\n",
+"disp('the value of K at s=sa is find to be 14.87 for Mp=40%')\n",
+"K=14.87\n",
+"ts=4/0.5 //ts=4/(zeta*wn)\n",
+"Kv=limit(s*GH,s,0)\n",
+"Kv=eval(Kv)\n",
+"Kv=float(Kv)\n",
+"disp(Kv,'Kv=');"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.43: Root_Locus_and_Value_of_K.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:root_locus_and_value_of_K\n",
+"//example 12.43\n",
+"//page 564\n",
+"s=%s;\n",
+"syms K;\n",
+"GH=K/(s*(s+2)*(s^2+2*s+2))\n",
+"disp('the characterstics eq. is determined as:')\n",
+"CH=(s*(s+2)*(s^2+2*s+2))+K\n",
+"CH=sym('s^4+4*s^3+6*s^2+4*s+K');\n",
+"disp('=0',CH,'characterstics_eq,CH=')\n",
+"c0=coeffs(CH,'s',0);\n",
+"c1=coeffs(CH,'s',1);\n",
+"c2=coeffs(CH,'s',2);\n",
+"c3=coeffs(CH,'s',3);\n",
+"c4=coeffs(CH,'s',4);\n",
+"b=[c0 c1 c2 c3 c4 ]\n",
+"routh=[b([5,3,1]);b([4,2]),0]\n",
+"routh=[routh;-det(routh(1:2,1:2))/routh(2,1),routh(1,3),0]\n",
+"routh(3,1)=simple(routh(3,1))\n",
+"t=routh(2:3,1:2)\n",
+"l=simple(-det(t)/t(2,1))\n",
+"routh=[routh;l,0,0]\n",
+"routh=[routh;K,0,0]\n",
+"K=sym('s^4+4*s^3+6*s^2+4*s')\n",
+"d=diff(K,s)\n",
+"e=-(4*s^3+12*s^2+12*s+4)\n",
+"r=roots(e)\n",
+"disp(routh,'routh=')\n",
+"disp('for given system to be marginally stable:');\n",
+"disp('((20-4K)/5)=0 ');\n",
+"disp('which gives:');\n",
+"disp('K=5');\n",
+"K=5;\n",
+"k=5\n",
+"a=5*s^2+5//intersection of root locus with s plane\n",
+"r=roots(a)\n",
+"disp(r,'intersection point with imaginary axis=')\n",
+"g=k/(s*(s+2)*(s^2+2*s+2))\n",
+"G=syslin('c',g)\n",
+"evans(g,200)\n",
+"xgrid(2)\n",
+"disp('angle of departure=-90 and +90')\n",
+"disp('breakaway point is -1 and +j and -j')\n",
+"disp('on solving we find K=1')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.44: Root_Locus_and_Value_of_K.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:root_locus_and_value_of_K\n",
+"//example 12.44\n",
+"//page 565\n",
+"s=%s;\n",
+"syms K;\n",
+"GH=K/((s^2+2*s+5)*(s^2+2*s+2))\n",
+"disp('the characterstics eq. is determined as:')\n",
+"CH=((s^2+2*s+5)*(s^2+2*s+2))+K\n",
+"CH=sym('((s^2+2*s+5)*(s^2+2*s+2))+K');\n",
+"disp('=0',CH,'characterstics_eq,CH=')\n",
+"c0=coeffs(CH,'s',0);\n",
+"c1=coeffs(CH,'s',1);\n",
+"c2=coeffs(CH,'s',2);\n",
+"c3=coeffs(CH,'s',3);\n",
+"c4=coeffs(CH,'s',4);\n",
+"b=[c0 c1 c2 c3 c4 ]\n",
+"routh=[b([5,3,1]);b([4,2]),0]\n",
+"routh=[routh;-det(routh(1:2,1:2))/routh(2,1),routh(1,3),0]\n",
+"routh(3,1)=simple(routh(3,1))\n",
+"t=routh(2:3,1:2)\n",
+"l=simple(-det(t)/t(2,1))\n",
+"routh=[routh;l,0,0]\n",
+"routh=[routh;K,0,0]\n",
+"K=sym('-(s^2+2*s+5)*(s^2+2*s+2)')\n",
+"d=diff(K,s)\n",
+"e=-(4*s^3+12*s^2+22*s+14)\n",
+"r=roots(e)\n",
+"disp(routh,'routh=')\n",
+"disp('for given system to be marginally stable:');\n",
+"disp('((7.5*14-4(K+10)/7.5)=0 ');\n",
+"disp('which gives:');\n",
+"disp('K=16.25');\n",
+"K=16.25;\n",
+"k=16.25\n",
+"a=7.5*s^2+26.25//intersection of root locus with s plane\n",
+"r=roots(a)\n",
+"g=k/((s^2+2*s+5)*(s^2+2*s+2))\n",
+"G=syslin('c',g)\n",
+"evans(g,200)\n",
+"xgrid(2)\n",
+"disp(r,'the point of intersection of root locus with imaginary axis =')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.45: Root_Locus_and_Value_of_K.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:root_locus_and_value_of_K\n",
+"//example 12.45\n",
+"//page 567\n",
+"s=%s;\n",
+"syms K;\n",
+"GH=K*(s+1)/(s*(s+2)*(s^2+4*s+8))\n",
+"disp('the characterstics eq. is determined as:')\n",
+"CH=((s*(s+2)*(s^2+4*s+8)))+K*(s+1)\n",
+"CH=sym('((s*(s+2)*(s^2+4*s+8)))+K*(s+1)');\n",
+"disp('=0',CH,'characterstics_eq,CH=')\n",
+"c0=coeffs(CH,'s',0);\n",
+"c1=coeffs(CH,'s',1);\n",
+"c2=coeffs(CH,'s',2);\n",
+"c3=coeffs(CH,'s',3);\n",
+"c4=coeffs(CH,'s',4);\n",
+"b=[c0 c1 c2 c3 c4 ]\n",
+"routh=[b([5,3,1]);b([4,2]),0]\n",
+"routh=[routh;-det(routh(1:2,1:2))/routh(2,1),routh(1,3),0]\n",
+"routh(3,1)=simple(routh(3,1))\n",
+"t=routh(2:3,1:2)\n",
+"l=simple(-det(t)/t(2,1))\n",
+"routh=[routh;l,0,0]\n",
+"routh=[routh;K,0,0]\n",
+"disp(routh,'routh=')\n",
+"disp('for given system to be marginally stable:');\n",
+"disp('(K^2-28*K-1280)=0 ');\n",
+"disp('which gives:');\n",
+"disp('K=52.4 and -24.42');\n",
+"K=52.4;//considering positive value\n",
+"k=52.4\n",
+"a=((80-52.4)/6)*s^2+52.4//intersection of root locus with imaginary axis\n",
+"r=roots(a)\n",
+"g=k*(s+1)/(s*(s+2)*(s^2+4*s+8))\n",
+"G=syslin('c',g)\n",
+"clf();\n",
+"evans(g,10)\n",
+"xgrid(2)\n",
+"disp(r,'the point of intersection of root locus with imaginary axis =')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.46: Root_Locus_and_Value_of_K.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:root_locus_and_value_of_K\n",
+"//example 12.46\n",
+"//page 570\n",
+"s=%s;\n",
+"syms K;\n",
+"GH=K/(s*((s+6)^2))\n",
+"disp('the characterstics eq. is determined as:')\n",
+"CH=(s*((s+6)^2))+K\n",
+"CH=sym('(s*((s+6)^2))+K');\n",
+"disp('=0',CH,'characterstics_eq,CH=')\n",
+"c0=coeffs(CH,'s',0);\n",
+"c1=coeffs(CH,'s',1);\n",
+"c2=coeffs(CH,'s',2);\n",
+"c3=coeffs(CH,'s',3);\n",
+"b=[c0 c1 c2 c3]\n",
+"n=4;\n",
+"routh=[b([4,2]);b([3,1])];\n",
+"routh=[routh;-det(routh)/routh(2,1),0]\n",
+"t=routh(2:3,1:2)\n",
+"routh=[routh;-det(t)/t(2,1),0]\n",
+"K=sym('-(s*((s+6)^2))')\n",
+"d=diff(K,s)\n",
+"e=3*s^2+24*s+36 \n",
+"r1=roots(e)\n",
+"disp(r1,'roots=')\n",
+"disp('-2 is break away point sinc it lies on root locus')\n",
+"disp(routh,'routh=')\n",
+"disp('for given system to be marginally stable:');\n",
+"disp('(-(K-432)/12)=0 ');\n",
+"disp('which gives:');\n",
+"disp('K=432');\n",
+"K=432;//considering positive value\n",
+"k=432\n",
+"a=12*s^2+k//intersection of root locus with imaginary axis plane\n",
+"r=roots(a)\n",
+"g=k/(s*((s+6)^2))\n",
+"G=syslin('c',g)\n",
+"clf();\n",
+"evans(g,5)\n",
+"xgrid(2)\n",
+"disp(r,'the point of intersection of root locus with imaginary axis =')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.48: Root_Locus_and_Value_of_K.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:root_locus_and_value_of_K\n",
+"//example 12_48\n",
+"//page 574\n",
+"s=%s;\n",
+"syms K;\n",
+"GH=K/(s*(s+2)*(s+4))\n",
+"zeta=0.277\n",
+"//from given data \n",
+"disp('the characterstics eq. is determined as:')\n",
+"CH=(s*(s+2)*(s+4))+K\n",
+"K=sym('-(s^3+6*s^2+8*s)')\n",
+"d=diff(K,s)\n",
+"e=-3*s^2-12*s-8 \n",
+"r1=roots(e)\n",
+"disp(r1,'roots=')\n",
+"disp('-0.85 is break away point sinc it lies on root locus')\n",
+"CH=sym('s^3+6*s^2+8*s+K');\n",
+"disp('=0',CH,'characterstics_eq,CH=')\n",
+"c0=coeffs(CH,'s',0);\n",
+"c1=coeffs(CH,'s',1);\n",
+"c2=coeffs(CH,'s',2);\n",
+"c3=coeffs(CH,'s',3);\n",
+"b=[c0 c1 c2 c3]\n",
+"n=4;\n",
+"routh=[b([4,2]);b([3,1])];\n",
+"routh=[routh;-det(routh)/routh(2,1),0]\n",
+"t=routh(2:3,1:2)\n",
+"routh=[routh;-det(t)/t(2,1),0]\n",
+"disp(routh,'routh=')\n",
+"disp('for given system to be marginally stable:');\n",
+"disp('(48-K)=0 ');\n",
+"disp('which gives:');\n",
+"disp('K=48');\n",
+"K=48;\n",
+"k=48\n",
+"a=6*s^2+48//intersection of root locus with imaginary plane\n",
+"r=roots(a)\n",
+"g=k/(s*(s+2)*(s+4))\n",
+"G=syslin('c',g)\n",
+"evans(g,8)\n",
+"xgrid(2)\n",
+"disp('the line theta=acos(zeta)=73.9 intersects root locus at sa=(-0.5+i1.66)')\n",
+"disp('the value of K at s=sa is find to be 15 for zeta=0.277')\n",
+"K=15\n",
+"k=15\n",
+"disp(r,'the point of intersection of root locus with imaginary axis =')\n",
+"g=k/(s*(s+2)*(s+4))\n",
+"cl=g/(1+g)\n",
+"disp(cl,'C(s)/R(s)=')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.49: Root_Locus_and_Value_of_K.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:root_locus_and_value_of_K\n",
+"//example 12.49\n",
+"//page 576\n",
+"s=%s;\n",
+"syms K;\n",
+"GH=(K*(s+4))/(s+2)^2\n",
+"disp('the characterstics eq. is determined as:')\n",
+"CH=(s+2)^2+(K*(s+4))\n",
+"CH=sym('((s+2)^2)+K*(s+4)');\n",
+"disp('=0',CH,'characterstics_eq,CH=')\n",
+"K=sym('((s+2)^2/(s+4))')\n",
+"d=diff(K,s)\n",
+"e=(s+2)*(s+6)\n",
+"r1=roots(e)\n",
+"disp(r1,'roots=')\n",
+"disp('-2 and -6 is break away point')\n",
+"g=(s+4)/((s+2)^2)\n",
+"G=syslin('c',g)\n",
+"clf();\n",
+"evans(g,10)\n",
+"xgrid(2)\n",
+"disp('for wd=2rad/sec,the point on root locus is s=-4+j2')\n",
+"disp('the value of K at s=-4+j2 is 4')\n",
+"K=4\n",
+"k=4\n",
+"g=k*(s+4)/((s+2)^2)\n",
+"cl=g/(1+g)\n",
+"disp(cl,'C(s)/R(s)=')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.4: Transfer_Function.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Caption:transfer_function\n",
+"// example 12.4\n",
+"//page 518\n",
+"// we are solving this problem from signal flow graph approach\n",
+"syms G1 G2 \n",
+"// forward path denoted by P1,P2 and so on and loop by L1,L2 and so on \n",
+"//path factor by D1,D2 and so on and graph determinant by D\n",
+"P1=G1;\n",
+"P2=G2;\n",
+"P3=G1*G2;\n",
+"P4=G1*G2;\n",
+"L1=-G1;\n",
+"L2=-G2;\n",
+"L3=G1*G2;\n",
+"L4=-G1*G2;\n",
+"L5=-G1*G2;\n",
+"D1=1;\n",
+"D2=1;\n",
+"D3=1;\n",
+"D4=1;\n",
+"D=1-(L1+L2+L3+L4+L5);\n",
+"Y=(P1*D1+P2*D2+P3*D3+P4*D4)/D;\n",
+"Y=simple(Y);\n",
+"disp(Y,'C(s)/R(s)=');"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.50: Root_Locus_and_Closed_loop_Transfer_Function.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:root_locus_and_close_loop_transfer_function\n",
+"//example 12.50\n",
+"//page 578\n",
+"s=%s\n",
+"K=8\n",
+"G=K/(s*(s+4))\n",
+"H=1;\n",
+"GH=G*H\n",
+"G=syslin('c',G)\n",
+"evans(G,8)\n",
+"xgrid(2)\n",
+"CH=s*(s+4)+K\n",
+"disp('=0',CH,'characterstics_eq,CH=')\n",
+"r=roots(CH)\n",
+"disp(r,'the point at which K=8')\n",
+"cl=G/(1+GH)\n",
+"disp(cl,'C(s)/R(s)=')\n",
+"\n",
+"\n",
+"\n",
+"disp('part b')\n",
+"g=K/(s+4)\n",
+"h=1/s\n",
+"gh=g*h\n",
+"CL=g/(1+gh)\n",
+"disp(CL,'C(s)/R(s)=')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.51: Root_Locus_and_Gain_and_Phase_Margin.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:root_locus_and_gain,phase_margin\n",
+"//example 12.51\n",
+"//page 580\n",
+"s=%s;\n",
+"K=3.46\n",
+"G=K/(s*(s+1)*(s+2))\n",
+"G=syslin('c',G)\n",
+"clf();\n",
+"evans(G,20)\n",
+"xgrid(2)\n",
+"[gm,freq_gm]=g_margin(G)\n",
+"[pm,freq_pm]=p_margin(G)\n",
+"disp(gm,'gain_margin=',freq_gm*2*%pi,'gain_margin_freq=')\n",
+"disp(pm,'phase_margin=',freq_pm*2*%pi,'phase_margin_freq=')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.54: Obtain_State_Matrix.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:obtain_state_matrix\n",
+"//example 12_54\n",
+"//page 583\n",
+"s=%s;\n",
+"g=5*(s+2)/(s*(s+1)*(s+5));\n",
+"CL=syslin('c',g);\n",
+"disp(CL,'C(s)/R(s)=');\n",
+"SS=tf2ss(CL)\n",
+"[Ac,Bc,U,ind]=canon(SS(2),SS(3))\n",
+"disp(SS,'state space matrix=')\n",
+"disp(Ac,'Ac',Bc,'Bc',U,'U',ind,'ind')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.55: Obtain_State_Matrix.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:obtain_state_matrix\n",
+"//example 12_55\n",
+"//page 585\n",
+"s=%s;\n",
+"g=50/(s*(s^2+0.5*s+50));\n",
+"CL=syslin('c',g);\n",
+"disp(CL,'C(s)/R(s)=');\n",
+"SS=tf2ss(CL)\n",
+"[Ac,Bc,U,ind]=canon(SS(2),SS(3))\n",
+"disp(SS,'state space matrix=')\n",
+"disp(Ac,'Ac',Bc,'Bc',U,'U',ind,'ind')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.56: Obtain_State_Transistion_Matrix.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:obtain_state_transistion_matrix\n",
+"//example 12_56\n",
+"//page 586\n",
+"s=%s;\n",
+"syms t\n",
+"A=[0 1;0 -3]\n",
+"[r c]=size(A);//size of matrix A\n",
+"p=s*eye(r,c)-A;//s*I-A where I is identity matrix\n",
+"q=det(p)//determinant of sI-A\n",
+"r=inv(p)//inverse of sI-A\n",
+"//for calculating state transistion matrix\n",
+"ip=[0 0;0 0]\n",
+"i=1;\n",
+"j=1;\n",
+"for i=1:2\n",
+" for j=1:2\n",
+" if(i==2 & j==1)\n",
+" else\n",
+" ip(i,j)=ilaplace(r(i,j),s,t);\n",
+" j=j+1;\n",
+" end\n",
+" end\n",
+" i=i+1;\n",
+"end\n",
+"r(2,1)=0\n",
+"disp(ip,'state transistion matrix,ip(t)=');"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.57: Obtain_Time_Response.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:obtain_time_response\n",
+"//example 12_57\n",
+"//page 586\n",
+"s=%s;\n",
+"syms t\n",
+"A=[0 1;-2 -3]\n",
+"B=[1 0]'\n",
+"x0=[0 0]'\n",
+"u=1/(s+1)\n",
+"[r c]=size(A);//size of matrix A\n",
+"p=s*eye(r,c)-A;//s*I-A where I is identity matrix\n",
+"q=det(p)//determinant of sI-A\n",
+"r=inv(p)//inverse of sI-A\n",
+"m=r*B*(1/(s+1));\n",
+"//for calculating zero state response\n",
+"x=[0;0]\n",
+"x(1,1)=ilaplace(m(1,1),s,t);\n",
+"x(2,1)=ilaplace(m(2,1),s,t);\n",
+"disp(x,'time response of the system,x(t)=');"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.59: Obtain_Time_Response.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:obtain_time_response\n",
+"//example 12_59\n",
+"//page 590\n",
+"s=%s;\n",
+"syms t\n",
+"A=[-1 0;1 -1]\n",
+"B=[0 1]'\n",
+"x0=[1 0]'\n",
+"[r c]=size(A);//size of matrix A\n",
+"p=s*eye(r,c)-A;//s*I-A where I is identity matrix\n",
+"q=det(p)//determinant of sI-A\n",
+"r=inv(p)//inverse of sI-A\n",
+"m=r*B*(1/s)\n",
+"r1=r*x0\n",
+"X=r1+m\n",
+"//for calculating zero state response\n",
+"x=[0;0]\n",
+"x(1,1)=ilaplace(X(1,1),s,t);\n",
+"x(2,1)=ilaplace(X(2,1),s,t);\n",
+"disp(x,'zero input response of the system,x(t)=');"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.5: Transfer_Function.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Caption:transfer_function\n",
+"// example 12.5\n",
+"//page 518\n",
+"// we are solving this problem from signal flow graph approach\n",
+"syms G1 G2 G3 G4 G5 H1 H2\n",
+"// forward path denoted by P1,P2 and so on and loop by L1,L2 and so on \n",
+"//path factor by D1,D2 and so on and graph determinant by D\n",
+"P1=G1*G4*G5;\n",
+"P2=G1*G2*G3*G5;\n",
+"L1=-G3*G5;\n",
+"L2=-G3*G5*H2;\n",
+"L3=-G1*G4*G5*H1;\n",
+"L4=-G1*G2*G3*G5*H1;\n",
+"D1=1;\n",
+"D2=1;\n",
+"D=1-(L1+L2+L3+L4);\n",
+"Y=(P1*D1+P2*D2)/D;\n",
+"Y=simple(Y);\n",
+"disp(Y,'C(s)/R(s)=');"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.61: Obtain_Transfer_Matrix.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//caption:obtain_transfer_matrix\n",
+"//example 12_61\n",
+"//page 592\n",
+"s=%s;\n",
+"syms t\n",
+"A=[-1 -1;3 -5]\n",
+"B=[1 1]'\n",
+"C=[1 2]\n",
+"[r c]=size(A);//size of matrix A\n",
+"p=s*eye(r,c)-A;//s*I-A where I is identity matrix\n",
+"q=det(p)//determinant of sI-A\n",
+"r=inv(p)//inverse of sI-A\n",
+"G=C*r*B\n",
+"disp(G,'transfer_matrix=')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.7: Determine_Peak_Time_and_Peak_Overshoot.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Caption:determine_peak_time_and_peak_overshoot\n",
+"//example 12.7\n",
+"//page 520\n",
+"s=%s;\n",
+"syms t;\n",
+"G=sym('(s+2)/(s*(s+1))')//G(s)\n",
+"H=1;\n",
+"CL=G/(1+G*H);\n",
+"disp(CL,'C(s)/R(s)=');\n",
+"//for unit step response R(s)=1/s; \n",
+"d=CL*(1/s);\n",
+"a=s*d;\n",
+"disp(d,'C(s)=');\n",
+"c=ilaplace(d,s,t);\n",
+"disp(c,'c(t)=');\n",
+"//for peak time we get tp=3*%pi/4\n",
+"tp=3*%pi/4\n",
+"Cmax=1-(exp(-tp)*cos(tp));\n",
+"Css=limit(a,s,0);\n",
+"disp(Css,'Css=');\n",
+"Mp=((Cmax-Css)/Css)*100\n",
+"Mp=float(Mp)\n",
+"disp(Mp,'peak_overshoot=')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.8: Time_Response_and_Peak_Overshoot.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Caption:time_response_and_peak_overshoot\n",
+"//example 12.8\n",
+"//page 521\n",
+"s=%s;\n",
+"syms t;\n",
+"num=sym('8*(s+1)');\n",
+"den=sym('(s^2+2*s+2)');\n",
+"CL=num/den;\n",
+"disp(CL,'C(s)/R(s)=');\n",
+"//for unit step response R(s)=1/s; \n",
+"d=CL*(1/s);\n",
+"disp(d,'C(s)=');\n",
+"c=ilaplace(d,s,t);\n",
+"disp(c,'c(t)=');\n",
+"//for peak time we get tp=%pi/2\n",
+"t=%pi/2\n",
+"a=s*d;\n",
+"a=simple(a)\n",
+"Cmax=4*(1+1.414*exp(-t)*sin(t-(%pi/4)))\n",
+"Css=limit(a,s,0);\n",
+"disp(Css,'Css=');\n",
+"Mp=((Cmax-Css)/Css)*100\n",
+"Mp=float(Mp)\n",
+"disp(Mp,'peak_overshoot=')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.9: Determine_Peak_Overshoot.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Caption:determine_peak_overshoot\n",
+"//example 12.9\n",
+"//page 523\n",
+"s=%s;\n",
+"syms t K;\n",
+"CL=sym('(s+1)/(s^2+2*s+5)');\n",
+"CL=K*CL;\n",
+"disp(CL,'C(s)/R(s)=')\n",
+"//for unit step response R(s)=1/s; \n",
+"d=CL*(1/s)\n",
+"Css=limit(s*d,s,0)\n",
+"disp(Css,'Css=');\n",
+"//since Css=0.8 (given)\n",
+"K=0.8*5;\n",
+"CL=eval(CL);\n",
+"disp(CL,'C(s)/R(s)=');\n",
+"//for unit step response R(s)=1/s; \n",
+"d=CL*(1/s)\n",
+"disp(d,'C(s)=');\n",
+"c=ilaplace(d,s,t);\n",
+"disp(c,'c(t)=');\n",
+"//for peak time we get tp=0.785\n",
+"t=0.785\n",
+"a=s*d;\n",
+"a=simple(a)\n",
+"Cmax=(4/5)*(1-exp(-t)*cos(2*%pi/4)+exp(-t)*2*sin(2*%pi/4))\n",
+"Css=limit(a,s,0)\n",
+"disp(Css,'Css=');\n",
+"Mp=((Cmax-Css)/Css)*100\n",
+"Mp=float(Mp)\n",
+"disp(Mp,'peak_overshoot=')"
+ ]
+ }
+],
+"metadata": {
+ "kernelspec": {
+ "display_name": "Scilab",
+ "language": "scilab",
+ "name": "scilab"
+ },
+ "language_info": {
+ "file_extension": ".sce",
+ "help_links": [
+ {
+ "text": "MetaKernel Magics",
+ "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md"
+ }
+ ],
+ "mimetype": "text/x-octave",
+ "name": "scilab",
+ "version": "0.7.1"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}