From b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b Mon Sep 17 00:00:00 2001 From: priyanka Date: Wed, 24 Jun 2015 15:03:17 +0530 Subject: initial commit / add all books --- 2048/CH4/EX4.1/aconv1.sce | 16 +++++++ 2048/CH4/EX4.10/respol6.sce | 15 ++++++ 2048/CH4/EX4.11/division.sce | 15 ++++++ 2048/CH4/EX4.2/aconv2.sce | 20 ++++++++ 2048/CH4/EX4.3/pz.sce | 13 +++++ 2048/CH4/EX4.4/disc1.sce | 8 ++++ 2048/CH4/EX4.5/respol.sci | 110 +++++++++++++++++++++++++++++++++++++++++++ 2048/CH4/EX4.6/respol1.sce | 13 +++++ 2048/CH4/EX4.7/respol2.sce | 24 ++++++++++ 2048/CH4/EX4.8/respol3.sce | 13 +++++ 2048/CH4/EX4.9/respol5.sce | 13 +++++ 11 files changed, 260 insertions(+) create mode 100755 2048/CH4/EX4.1/aconv1.sce create mode 100755 2048/CH4/EX4.10/respol6.sce create mode 100755 2048/CH4/EX4.11/division.sce create mode 100755 2048/CH4/EX4.2/aconv2.sce create mode 100755 2048/CH4/EX4.3/pz.sce create mode 100755 2048/CH4/EX4.4/disc1.sce create mode 100755 2048/CH4/EX4.5/respol.sci create mode 100755 2048/CH4/EX4.6/respol1.sce create mode 100755 2048/CH4/EX4.7/respol2.sce create mode 100755 2048/CH4/EX4.8/respol3.sce create mode 100755 2048/CH4/EX4.9/respol5.sce (limited to '2048/CH4') diff --git a/2048/CH4/EX4.1/aconv1.sce b/2048/CH4/EX4.1/aconv1.sce new file mode 100755 index 000000000..48b7bbb29 --- /dev/null +++ b/2048/CH4/EX4.1/aconv1.sce @@ -0,0 +1,16 @@ +// To produce a^n 1(n) +// 4.1 + +exec('stem.sci',-1); +exec('label.sci',-1); + +a = 0.9; +n = -10:20; +y = zeros(1,size(n,'*')); +for i = 1:length(n) + if n(i)>=0, + y(i) = a^n(i); + end +end +stem(n,y) +label('u1',4,'Time(n)','0.9^n1(n)',4) diff --git a/2048/CH4/EX4.10/respol6.sce b/2048/CH4/EX4.10/respol6.sce new file mode 100755 index 000000000..aad80d70b --- /dev/null +++ b/2048/CH4/EX4.10/respol6.sce @@ -0,0 +1,15 @@ +// Partial fraction expansion for Example 4.30 +// 4.10 + +// 3 - (5/6)z^-1 3z^2 - (5/6)z +// G(z) = --------------------------- = -------------------------- +// (1-(1/4)z^-1)(1-(1/3)z^-1) (z - (1/4))(z - (1/3)) + +// No equivalent of residuez + +exec('respol.sci',-1); +exec('flip.sci',-1); + +num = [3 -5/6 0]; +den = convol([1 -1/4],[1 -1/3]); +[res,pol,q] = respol(num,den) diff --git a/2048/CH4/EX4.11/division.sce b/2048/CH4/EX4.11/division.sce new file mode 100755 index 000000000..08a54e3b3 --- /dev/null +++ b/2048/CH4/EX4.11/division.sce @@ -0,0 +1,15 @@ +// Long division of problems discussed in Example 4.32 on page 102 +// 4.11 + +exec('tf.sci',-1); +exec('label.sci',-1); + +num = [11 -15 6]; +den = convol([1 -2], convol([1 -1],[1 -1])); +u = [1 zeros(1,4)]; +y = filter(num,den,u); +G = tf(num,den,-1); +u1=zeros(1,90); u1(1)=1; +x1=dsimul(tf2ss(G),u1); +plot2d(x1) +label('Impulse Response',4,'Time(seconds)','Amplitude',4) diff --git a/2048/CH4/EX4.2/aconv2.sce b/2048/CH4/EX4.2/aconv2.sce new file mode 100755 index 000000000..026cad325 --- /dev/null +++ b/2048/CH4/EX4.2/aconv2.sce @@ -0,0 +1,20 @@ +// Plot of -0.9^n1(-n-1) +// 4.2 + +exec('stem.sci',-1); +exec('label.sci',-1); + +a = 0.9; +n = -10:20; +y = zeros(1,size(n,'*')); +for i = 1: length(n) + if n(i)<= -1, + y(i) = -(a^n(i)); + else y(i) = 0; + end +end +stem(n,y) +label('u2',4,'Time(n)','-0.9^n1(-n-1)',4) + + + diff --git a/2048/CH4/EX4.3/pz.sce b/2048/CH4/EX4.3/pz.sce new file mode 100755 index 000000000..31894dd9d --- /dev/null +++ b/2048/CH4/EX4.3/pz.sce @@ -0,0 +1,13 @@ +// To produce pole-zero plots +// 4.3 + +exec('label.sci',-1); + +zero = [0 5/12]; +num = poly(zero,'z',"roots"); +pole = [1/2 1/3]; +den = poly(pole,'z',"roots"); +h = syslin('d',num./den); +plzr(h); + +label('Pole-Zero Plot',4,'Real(z)','Imaginary(z)',4); diff --git a/2048/CH4/EX4.4/disc1.sce b/2048/CH4/EX4.4/disc1.sce new file mode 100755 index 000000000..456181fe1 --- /dev/null +++ b/2048/CH4/EX4.4/disc1.sce @@ -0,0 +1,8 @@ +// Discrete transfer function of the continuous state space system +// 4.4 + +F = [0 0; 1 -0.1]; G = [0.1; 0]; +C = [0 1]; dt = 0.2; +sys = syslin('c',F,G,C); +sysd = dscr(sys,dt); +H = ss2tf(sysd); diff --git a/2048/CH4/EX4.5/respol.sci b/2048/CH4/EX4.5/respol.sci new file mode 100755 index 000000000..ea6818967 --- /dev/null +++ b/2048/CH4/EX4.5/respol.sci @@ -0,0 +1,110 @@ +// Computation of residues +// 4.5 +// Numerator and denominator coefficients +// are passed in decreasing powers of z(say) + +function [res,pol,q] = respol(num,den) +len = length(num); +if num(len) == 0 + num = num(1:len-1); +end + +[resi,q] = pfe(num,den); +res = resi(:,2); +res = int(res) + (clean(res - int(res),1.d-04)); +pol = resi(:,1); +pol = int(pol) + (clean(pol - int(pol),1.d-04)); +endfunction; + +/////////////////////////////////////////////////// +// Partial fraction expansion + +function [resid1,q] = pfe(num,den) +x = poly(0,'x'); +s = %s; + +num2 = flip(num); +den2 = flip(den); +num = poly(num2,'s','coeff'); +den = poly(den2,'s','coeff'); +[fac,g] = factors(den); +polf = polfact(den); +n = 1; + +r = clean(real(roots(den)),1.d-5); +//disp(r); +l = length(r); +r = gsort(r,'g','i'); +r = [r; 0]; +j = 1; +t1 = 1; q = []; +rr = 0; +rr1 = [0 0]; +m = 1; + + for i = j:l + if abs(r(i)- r(i+1)) < 0.01 then + r(i); + r(i+1); + n = n+1; + m = n; + //pause + t1 = i; + //disp('Repeated roots') + else + m = n; + //pause + n = 1; + end + i; + if n == 1 then + rr1 = [rr1; r(i) m]; + //pause + end; + j = t1 + 1; + end; +rr2 = rr1(2:$,:); +[r1,c1] = size(rr2); +den1 = 1; + +for i = 1:r1 + den1 = den1 * ((s-rr2(i,1))^(rr2(i,2))); +end; +[rem,quo] = pdiv(num,den); +q = quo; +if quo ~= 0 + num = rem; +end + +tf = num/den1; +res1 = 0; +res3 = [s 0]; +res5 = [0 0]; +for i = 1:r1 + j = rr2(i,2) + 1; + tf1 = tf; //strictly proper + k = rr2(i,2); + tf2 = ((s-rr2(i,1))^k)*tf1; + rr2(i,1); + res1 = horner(tf2,rr2(i,1)); + res2 = [(s - rr2(i,1))^(rr2(i,2)) res1]; + res4 = [rr2(i,1) res1]; + res3 = [res3; res2]; + res5 = [res5; res4]; + res = res1; + for m = 2:j-1 + k; + rr2(i,1); + tf1 = derivat(tf2)/factorial(m-1); //ith derivative + res = horner(tf1,rr2(i,1)); + res2 = [(s - rr2(i,1))^(j-m) res]; + res4 = [rr2(i,1) res]; + res5 = [res5; res4]; + res3 = [res3; res2]; + tf2 = tf1; + end; +end; +resid = res3(2:$,:); //with s terms +resid1 = res5(2:$,:); //only poles(in decreasing no. of repetitions) +endfunction; +//////////////////////////////////////////////////////////// diff --git a/2048/CH4/EX4.6/respol1.sce b/2048/CH4/EX4.6/respol1.sce new file mode 100755 index 000000000..1b5dba73b --- /dev/null +++ b/2048/CH4/EX4.6/respol1.sce @@ -0,0 +1,13 @@ +// Partial fraction expansion for Example 4.24 +// 4.6 + +// 2z^2 + 2z +// G(z) = --------------- +// z^2 + 2z - 3 + +exec('respol.sci',-1); +exec('flip.sci',-1); + +num = [2 2 0]; +den = [1 2 -3]; +[res,pol] = respol(num,den) //respol is a user defined function diff --git a/2048/CH4/EX4.7/respol2.sce b/2048/CH4/EX4.7/respol2.sce new file mode 100755 index 000000000..48e7875a8 --- /dev/null +++ b/2048/CH4/EX4.7/respol2.sce @@ -0,0 +1,24 @@ +// Partial fraction expansion for Example 4.26 +// 4.7 + +// z^2 + z A B C +// G(z) = ----------- = ------- + --------- + --------- +// (z - 1)^3 (z - 1) (z - 1)^2 (z - 1)^3 + +exec('respol.sci',-1); +exec('flip.sci',-1); + +num = [1 1 0]; +den = convol([1 -1],convol([1 -1],[1 -1])); // poly multiplication +[res,pol] = respol(num,den) + +// Output interpretation +// res = +//C = 2 +//B = 1 +//A = 0 + +// pol = +// 1 (z - 1)^3 +// 1 (z - 1)^2 +// 1 (z - 1) diff --git a/2048/CH4/EX4.8/respol3.sce b/2048/CH4/EX4.8/respol3.sce new file mode 100755 index 000000000..fa5574077 --- /dev/null +++ b/2048/CH4/EX4.8/respol3.sce @@ -0,0 +1,13 @@ +// Partial fraction expansion for Example 4.27 +// 4.8 + +// 11z^2 - 15z + 6 A1 A2 B +// G(z) = ----------------- = ------- + --------- + ------- +// (z - 2) (z - 1)^2 (z - 1) (z - 1)^2 (z - 2) + +exec('respol.sci',-1); +exec('flip.sci',-1); + +num = [11 -15 6]; +den = convol([1 -2],convol([1 -1],[1 -1])); +[res,pol] = respol(num,den) //User defined function diff --git a/2048/CH4/EX4.9/respol5.sce b/2048/CH4/EX4.9/respol5.sce new file mode 100755 index 000000000..146db429c --- /dev/null +++ b/2048/CH4/EX4.9/respol5.sce @@ -0,0 +1,13 @@ +// Partial fraction expansion for Example 4.29 +// 4.9 + +// z^2 + 2z +// G(z) = -------------------- +// (z + 1)^2 (z - 2) + +exec('respol.sci',-1); +exec('flip.sci',-1); + +num = [1 2 0]; +den = convol(convol([1 1],[1 1]),[1 -2]); +[res,pol] = respol(num,den) -- cgit