# Solving linear equations with Simulink : tutorial 4

In this tutorial, a block diagram is designed which will help us to solve a system of linear equations using MATLABs’ Simulink. At the start a brief introduction to a linear equations and system of linear equations are provided. After that a simple example is performed on MATLAB simulink in which a sample system of linear equations is taken and I solved for the variables involved with the help of simulink. The example taken here is to solve two linear equations for two unknowns we can however extend it for solving larger number of equations simultaneously. At the end a simple exercise is provided regarding the concepts and blocks used in this tutorial.

### Introduction to linear equation and system of linear equations

A linear equation is a mathematical term which is in the form of unknown variables whose power is one and which can be written in the form of point slope equation as given below,

y=mx+c

Where m is the slope of the line and c is the y-intercept. The graph of a linear equation is a straight line. A system of linear equations is, however, a set of linear equations which contains same variable. The number of equations is equal to the number of unknowns present in the equation. For instance, if the system contains 5 linear equations then the number of unknown or variables in all these equations collectively is also 5 with each equation satisfying the definition of linear equations (having the power of each variable equal to 1). In this tutorial we are going to solve a system of linear equations with two equations and two unknowns and the equations are given below,

2x+3y = -4

4x+5y = -5

Lets’ suppose the general system was

a1*x + b1 * y = -k1

a2*x + b2 * y = -k2

This implies that a1 = 2, b1 = 3, k1 = 4, a2 = 4, b2 = 5, k2 = 5

These values will be used in the tutorial later.

### How to solve linear equations with Simulink

Lets’ now move towards a simple example for solving the system of linear equations using Simulink.  In Simulink a block named as Algebraic Constraint will help us do the job for us. However, it is not that simple we also have to apply some logic in order to solve the system of linear equations. Lets’ now begin with the programming part. Open MATLAB and then Simulink as we have done in previous tutorials. After that open the library browser and from the library browser select the commonly used blocks as we have been doing in previous tutorials. From that section select the gain block and drag and drop that gain block on the simulink block diagram section. Place two such gain blocks as the example we have taken here is for two unknown variables, as shown in the figure below, Figure 1: Gain blocks

Figure 2: Constant block

Figure 3: Math operations

Figure 5: List of signs

Figure 7: Algebraic constraints

Figure 8: Sinks

Figure 9: Display

Figure 10: Block diagram of one equation

Figure 11: Block diagrams for both equations

Figure 12: X value

Figure 13: Y value

Figure 14: Command window

Figure 15: Variable value assignment

Figure 16: Workspace

Figure 17: Output

Exercise:

• Design a block diagram that will be able to solve three linear equations with three unknowns as provided in the equations given below,

3x+4y-2z=9 ;  5x+2y+z=0 ; x-y+5z=11