diff options
author | priyanka | 2015-06-24 15:03:17 +0530 |
---|---|---|
committer | priyanka | 2015-06-24 15:03:17 +0530 |
commit | b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch) | |
tree | ab291cffc65280e58ac82470ba63fbcca7805165 /122/CH2 | |
download | Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2 Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip |
initial commit / add all books
Diffstat (limited to '122/CH2')
-rwxr-xr-x | 122/CH2/EX2.4/exa2_4.sce | 15 | ||||
-rwxr-xr-x | 122/CH2/EX2.a.11/exaA_2_11.sce | 17 | ||||
-rwxr-xr-x | 122/CH2/EX2.a.12/exaA_2_12.sce | 18 | ||||
-rwxr-xr-x | 122/CH2/EX2.a.7/exaA_2_7.sce | 23 | ||||
-rwxr-xr-x | 122/CH2/EX2.b.14/excB_2_14.sce | 31 | ||||
-rwxr-xr-x | 122/CH2/EX2.b.14/figB2_14_a.jpg | bin | 0 -> 24937 bytes | |||
-rwxr-xr-x | 122/CH2/EX2.b.14/figB2_14_b.jpg | bin | 0 -> 19630 bytes | |||
-rwxr-xr-x | 122/CH2/EX2.b.4/excB_2_4.sce | 56 | ||||
-rwxr-xr-x | 122/CH2/EX2.b.4/figB2_4.jpg | bin | 0 -> 54004 bytes | |||
-rwxr-xr-x | 122/CH2/EX2.i.1/ils2_1.sce | 32 | ||||
-rwxr-xr-x | 122/CH2/EX2.i.2/ils2_2.sce | 31 |
11 files changed, 223 insertions, 0 deletions
diff --git a/122/CH2/EX2.4/exa2_4.sce b/122/CH2/EX2.4/exa2_4.sce new file mode 100755 index 000000000..0d4205cb1 --- /dev/null +++ b/122/CH2/EX2.4/exa2_4.sce @@ -0,0 +1,15 @@ +// Example2-4 +// Conversion from state space to transfer function model + +clear;clc;close; + +// Please edit the path below +// cd "/your code directory/"; +// exec("transferf.sci"); + +A = [0 1 0; 0 0 1;-5 -25 -5]; +B = [0; 25; -120]; +C = [1 0 0]; +D = [0]; +G = transferf(A,B,C,D); +disp(G,'transfer function = '); diff --git a/122/CH2/EX2.a.11/exaA_2_11.sce b/122/CH2/EX2.a.11/exaA_2_11.sce new file mode 100755 index 000000000..7a9edcec9 --- /dev/null +++ b/122/CH2/EX2.a.11/exaA_2_11.sce @@ -0,0 +1,17 @@ +// Example A-2-11 +// Conversion from state space model to transfer function model +// for a Single Input Single Output System + +clear; clc; close; + +// Please edit the path below +// cd "/your code directory/"; +// exec("transferf.sci"); + +A = [-1 1 0; 0 -1 1; 0 0 -2]; +B = [0; 0; 1]; +C = [1 0 0]; +D = [0]; + +Htf = transferf(A,B,C,D); // Htf is the tranfer function +disp(Htf,'Htf ='); // polynomial. ie. Htf = num / den diff --git a/122/CH2/EX2.a.12/exaA_2_12.sce b/122/CH2/EX2.a.12/exaA_2_12.sce new file mode 100755 index 000000000..8000082a9 --- /dev/null +++ b/122/CH2/EX2.a.12/exaA_2_12.sce @@ -0,0 +1,18 @@ +// Example A-2-12 +// Conversion from state space model to transfer function model +// for a multiple input multiple output system + +clear; clc; close; + +// Please edit the path below +// cd "/your code directory/"; +// exec("transferf.sci"); + +A = [0 1; -25 -4]; +B = [1 1; 0 1]; +C = [1 0; 0 1]; +D = [0 0; 0 0]; + +Htf = transferf(A,B,C,D) // Htf is the tranfer function matrix, +disp(Htf,'Htf ='); // with four transfer functions - + // Htf(1,1),Htf(1,2),Htf(2,1),Htf(2,2); diff --git a/122/CH2/EX2.a.7/exaA_2_7.sce b/122/CH2/EX2.a.7/exaA_2_7.sce new file mode 100755 index 000000000..392d82378 --- /dev/null +++ b/122/CH2/EX2.a.7/exaA_2_7.sce @@ -0,0 +1,23 @@ +// Example A-2-7 +// Transfer function to controllable form (state space) + +clear; clc;close;mode(0); + +s = %s; +Num = 2*s^3 + s^2 + s + 2; n = coeff(Num); +Den = s^3 + 4*s^2 + 5*s + 2; d = coeff(Den); +for i = 1:4 ; b(i) = n(5 - i); a(i) = d(5 - i); end + +// Method 1 +_beta(1) = b(1); +_beta(2) = b(2) - a(2)*_beta(1); +_beta(3) = b(3) - a(2)*_beta(2) - a(3)*_beta(1); +_beta(4) = b(4) - a(2)*_beta(3) - a(3)*_beta(2) - a(4)*_beta(1); + +A = [0 1 0; 0 0 1; -d(1:3)] +B = _beta(2:4) +C = [1 0 0 ] +D = b(1) + +// method 2 +H2 = cont_frm(Num,Den) diff --git a/122/CH2/EX2.b.14/excB_2_14.sce b/122/CH2/EX2.b.14/excB_2_14.sce new file mode 100755 index 000000000..1fb9b25d4 --- /dev/null +++ b/122/CH2/EX2.b.14/excB_2_14.sce @@ -0,0 +1,31 @@ +// Exercise B-2-14 + +// An illustration on Linearization +// Linearize the function y = f(x) = 0.2*x^3 at x=2 +// SOLUTION : y = 2.4*x - 3.2 + +// Let us observe graphically the linear approximation +// and the error, and percentage error + +clear; clc; xdel(winsid()); + +x = 0.05:0.05:5; +y = 0.2 * x .^ 3; + +yl = 2.4 * x - 3.2 ; // this is not a linear system! +err = abs(y - yl); //Error in approximation +errpc = err ./ y * 100; //Percentage error + +subplot(2,1,1); +plot2d(x,y,style=2); +plot2d(x,yl,style=3,leg="linearized system"); +xtitle('Original and linearized system','x','y'); + +subplot(2,1,2); +plot2d(x,err,style=5); +xtitle('Error','x','error'); + +scf(); +plot2d(x,errpc,style=5,rect=[1 0 3 100]); +plot2d(x, 10 * ones(1,length(x)) ,style=2,leg="10% error margin" ); +xtitle('Percentage Error','x','% error'); diff --git a/122/CH2/EX2.b.14/figB2_14_a.jpg b/122/CH2/EX2.b.14/figB2_14_a.jpg Binary files differnew file mode 100755 index 000000000..e75c17462 --- /dev/null +++ b/122/CH2/EX2.b.14/figB2_14_a.jpg diff --git a/122/CH2/EX2.b.14/figB2_14_b.jpg b/122/CH2/EX2.b.14/figB2_14_b.jpg Binary files differnew file mode 100755 index 000000000..624e85ccb --- /dev/null +++ b/122/CH2/EX2.b.14/figB2_14_b.jpg diff --git a/122/CH2/EX2.b.4/excB_2_4.sce b/122/CH2/EX2.b.4/excB_2_4.sce new file mode 100755 index 000000000..f43fca5e6 --- /dev/null +++ b/122/CH2/EX2.b.4/excB_2_4.sce @@ -0,0 +1,56 @@ +// Exercise B-2-4 +// Plotting the response of different types of controllers +// to unit step and unit ramp input. + +clear; clc; xdel(winsid()); + +Kp = 4; //proportional gain +Ki1 = 2; //integral gain +Td = 0.8; //differential time +Ti = 2; //integral time +Ki2 = Kp / Ti; + +s = %s; +Gi = syslin('c',Ki1/s); + +t = 0:0.05:3; +ramp = t; +subplot(3,2,1); +p1 = Kp * ones(1,length(t)); +p2 = Kp * t; +plot2d(t ,p1 , style=2); +plot2d(t ,p2 , style=3); +xtitle('Proportional control','t','y'); +legend('step input','ramp input'); +xgrid(color('gray')); + +subplot(3,2,2); +i1 = csim("step",t,Gi); +i2 = csim(ramp,t,Gi); +plot2d(t ,i1, style=2); +plot2d(t ,i2, style=3) ; +xtitle('Integral control','t','y'); +xgrid(color('gray')); +i1 = i1 * Ki2 / Ki1; //change of gain +i2 = i2 * Ki2 / Ki1; + + +subplot(3,2,3); +plot2d(t ,p1 + i1, style=2); +plot2d(t ,p2 + i2, style=3); +xtitle('Proportional integral control','t','y'); +xgrid(color('gray')); + +subplot(3,2,4); +pd1 = p1; +pd2 = p2 + Kp*Td*ones(1,length(t)); //derivative term +plot2d(t ,pd1, style=2); +plot2d(t ,pd2, style=3); +xtitle('Proportional plus derivative control','t','y'); +xgrid(color('gray')); + +subplot(3,2,5); +plot2d(t ,pd1 + i1, style=2); +plot2d(t ,pd2 + i2, style=3,leg='ramp input') ; +xtitle('P.I.D. control','t','y'); +xgrid(color('gray')); diff --git a/122/CH2/EX2.b.4/figB2_4.jpg b/122/CH2/EX2.b.4/figB2_4.jpg Binary files differnew file mode 100755 index 000000000..2bc5dc63c --- /dev/null +++ b/122/CH2/EX2.b.4/figB2_4.jpg diff --git a/122/CH2/EX2.i.1/ils2_1.sce b/122/CH2/EX2.i.1/ils2_1.sce new file mode 100755 index 000000000..4aa3a8330 --- /dev/null +++ b/122/CH2/EX2.i.1/ils2_1.sce @@ -0,0 +1,32 @@ +// Illustration 2.1 +// Section 2-3 in the book +// Demonstrating Series,Parallel and feedback connection of Linear Systems + +clear; clc; close; + +// Define Polynomials in variable 's' +// Please NOTE : The list of coeficients has to be given in +// INCREASING powers of 's', + +n1 = poly( [10] ,'s','c'); +d1 = poly( [10 2 1] ,'s','c'); // 10 + 2*s + s^2 + +// Alternate method to define transfer functions in scilab +// using '%s' +s = %s; +n2 = 5; +d2 = 5 + s; + + +G1 = syslin('c',n1,d1); //define continuous LTI systems systems +G2 = syslin('c',n2,d2); + +disp(G1,'G1 =');disp(G2,'G2 ='); //display variables on the screen + +series = G1 * G2; +parallel = G1 + G2; +feedback = G1 /. G2 ; // feedback is via G2. + +disp(series,'series ='); +disp(parallel,'parallel ='); +disp(feedback,'feedback ='); diff --git a/122/CH2/EX2.i.2/ils2_2.sce b/122/CH2/EX2.i.2/ils2_2.sce new file mode 100755 index 000000000..f300860e5 --- /dev/null +++ b/122/CH2/EX2.i.2/ils2_2.sce @@ -0,0 +1,31 @@ +// Illustration 2.2 +// Conversion from transfer function model to state space model +// Section 2-6 of the Book + +// This example demonstrates that there is no unique +// state space reperesentation of a transfer function. + +clear; clc; close; mode(0); +s = %s; +num = s; +den = 160 + 56*s + 14*s^2 + s^3; +Htf = syslin('c',num,den) + +// There are infinite state space models for the same transfer +// function. The tf2ss() function will return one of them, + +Hss = tf2ss(Htf); +ssprint(Hss); //Print the state space model + +//Alternatively: you can directly get the A,B,C,D +[A,B,C,D] = abcd(Htf) + +//To cross check, let us find the transfer function +Htf2 = clean(ss2tf(Hss)) //which matches with Htf + + + +Hssc = cont_frm(Htf.num,Htf.den) +Htfc = clean(ss2tf(Hssc)) + +// The same transfer function again
\ No newline at end of file |