MATLAB Assignment 1
MATLAB Assignment 1
To compute the inverse Laplace transform using MATLAB's Symbolic Math Toolbox, first, define the Laplace variable using 'syms s'. Then, use the 'ilaplace' function on the expression. For example, for the function F(s) = 3/(s*(s^2 + 2*s + 5)), you define 'f = ilaplace (3 / (s * (s^2 + 2*s + 5)))' to obtain the inverse Laplace transform in the time domain. The 'pretty' function can be used afterwards to display the result in a readable format .
To diagonalize a system matrix in MATLAB, use the 'eig' function to compute the eigenvectors and eigenvalues. For a matrix A, define the system and use '[P, D] = eig(A)' to get the transformation matrix P and the diagonal matrix D. To express the system in its diagonal form use 'Adt = inv(P) * A * P'. The transformed B and C matrices can be computed as 'Bdt = inv(P) * B' and 'Cdt = C * P'. This process transforms the system but retains its controllability and observability .
To find the partial fraction expansion of a transfer function in MATLAB, you use the 'residue' command. For example, for the transfer function F(s) = 2 / ((s+1)(s+2)^2), you define the numerator as 'numf = 2' and the denominator using 'denf = poly([-1, -2, -2])'. Then, use '[K, p, k] = residue(numf, denf)' to obtain the residues (K), poles (p), and direct terms (k) of the partial fraction expansion .
Performing a similarity transformation involves altering a system's state-space matrices A, B, C using a transformation matrix P. Given Pinv (an inverse transformation matrix), define P as 'P = inv(Pinv)'. For a state-space system with A = [0, 1, 0; 0, 0, 1; -2, -5, -7], perform the transformation with 'Az = Pinv * A * P', 'Bz = Pinv * Bx', where Bx is the input matrix, and 'Cz = Cx * P', where Cx is the output matrix .
To convert a state-space representation to a transfer function in MATLAB, define the state-space matrices A, B, C, and D. For instance, if A = [0, 1, 0; 0, 0, 1; -9, -8, -7], B = [7; 8; 9], C = [2, 3, 4], and D = 0, use '[num, den] = ss2tf(A, B, C, D)' to obtain the transfer function in polynomial form. Alternatively, use 'F = ss(A, B, C, D)' followed by 'F_tf = tf(F)' to convert it to transfer function form with the tf command .
In MATLAB, to plot the step responses of multiple systems simultaneously, define the transfer functions of each system, such as T1, T2, and T3 using the 'tf' command to define each system with its respective numerator and denominator. Use the 'step' command to plot these responses together: 'step(T1, T2, T3)'. This command displays the step responses all on the same graph, and using 'title('Step Responses of T1(s), T2(s), and T3(s)')' to label the plot appropriately .
From the poles of a second-order system, such as -3 ± 7i, you can derive the natural frequency (ωn), damping ratio (ζ), settling time (Ts), peak time (Tp), and percent overshoot (%OS). Use MATLAB commands like 'omegan = sqrt(deng(3) / deng(1))' for natural frequency, 'zeta = (deng(2) / deng(1)) / (2 * omegan)' for damping ratio, 'Ts = 4 / (zeta * omegan)' for settling time, 'Tp = pi / (omegan * sqrt(1 - zeta^2))' for peak time, and 'pos = 100 * exp(-zeta * pi / sqrt(1 - zeta^2))' for percent overshoot .
To convert a transfer function from a zero-pole-gain representation to a numerator-denominator form in MATLAB, the 'tf' command is used. For instance, if you have a transfer function with zeros at [], poles at [-1, -2, -2], and a gain of 2, you use the command 'F = zpk([], [-1, -2, -2], 2)' to represent it in zero-pole-gain form. Then, 'F_tf = tf(F)' converts it to numerator-denominator form, providing the transfer function representation in terms of its polynomial coefficients .
To find the roots of a polynomial in MATLAB, use the 'roots' command. For example, for the polynomial 5s^4 + 7s^3 + 9s^2 - 3s + 2, define it as 'P = [5, 7, 9, -3, 2]', then 'roots(P)' returns its roots. For polynomial multiplication, use the 'conv' command. To multiply (s^3 + 7s^2 + 10s + 9) and (s^4 - 3s^3 + 6s^2 + 2s + 1), define each as vectors and apply 'conv([1, 7, 10, 9], [1, -3, 6, 2, 1])' to get the resultant coefficients .
To perform block diagram reduction in MATLAB, define the transfer functions using commands like 'tf' for the blocks based on their numerators and denominators. Use 'series', 'parallel', and 'feedback' commands to connect these transfer functions based on their configuration. For example, use 'G4 = series(G2, G3)' to connect G2 and G3 in series, 'G5 = feedback(G4, H1)' to account for feedback, and finally 'Ge = series(G1, G5)' to connect in series with G1. Use 'T = feedback(Ge, 1)' to get the equivalent transfer function from R(s) to Y(s).