Anda di halaman 1dari 6

EXAMPLE 2.7 EXAMPLE 2.

9
A.) >> x = [0 : 0.1 : 15];
>> n = [1 6 5 4 3]; >> w = 10;
% n = s ^ 4 + 6s ^ 3 + 5s ^ 2 + 4s + 3 >> y = exp(– 0.6*x).*cos(w*x);
>> d = [1 7 6 5 4 7]; >> plot(x, y)
% d = s ^ 5 + 7s ^ 4 + 6s ^ 3 + 5s ^ 2 + 4s + 7 >> title(‘y(x) = e^-^0^.^6^x cos\omega x’)
>> n2 = polyval(n, [– 10]) >> xlabel(‘x’)
n2 = 4463 >> ylabel(‘y’)
>> nn10 = polyval(n, [– 10])
nn10 = 4463 EXAMPLE 2.10
>> n5 = polyval(n, [– 5]) A.)
nn5 = – 17 t = linspace(0, 2*pi, 200);
>> nn3 = polyval(n, [– 3]) r = sqrt(abs(5*cos(3*t)));
nn3 = – 45 polar(t, r)
>> nn1 = polyval(n, [– 1])
nn1 = – 1 B.)
t = linspace(0, 2*pi, 200);
B.) r = sqrt(abs(5*cos(3*t)));
>> dn10 = polyval(d, [– 10]) d x = r.*cos(t);
n10 = – 35533 y = r.*sin(t);
>> dn5 = polyval(d, [– 5]) fill(x, y, ‘k’),
dn5 = 612 axis(‘square’)
>> dn3 = polyval(d, [– 3])
dn3 = 202 C.)
>> dn1=polyval(d, [– 1]) x = 1 : 0.1 : 20;
dn1 = 8 y1 = exp(– 2*x).*cos(x);
y2 = exp(2*x);
C.) Ax = plotyy(x, y1, x, y2);
>> Hn10 = nn10/dn10 hy1 = get(Ax(1), ‘ylabel’);
Hn10 = – 0.1256 hy2 = get(Ax(2), ‘ylabel’);
>> Hn5 = nn5/dn5 set(hy1, ‘string’, ‘exp(– 2x).cos(x)’)
Hn5 = – 0.0278 set(hy2, ‘string’, ‘exp(– 2x)’);
>> Hn3 = nn3/dn3
Hn3 = – 0.2228 D.)
>> Hn1 = nn1/dn1 x = linspace(– 5*pi,5*pi,100);
Hn1 = – 0.1250 y = cos(x)./x;
area(x, y);
EXAMPLE 2.8 xlabel(‘x (rad)’), ylabel(‘cos(x)/x’)
>> x = [0 : 0.1 : 15]; hold on
>> w = 15;
>> y = exp(– 0.7*x).*sin(w*x); E.)
>> plot(x, y) t = linspace(0, 2*pi, 200);
>> title(‘y(x) = e^-^0^.^7^x sin\omega x’) f = exp(– 0.6*t).*sin(t);
>> xlabel(‘x’) stem(t, f)
>> ylabel(‘y’)
F.)
r = – 7 : 0.2 : 7;
[X, Y] = meshgrid(r, r);
Z = – 0.333*X.^2 + 2*X.*Y + Y.^2;
cs = contour(X, Y, Z);
label(cs)
EXAMPLE 2.11 C.)
A.) % Mesh Curtain Plot
u = – 7 : 0.2 : 7; >> x = – 4.0 : 0.25 : 4;
[X, Y] = meshgrid(u, u); >> y = – 4.0 : 0.25 : 4;
Z = cos (X).*cos (Y).*exp(– sqrt(X.^2 + Y.^2)/5); >> [x, y] = meshgrid(x, y);
surf(X, Y, Z) >> z = 2.0.^(– 1.5*sqrt(x.^2 +
y.^2)).*cos(0.5*y).*sin(x);
B.) >> mesh z(x, y, z)
t = linspace(0, 5*pi, 200); >> xlabel(‘x’); ylabel(‘y’)
x = t ; y = t.*cos(t); >> zlabel(‘z’)
z = exp(t/5) – 2;
stem3(x, y, z, ‘filled’); D.)
xlabel(‘t’), ylabel (‘t cos(t)’), zlabel (‘e^t/5 – 1’) % Mesh and Contour Plot
>> x = – 4.0 : 0.25 : 4;
C.) >> y = – 4.0 : 0.25 : 4;
z =[0 : 0.2 : 1]’; >> [x, y] = meshgrid (x, y);
r = sin(5*pi*z)+3; >> z = 2.0.^(– 1.5*sqrt(x.^2 +
cylinder(r) y.^2)).*cos(0.5*y).*sin(x);
EXAMPLE 2.12 >> meshc(x, y, z)
% Line plots >> xlabel(‘x’); ylabel(‘y’)
>> t = [0:0.1:6*pi]; >> zlabel(‘z’)
>> x = sqrt(t).*sin(3*t);
>> y = sqrt(t).*cos(3*t); E.)
>> z = 0.8*t; % Surface and Contour Plot
>> plot3(x, y, z, ‘k’, ‘linewidth’, 1) >> x = – 4.0 : 0.25 : 4;
>> grid on >> y = – 4.0 : 0.25 : 4;
>> xlabel (‘x’); ylabel (‘y’) ; zlabel (‘z’) >> [x, y] = meshgrid(x, y);
>> z = 2.0. ^ (– 1.5*sqrt (x. ^2 + y. ^2)).*cos
EXAMPLE 2.14 (0.5*y).*sin(x);
A.) >> surfc(x, y, z)
% Mesh Plot >> xlabel(‘x’); ylabel(‘y’)
>> x = – 4 : 0.25 : 4; >> zlabel(‘z’)
>> y = – 4 : 0.25 : 4;
>> [x, y] = meshgrid(x, y); EXAMPLE 2.15
>> z = 2.^(– 1.5*sqrt(x.^2 + A.)
y.^2)).*cos(0.5*y).*sin(x); % Surface Plot with lighting
>> mesh(x, y, z) >> x = – 4.0 : 0.25 : 4;
>> xlabel(‘x’); y label(‘y’) >> y = – 4.0 : 0.25 : 4;
>> zlabel(‘z’) >> [x, y] = meshgrid(x, y);
>> z = 2.0.^(– 1.5*sqrt(x.^2 +
B.) y.^2)).*cos(0.5*y).*sin(x);
% Surface Plot >> surfl(x, y, z)
>> x = – 4 : 0.25 : 4; >> xlabel(‘x’); ylabel(‘y’)
>> y = – 4 : 0.25 : 4; >> zlabel(‘z’)
>> [x, y] = meshgrid(x, y);
>> z = 2.0.^(– 1.5*sqrt(x.^2 + B.)
y.^2)).*cos(0.5*y).*sin(x); % Waterfall Plot
>> surf(x, y, z) >> x = – 4.0 : 0.25 : 4;
>> xlabel(‘x’); y label (‘y’) >> y = – 4.0 : 0.25 : 4;
>> zlabel(‘z’) >> [x, y] = meshgrid(x, y);
>> z = 2.0.^(– 1.5*sqrt(x.^2 + E.)
y.^2)).*cos(0.5*y).*sin(x); %Use of stairs command
>> waterfall(x, y, z) >> t = linspace(0, 2*pi, 200);
>> xlabel(‘x’); ylabel(‘y’) >> r = sqrt(abs(3*sin(7*t)));
>> zlabel(‘z’) >> y = r.*sin(t);
>> stairs(t, y)
C.) >> axis([0 pi 0 inf]);
% 3-D Contour Plot
>> x = – 4.0 : 0.25 : 4; F.)
>> y = – 4.0 : 0.25 : 4; % Use of bar command
>> [x, y] = meshgrid(x, y); >> t = linspace(0, 2*pi,200);
>> z = 2.0.^(– 1.5*sqrt(x.^2 + >> r = sqrt(abs(3*sin(4*t)));
y.^2)).*cos(0.5*y).*sin(x); >> y = r.*sin(t); >> bar(t, y)
>> contour3(x, y, z, 15) >> axis([0 pi 0 inf]);
>> xlabel(‘x’) ; ylabel(‘y’)
>> zlabel(‘z’) G.)
%use of comet command
D.) >> q = linspace(0, 5*pi, 200);
% 3-D Contour Plot >> y = q.*sin(q);
>> x = – 4.0 : 0.25 : 4; >> comet(q, y)
>> y = – 4.0 : 0.25 : 4;
>> [x, y] = meshgrid(x, y); EXAMPLE 2.17
>> z = 2.0.^(– 1.5*sqrt(x.^2 + >> A = [3 2*pi ; 5j 10 + sqrt(2)*j];
y.^2)).*cos(0.5*y).*sin(x); >> B = [7j –15j ; 2*pi 18];
>> contour3(x, y, z, 15) A.) >>A + B
>> xlabel(‘x’) ; ylabel(‘y’) B.) >> A * B
>> zlabel(‘z’) C.) >> A ^ 2
D.) >> inv(A)
EXAMPLE 2.16 E.) >> B ^ – 1
A.) F.) >> inv(B) * inv(A)
% Use of plot command G.) >> (A ^ 2 + B ^ 2) – (A * B)
>> fplot(‘x.*cos(x)’, [0, 10*pi])
B.) EXAMPLE 2.19
% Semilog x command A.)
>> t = linspace(0, 2 * pi, 200); A = [4 – 1 5 ; 2 1 3 ; 6 – 7 9]
>> x = exp(– 2 * t); y = t; %The eigenvalues of A
>> semilog x (x, y),grid format short e
eig(A)
C.) %The eigenvectors of A
% Semilog x command [Q, d] = eig(A)
>> t = linspace(0, 2 * pi, 200);
>> x = exp(– 2 * t); y = t; B.)
>> semilog x (x, y),grid %The eigenvalues of A
format short e
D.) eig(A)
% Use of loglog command %The eigenvectors of A
>> t = linspace(0, 2 * pi, 200); [Q, d] = eig(A)
>> x = exp(t); >> y = 50 + exp(t);
>> loglog(x, y), grid
EXAMPLE 2.20 >> int (S3, ‘a’, ‘b’)
% MATLAB Program
% The matrix D.)
“a” = A * B >> S4 = 7*x^5 – 6*x^4 + 11*x^3 + 4*x^2 + 8 * x –
>> A = [ 3 0 2 1; 1 2 5 4; 7 – 1 2 6; 1 – 2 3 4 ]; 9
>> B = [ 1 3 5 7; 2 – 1 – 2 4; 3 2 1 1; 4 1 0 6 ]; >> int (S4)
>> a = A * B
>> eig (a) E.)
>> [Q, d] = eig (a) >> S5 = cos (a)
>> int (S5)
EXAMPLE 2.21
A.) EXAMPLE 2.24
>> A = [1 2 3 5 ; – 2 5 7 – 9 ; 5 7 2 – 5 ; – 1 – 3 – 7 A.) >> solve (‘Dy = 5*t – 6*y’)
7]; B.) >> dsolve (‘D2y + 3*Dy + y = 0’)
>> B = [21 ; 18 ; 25 ; 30] ; C.) >> dsolve (‘Ds = A*x^3’, ‘x’)
>> S = A\B D.) >> dsolve (‘Ds = A*x^3’, ‘A’)

B.) EXAMPLE 2.25


>> A = [1 2 3 4 ; 2 – 2 – 1 1 ; 1 – 3 4 – 4 ; 2 2 – 3 A.) >> dsolve (‘Dy = – 7*x^2’, ‘y (1) = 0.7’)
4]; B.) >> dsolve (‘Dy = 5*x*cos (y) ^2’, ‘y (0) =
>> B = [8 ; – 3 ; 8 ; – 2]; pi/4’)
>> S = A\B C.) >> dsolve (‘Dy = – y + exp (3*x)’, ‘y (0) =
2’)
EXAMPLE 2.22 D.) >> dsolve (‘Dy + 5*y = 35’, ‘y (0) = 4’)
A.)
>> syms x EXAMPLE 2.26
>> S1 = exp(x ^ 8); A.) x(t) when all the initial conditions are
>> diff (S1) zero
>> x = dsolve (‘D2x = – 7*Dx – 5*x + 8’,
B.) ‘x(0) = 0’)
>> S2 = 3* x ^3*exp(x^5); B.) x(t) when all the initial conditions are
>> diff (S2) zero
>> x = dsolve (‘D2x = – 7*Dx – 5*x + 8’,
C.) ‘x(0) = 0’)
>> S3 = 5*x^3 – 7*x^2 + 3*x + 6;
>> diff (S3) EXAMPLE 2.27
A.) x (t) when all the initial conditions are
EXAMPLE 2.23 zero
A.) >> x = dsolve (‘D2x = – 12*Dx – 15*x
>>syms x, y, a, b +35’, ‘x (0) = 0’)
>> S1 = abs(x)
>> int (S1, 0.2, 0.7) B.) x (t) when x (0) = 0 and x(0) = 1.
>> x = dsolve (‘D2x = – 12*Dx – 15*x +
B.) 35’, ‘x (0) = 0’, ‘Dx (0) = 1’)
>> S2 = cos (y) + 7*y^2
>> int (S2, 0, pi) EXAMPLE 2.28
>> A = [s 2 0 ; 2 s – 3 ; 3 0 1] ;
C.) >> inv (A)
>> S3 = sqrt (x)
>> int (S3)
>> int (S3, ‘a’, ‘b’)
EXAMPLE 2.29 % define the function.
>> b = [0 0 0 0 1]; >> laplace(f)
>> a = [1 5 7 0 0]; >> pretty(laplace(f))
>> [r, p, k] = residue (b, a) % the pretty function prints symbolic output
% From the above MATLAB output, we have the % in a format that resembles typeset
following expression: mathematics.
% Note that the row vector k is zero implies that
there is no constant term in this example B.)
problem. >>syms t x
% The MATLAB program for determining the >>f = – 7*t*exp(– 5*t);
inverse Laplace transform of F(s) is given below: >> laplace(f, x)
>> syms s C.)
>> f = 1/(s^4 + 5*s^3 + 7*s^2); >>syms t x
>> ilaplace (f) >>f = – 3*cos(5*t);
>> laplace(f, x)
EXAMPLE 2.30
>> b = [0 0 5 3 6]; D.)
>> a = [1 3 7 9 12]; >>syms t x
>> [r, p, k] = residue(b, a) >>f = t*sin(7*t);
% From the above MATLAB output, we have the >> laplace(f, x)
following expression:
% Note that the row vector k is zero implies that E.)
there is no constant term in this example >>syms t x
problem. >>f = 5*exp(– 2*t)*cos(5*t);
% The MATLAB program for determining the >> laplace(f, x)
inverse Laplace transform of F(s) is given below:
>> syms s F.)
>> f = (5*s^2 + 3*s +6)/(s^4 + 3*s^3 + 7*s^2 + >>syms t x
9*s +12); >>f = 3*sin(5*t + (pi/4));
>> ilaplace(f) >> laplace(f, x)

EXAMPLE 2.31 G.)


num = [ 1 3 5 7 25]; >>syms t x
den = [1 5 20 40 45]; >>f = 5*exp(– 3*t)*cos(t – (pi/4));
[r, p, k] = residue(num, den) >> laplace(f, x)
EXAMPLE 2.32
>> num = conv([8 8], [1 3]); EXAMPLE 2.35
>> den = conv([1 6 8], [1 12 36]); A.) >> syms s
>> [r, p, k] = residue(num, den) >> f = s/(s*((s + 2)*(s + 6)));
>> ilaplace(f)
EXAMPLE 2.32
>> num = conv([8 8], [1 3]);
>> den = conv([1 6 8], [1 12 36]); B.) >> syms s
>> [r, p, k] = residue(num, den) >> f = 1/((s^2)*(s + 5));
>> ilaplace(f)
EXAMPLE 2.33
A.) C.) >>syms s
% MATLAB Program >> f = (3*s + 1)/(s^2 + 2*s + 9);
>> syms t >> ilaplace(f)
% tell MATLAB that “t” is a symbol.
>> f = 7 * t^3*cos(5*t + (pi/3));
D.) >>syms s
>> f = (s – 25)/(s*(s^2 + 3*s + 25));
>> ilaplace(f)

EXAMPLE 2.36
% MATLAB Program
>> syms s
% tell MATLAB that “s” is a symbol.
>>G = (s^2 + 9*s +7)*(s + 7)/[(s + 2)*(s + 3)*(s^2
+ 12*s + 150)];
% define the function.
>>pretty(G)
% the pretty function prints symbolic output
% in a format that resembles typeset
mathematics.
>> g = ilaplace(G);
% inverse Laplace transform
>>pretty(g)

EXAMPLE 2.38
% MATLAB Program:
% a. the ratio of factors
>>Gtf = tf([1 20 27 17 35] , [1 8 9 20 29 32]) %
generate the
% transfer function
% Computer response:
% b. the ratio of polynomials
>> Gzpk = zpk(Gtf) % zpk is used to create zero-
pole-gain models
% or to convert TF or SS models to zero-pole-
gain form.
% Computer response:

Anda mungkin juga menyukai