# Solving Linear Systems Assignments Using MATLAB for Discretization, State Transition Matrices, and State Realization

August 05, 2024
Emma Richards
Australia
Linear System
Emma Richards has over 12 years of experience, completed her Master's in Electrical Engineering at the University of Melbourne, Australia.

Linear systems assignments, particularly within control systems and signal processing domains, often present challenges that require a deep understanding of mathematical concepts and practical implementation skills. These assignments typically include tasks such as discretization of systems, finding state transition matrices, and realizing state equations from given matrices. This blog will walk you through a general approach to solving such MATLAB assignment, applicable to various similar problems. By the end, you'll be well-equipped to tackle your linear systems assignment with confidence.

## Discretizing a Linear Time-Invariant (LTI) System

Discretizing an LTI system is a crucial process, especially when dealing with digital controllers or simulations. This process involves converting a continuous-time system into a discrete-time system using a specified sampling time.

### Example Problem:

Discretize the system below using a sample time of T=1T = 1T=1 second.

### Steps to Solve:

1. Define the System Matrices:

2. Use MATLAB Functions:

The c2d function in MATLAB is used to discretize the system.

• A = [-2 0; 1 0];
• B = [1; 0];
• C = [0 1];
• D = 2;
 sys = ss(A, B, C, D); Ts = 1; % Sample time sys_d = c2d(sys, Ts); [Ad, Bd, Cd, Dd] = ssdata(sys_d); 
• Explanation:
• A, B, C, and D are the matrices defining the continuous-time state-space system.
• ss creates the state-space model.
• c2d converts the continuous-time model to a discrete-time model using the specified sampling time Ts=1T_s = 1Ts=1 second.
• ssdata extracts the discrete-time system matrices AdA_dAd, BdB_dBd, CdC_dCd, and DdD_dDd.

2. Interpreting the Results:

After running the MATLAB code, you will obtain the discrete-time state-space matrices. These matrices represent the system in discrete-time, allowing for digital implementation and analysis.

## Finding the Fundamental Matrix and State Transition Matrix for a Linear Time-Varying (LTV) System

The state transition matrix is essential for solving the state-space equations of time-varying systems. It provides insight into how the state of the system evolves over time.

### Example Problem:

Find a fundamental matrix and the state transition matrix ϕ(t,t0) for:

Use (linearly independent) initial values of [1/0] and [0/1] respectively

### Steps to Solve:

1. Define the System Matrix:

Solve the State Transition Matrix:

• The state transition matrix can be found using the method of integrating the system matrix. This is generally done numerically using MATLAB's ode45 or other ODE solvers.
 syms t; A = [-1, exp(2*t); 0, -1]; [V, D] = eig(A); Phi = V * expm(D * t) / V; 
• Explanation:
• The syms function is used to define the symbolic variable t.
• A is defined as a function of t.
• eig computes the eigenvalues and eigenvectors of the matrix A.
• expm calculates the matrix exponential.
• The fundamental matrix Φ\PhiΦ is constructed using the eigenvalues and eigenvectors.

2. Interpreting the Results:

• The resulting matrix Φ\PhiΦ represents the state transition matrix. This matrix is crucial for analyzing the behavior of the time-varying system over a period.

## Finding a State Equation Realization from a Given Rational Matrix

State realization involves finding a state-space representation (A, B, C, D matrices) from a given transfer function or rational matrix. This process is fundamental in control systems for designing controllers and observers.

### Example Problem:

Find a state equation realization for the given rational matrix:

### Steps to Solve:

1. Express in Partial Fraction Form:

• Decompose the rational matrix into simpler terms if necessary.
• Use MATLAB's tf and ss functions.
 num = {-12 6; 22 23}; den = {3 34; 3 34}; sys_tf = tf(num, den); sys_ss = ss(sys_tf); [A, B, C, D] = ssdata(sys_ss); 
• Explanation:
• num and den represent the numerators and denominators of the transfer function elements.
• tf creates the transfer function model.
• ss converts the transfer function to a state-space model.
• ssdata extracts the state-space matrices AAA, BBB, CCC, and DDD.

2. Interpreting the Results:

• After running the MATLAB code, you will obtain the state-space matrices representing the system. These matrices are used for further analysis and controller design.

## Practical Tips for Solving Linear Systems Assignments

### Understanding the Problem Statement

• Carefully read the problem statement to understand what is required.
• Identify the type of system (LTI, LTV) and the specific tasks (discretization, state transition, realization).

### Formulating the Mathematical Model

• Write down the system equations and matrices.
• Ensure you understand the physical meaning of each parameter and variable.

### Utilizing MATLAB Efficiently

• Familiarize yourself with MATLAB functions relevant to control systems and signal processing.
• Use help and doc commands in MATLAB to get detailed information on functions.

### Debugging and Verification

• Check your code for errors by running smaller test cases.
• Compare your results with analytical solutions if available.
• Use MATLAB's plotting functions to visualize the system behavior.

### Consulting Resources

• Refer to textbooks on control systems and linear algebra for theoretical background.
• Use online forums and MATLAB documentation for additional support.

## Conclusion

By understanding the underlying principles and utilizing MATLAB's powerful functions, you can solve a wide range of linear systems assignments. Whether it's discretizing continuous systems, finding state transition matrices for time-varying systems, or realizing state equations from rational matrices, MATLAB provides robust tools to tackle these problems efficiently. Always start by defining your system matrices and then use the appropriate MATLAB functions to perform the required operations. This approach ensures a systematic and accurate solution to your linear systems assignments.