Special Types of Matrices in MATLAB

Hey students welcome to another tutorial in The Engineering Projects where we are going to learn a lot about matrices. If you are a beginner to the metrics, then you should go to learn the fundamentals of matrices. Yet, if you know the basic introduction, you are at the right lecture because we are learning about the special kinds of matrices and you are also going to see the matrices in action using MATLAB. So, here is a simple list of today’s topics. 

  • What is a matrix?

  • How can we identify the matrix with the help of its general form?

  • What are the different types of matrices?

  • What is the concept of transpose while dealing with matrices?

  • How can we implement these types of matrices in MATLAB by different commands?

What is a Matrix?

A matrix is a type of array that stores data of the same kind. It has great importance in the world of technology and it is defined as:

"A matrix takes the form of an ordered rectangular array surrounded by a square bracket and has entries of the same kind in the form of real or complex data."

To perform different operations on the matrices, you just have to apply them to the whole matrix at once; there is no need to apply them to all the entries one after the other. This will make sense when you see the matrices in action. 

Till now, we have learned about the basic introduction of the following types of matrices:

  • Row matrix

  • Column matric

  • Square matrix

  • Rectangular matrix

These are the basic types irrespective of the elements or entries present in them, and now, we are going to discuss some types that have the features of these matrices but the entries in them are in a specific pattern, so they are considered the special kinds of matrices. Before going into the details of each of them, there must be the foundation of a concept of a general form of the matrix. 

The General Form of the Matrix

To examine the location of a specific element, we use the terms "rows” and “columns” where

  1. Rows are the horizontal entries of the matrix.

  2. Columns are the vertical entries of the matrix.

A specific element is the part of a row and column at a time and to mention the location of an element, it is important to know the information about both of them. So, in the general form, a three-by-three matrix is shown as:

Where

  • A= name of the matrix
  • a= elements of the matrix A

Notice that a has two numbers with them in which the first number denotes the rows and the second one is the number of columns. To make it easier, we denote rows with i and columns with j. So we can say,

  • aij=a23=element of the second row and first column

Keeping this concept in mind, now it is easy to understand the types of matrices in which the value of the elements matters. Have a look at some of these types.

Identity Matrix

The identity matrix is a special kind of matrix having the arrangement of entries in such a way that all the diagonal entries are one and the remaining ones are all zero. In this way, we get the matrix of the form:

You can observe that for an identity matrix, the elements where i=j are all ones, and all the elements other than this are zero. There are certain applications of the identity matrix and you will know them in the upcoming lectures. 

Zero or Null Matrix

Here is an interesting type of matrix. This matrix has all the entries zero and no other value can be found in this element. So we assume the zero or null matrix as:

Where the sequence of the matrix can be any. No matter whether it square, row, or rectangular matrix. 

Singular Matrix

A singular matrix is the type of square matrix that has the determinant equal to zero. It is possible in the condition when all the entries of the matrix have the value one.

We all know the procedure to find the determinant. So, taking the determinant of this matrix C, we provide ourselves with the following calculations:

|C|=1x[(1x1) - (1x1)] - 1x [(1x1)-(1x1)] + 1x[(1x1)-(1x1)]

    =1x(1-1) - 1x(1-1) + 1x(1-1)

    =1x(0) - 1x(0) + 1x(0)

    = 0 - 0 + 0

    =0

So in general, we say, in a singular matrix:

|C| =0

Non-singular Matrix

A non-singular matrix, on the other hand, has entries in such a way that the determinant is never zero. So, we can say, most of the matrices are included in a non-singular type of matrix. Here is an example of a non-singular matrix, which we have also mentioned in other categories.

|C|=3x[(-6x7) - (1x-1)] - 0x [(2x7)-(1x4)] + (-5)x[(2x-1)-(-6x4)]

    =3x(-42+1) - 0x(14-4) - 5x(-2+24)

    =1x(-41) - 0x(-10) + 5x(22)

    = -41 - 0 + 110

    =69

Hence, we can conclude for the non-singular matrix that if A is a non-singular matrix, then:

|A|≠ 0

Diagonal Matrix

The concept of diagonal was used in the identity matrix, but it is a slightly different case. A diagonal matrix is one that has all the entries, other than the diagonal, equal to zero. The values in the diagonal may be anything. 

Here, one concept must be clear. In some cases, all the diagonal values except one may be zero, but it will still be called the diagonal matrix. In other words, by changing even one of the values in the null matrix, we can convert it into the diagonal matrix. 

Scalar Matrix

A scalar matrix has all the diagonal values the same, no matter what the value is, and all other values are zero. So, in the scaler matrix, three conditions must be satisfied:

  1. The values other than the diagonal are all zero. 

  2. The values in the diagonal must be non-zero.

  3. All the values of the diagonal are the same, no matter what the value is. 

  4. The matrix is a square matrix.

If one of the conditions is not satisfied, it is not a scalar matrix. 

Upper Triangular Matrix

This is an interesting type of matrix. The upper triangular matrix can be recognized when all the entries below the diagonals are zero and the entries above the diagonal are non-zero. So we get the matrix as:

The value in the diagonal must be non-zero for at least one value. And the 

The Lower Triangular Matrix

As you can guess, the lower triangular matrix has non-zero values in the lower elements than the diagonal. The values presented in the upper portion of the diagonal are all zero. So the lower triangular matrix looks like this:

Transpose of a Matrix

This is another concept in matrices that is important to discuss here because some types of matrices depend upon it. We know that a matrix has i rows and j columns. Then, the transpose of the matrix is defined as:

The transpose of matrix A, denoted by AT , is obtained when the rows and columns of matrix A are interchanged no matter what the total number of rows and columns. 

This concept is used in different ways, and the results obtained are important. To understand well, you must know, that a rectangular matrix of order 2 by 3 will be converted into a matrix of order 2 by 3 when the transpose is applied to it. 

Symmetrix Matrix

It is a special kind of matrix that involves the procedure of transpose. A skew-symmetric matrix is one that has the arrangement of elements in such a way that applying the transposed result in the matrix that has the same entries and same order. In other words:

AT=A

So, the skew-symmetric matrix is always a square.

The Skew Symmetrix Matrix

Here is another kind of square matrix that involves the transpose, and it is slightly different from the one discussed just before. This type of matrix, after taking the transpose, results in a matrix with all the negative values. So we define this in a simple way as

AT=-A

Harmatian Matrix

A hermitian matrix involves complex numbers in it. That means some, or all the elements of a matrix A are complex numbers, and the transpose of that matrix A results in the transpose of a conjugate matrix. So, the following conditions are applied to the hermitian matrix:

  • It is a square matrix.

  • It involves complex numbers.

  • A conjugate of the matrix is obtained. 

  • The resultant matrix has the conjugate values.

    The Skew Harmatian Matrix

    A skew hermitian matrix, with the complex conjugate, is the one that involves the negative values of the original matrix ( the one before the transpose procedure). It will be crystal clear to you when you examine the case given below:

    Special Matrices in MATLAB

    Are you enjoying the different types of matrices? Matrices are fun in MATLAB, it is good practice if we attempt all these types in MATLAB. Notice that, these types follow a specific sequence. Hence, MATLAB has a special function designed for the user with the help of which, one can have all these types by simply writing some commands. But it would be helpful if you understood the commands first.


    Command

    Description

    eye(a,b)

    It creates an identity matrix.

    Where

    a=number of rows

    b=numbers of columns


    triu(A)

    It converts the matrix A into the upper triangle.

    tril(A)

    It converts matrix A into the lower triangle.

    null(a,b)

    It creates a null matrix. 

    Where,

    a=number of rows

    b=numbers of columns

    ones(a,b)

    Creates the singular matrix having the rows a and columns b. 

    diag(A)

    Used to get only diagonals of the matrix provided by you as A.

    sort(A)

    Sort the elements of the matrix A in the ascending order column-wise.

    A’

    It takes the hermitian of a complex matrix A.


    Follow the procedure given below to perform the tasks.

    • Start your MATLAB software. 

    • Go to the command window.

    • Start typing the codes given below and get your desired matrix.

    A=[ 2 7 4; 5 11 5; 3 8 23]

    • Notice that we have a square matrix now. It will help us in different operations. So let’s start using different operations. 

    • Write your first command.

    IdentityMatrix=eye(3,3)

    • It will create an identity matrix with the name IdentityMatrix with three rows and columns.

    • Similarly, write the command given below:

     UpperTriangularMatrix=triu(A)

    • It's time to create the lower triangular matrix. So write the command.

     LowerTriangularMatrix=tril(A)

    • For the null matrix, we are going to use:

    NullMatrix=null(2,5)

    • For the singular matrix, we are using the following command:

    SingularMatrix=ones(3,4)

    • If you wish to have a diagonal matrix of A, write the command:

    DiagonalOfMatrix=diag(A)

    • To sort your matrix A, we are using the command given below:

    SortMatrix=sort(A)

    • If you want to find the hermitian of the matrix, first you have to introduce the complex matrix in MATLAB. So we are writing the following matrix:

    B = [1+j; 1-j; 2-j; 1+2j]    

    • Now, by simply applying the command, we can get the hermitian of this matrix.

    HermitianMatrix=B’

    Thus, today’s lecture was full of different types of matrices, and many of them were new to us. We began with the definition of the matrix, then we saw different types of it where the data or the elements of the matrix were important. Many of them have conditions where the order and location of the elements are important. The concept of transport in the matrix was new to us, and by using it, we explored different types. In the end, with the help of different commands in MATLAB and with the help of practice, we sharpened our concepts. There are different and interesting types of matrices, and we are going to explore all of them in our upcoming lectures.

    The Reynolds Transport Theorem

    Before starting this important topic there are some of the important terminologies related to the theorem that are frequently used throughout. So let us have a look at them.

    System

    Some important key points related to the system are as follows:

    • In thermodynamics, a system is a quantity of matter of fixed quantity. 

    • The system is mostly closed. system. There is a change in the size and shape of the system but due to the closed system, no mass can cross the boundary.

    • One of the important points is that the mass of the system remains constant.

    Control Volume

    Some important key points related to the control volume are as follows:

    • The control volume is also known as the open system and it is defined as the region that is specified for a case study. 

    • In the case of a control, volume mass can cross and move in and out of the boundary and which is called the control surface.

    • One of the important key points related to the control volume is that the mass of the control volume decreases during the process but, the volume remains constant.

    Reynold’s Transport Theorem

    The important key points related to Reynold’s Transport Theorem are as follows:

    • In fluid mechanics, control volumes are easy to handle and many of the laws and theorem are based on it. 

    • So Reynold’s Transport theorem is actually a relationship between the rate of change of extensive properties of the system and control volumes.

    • A system is considered arbitrary when Reynold’s Theorem is being considered. But here the derivation is also being carried away. 

    • Reynold’s Transport Theorem provides a relationship between the system and control volume.

    Derivation of Reynold’s Transport Theorem

    Let us start the theorem with a background of it:

    • First of all, we will consider the flow that is moving from left to right and that flow is passing through an expanding field.

    • As the fluid flow the upper and the lower bounds of the fluid flow are considered to be streamlines of flow. Between any two streamlines, it is assumed automatically that the flow will be uniform and so in this situation, it is also considered.

    • So there is a diagram that is mentioned below that shows the moving system and control volume (shaded region) of the flow field is considered at the times t and ∆t. the streamlines are also shown.

    • Here one interesting fact is that the system and the control volume are the same as the system seems to be coinciding with the control volume.

    • With reference to the diagram, in part (1) the system moves with uniform speed V1 and so in part (2) it moves with speed V2 uniformly.

    • If you look at the diagram, then there is a central region called the hatched region.

    • The region that is uncovered by the system during the motion is mentioned as section I and this is part of the control volume. but the new region that is covered by the system is said to be section II and this is not part of the control volume.

    • Now let us start the derivation. For derivation let us suppose B as extensive property and that may be mass, energy or momentum.

    • Moreover, let us suppose

    b= B/m

    • Now this b=B/m is the intensive property (we are supposing it). 

    • So the extensive property is additive, they can be added easily.

    • so the extensive property at times t and ∆t are presented as follows:

    Bsys,t=BCV,t

    Bsys,t+∆t=BCV,t+∆t - BI,t+∆t+BII,t+∆t


    • Now we will get to the final result by taking two steps. The first step will be subtracting equation 1 with equation 2 and then taking the limit ∆t→ 0. So the final result will be:


    dBsysdt=dBCVdt-Bin+Bout


    • The value Bin and Bout is as follows:

    Bin= b11V1A1

    Bout= b22V2A2

    • Here A1 and A2 are the cross-sectional areas.


    • And the values of BI, t+∆t and BII, t+∆t is as follows:

    BI, t+∆t = b11V1∆tA1

    BII, t+∆t=b22V2∆tA2


    • Now we are on the second last step and it is as follows:

    Bin=BI=b11V1A1( after taking limit)


    Bout=BII=b22V2A2 (after taking the limit)


    • The important point here is that property is the extensive property and the time rate change of the system is equal to the time rate of change of B of control volume along with the net flux B of control volume by mass.

    • Now the final result will be:

    Bnet=Bout-Bin=∫CS ρbV.n dA  (inflow is negative)


    • So below mentioned is the diagram that shows the whole working of the derivation:

    • In the case of the control volume, the equation will be as follows

    BCV=∫CV ρb dV

    • Here the following equation presents the time rate of change of property B content of the control volume:

    dBCVdt= d/dt∫CV ρb dV

    • so the system to control volume in the case of the fixed control system will be as follows:

    dBCVdt= ddt∫CV ρb dV +∫CS ρbV.n dA  

    So that is the explanation related to Reynold’s Transport Theorem. 

    Conclusion:

    I hope you have learned a lot through this article. Thank you for reading.

    Fundamentals of Fluid Flow Visualization

    Flow visualization widely uses Computational Fluid Dynamics (CFD) and physical experiments. So following are the types of patterns that can be visualized computationally and experimentally. So without wasting any time, let us start.

    Streamlines and Streamtubes

    There are two patterns. I will first explain the streamlines. So the definition of streamlines is as follows:

    A streamline is a curve that is tangent everywhere to the instantaneous local velocity vector.

    You might not understand the definition by reading it, so just for your ease, let me explain to you in few key points:

    • A streamline defines fluid’s motion throughout the flow field.

    • A streamline acts as an indicator of the instantaneous direction of motion of the fluid. To explain this situation, let me exemplify it with an example.

    • For instance, when we throw water on a solid surface, we observe the fluid flow pattern on the wall. That pattern is a streamlined pan in which the water is separated, moved in recirculating motion, or coming off the wall.

    • There is an equation of streamline; let me explain the background of the equation to you. Before that, have a look at the diagram.

    • As you can see, there is an infinitesimal arc along the streamline. Here the infinitesimal arc length is as follows:

    dr=dxi+dyj +dzk

    • Here is a condition that dr should be parallel to the local velocity, whose equation is as follows:

    V=ui+vj +wk

    • By utilising the geometric rules, infinitesimal arc dr is proportional to the local velocity, and the equation of streamline will be like this:

    drV=dxu=dyv=dzw

    • Here, dr is the magnitude of infinitesimal arc length, and V is the magnitude of velocity.

    • To obtain the equation in an (x, y) plane, we will integrate equation 1 and get the equation of streamline in an (x, y) plane. The equation is as follows:

    (dydx)along astreamline=vu

    Now I will give a brief explanation about the Streamtubes. So the definition of Streamtubes is as follows:

    A Streamtubes is a bundle of streamlines similar to the communication cable with optic fibre cables.

    You might not understand the definition by reading it, so just for your ease, let me explain to you in few key points:

    • As I have discussed earlier, streamlines are parallel to the local velocity, so according to the theoretical information, the fluid cannot cross the streamlines.

    • A simple diagram elaborates on tee difference between the streamlines and streamtubes.

    Pathlines

    The definition of Pathlines is as follows:

    A Pathline is an actual path travelled by an individual particle (obviously a fluid particle) at some time period.

    The following are some essential key points related to the pathlines:

    •  You might have noticed one thing while reading the definition of pathline and Lagrangian are much similar. Both follow a path of an individual particle when the fluid flows.

    • There is a technique named Particle Image Velocimetry (PIV) that is used to measure the velocity field in one flow of a specific plane.

    • Let me explain to you the PIV technique briefly. So what happens in PIV is that those small particles are released in fluid, as shown in the diagram.

    • Then, the flow is observed by a two-flash light to make two spots on a film of every small particle moving. The magnitude and direction of the velocity of each particle location are fixed because the particle size is small. In today’s modern era of science and technology, many modern computers and digital photography have enabled this feature.

    • In order to trace the location of particles by the following equation:

    x=xstart+tstarttV dt

    • So, the diagram mentioned earlier shows the pathline following the actual path of fluid particles.

    • There is a condition that if the velocity field is steady, the fluid particles are bound to follow the streamlines.

    Streaklines

    The definition of a streakline is as follows:

    A streakline is the locus of fluid particles passed sequentially through the flow’s specific (prescribed) point.

    The following are some important key points related to the streaklines:

    • The streaklines are one of the most common flow patterns produced through physical experiments. To explain this point more clearly, let me explain to you through an example. If we insert a tube (specifically in small size) in the flow and then add a continuous stream of tracer fluid, the pattern produced due to the addition will be streaklines. The flowing diagram shows the streaklines produced when the constant stream of tracer fluid (colored fluid) is added to the flow. The fact about the diagram is that the streaklines are similar to the pathline and streamlines.

    • Here is an interesting point to be noted: if the flow is steady, then the pathlines, streamline, and streaklines are all identical.

    • So you might be confused by the statement that pathlines, streamlines, and streaklines are similar in steady flow. But in the case of unsteady flow, the scenario is entirely different. 

    • There is a difference, i.e., streamlines give an instantons flow pattern (by definition) but in the case of streaklines is an instantons snapshot of time-integrated flow patterns. And the pathlines are the time-exposed flow path of an individual particle at some time.

    • The equation to find the integrated tracer particle is as follows:

    x=xinjection+tinjecttpresentV dt

    Timelines

    The definition of timelines is as follows:

    A timeline is a set of adjacent fluid particles that were marked at the same time.

    The following are some key points related to the timeline:

    • The fluid flows in which there is uniformity and a steady flow, then timelines are observed. 

    • Practically timelines can be generated in any water channel with the help of hydrogen bubble wire.

    Plots of Fluid Flow Data

    As we all know, flow properties vary from time to time, and in space, it is necessary to plot flow data in various ways. In this article, I am going to explain three kinds of plots that are profile plots, vector plots, and contour plots, respectively.

    So without wasting any time, let’s start explaining the plots.

    Profile Plots

    The definition of a profile plot is as follows:

    A profile plot indicates how the scalar property varies along some desired direction in the flow field.

    The following are some essential key points related to profile plots:

    • It is one of the simplest plots much similar to the XY-plots. 

    • As the definition describe that the profile plots are created for the scalar quantities, but in fluid mechanics, velocity profile plots are used. As velocity is a vector quantity. So, to create a profile plot, we either use magnitude or velocity.

    Vector Plots

    The definition of the vector plots is as follows:

    A vector plot is an array of arrows reflecting the magnitude along with the direction of vector quantity at an instant of time.

    The following are some essential points related to the vector plots:

    • Streamlines are used to present the direction of the instantaneous velocity; here, they do not show the velocity magnitude.

    • A flow pattern is a vector plot for experimental and computational fluid flow. They have an array of arrows that indicate both magnitude and direction of a vector quantity.


    Contour Plots

    The following definition of a contour plot is as follows:

    A contour plot shows curves of constant values of scalar property (or magnitude of a vector property) at an instant in time.

    The following are some essential key points related to the contour plots:

    • The contour plot may have curves indicating various properties called Contour Line Plot.

    • Some of the contours are filled with color of grey are called Filled Contour Plot.

    Kinematic Descriptions

    In fluid mechanics, the elements have four fundamental types of motion or deformation in two dimensional as follows. It is interesting to know the fact that all four of these motions can act at the same time. Yes, you heard it right. Isn’t it amazing? In fluid dynamics, the motion and deformation of liquid elements at different times are described. So the deformation rates are expressed in terms of velocity and derivatives of velocity.

    • Translation

    • Rotation

    • Linear Strain (Extensional Strain)

    • Shear Strain

    So let us start explaining one by one. 

    Translation 

    The translator and rotatory motion are one of the most common motions that are observed in our daily life. For the three dimensions, a vector is used to define the translator rate. In Cartesian coordinates the rate of translation is as follows:

    V=ui+vj+wk

    Rotation

    The rate of rotation or the angular velocity is defined to be the average rotation rate of two perpendicular lines that intersects at some point. 

    Example:

    In order to exemplify this whole situation, let us explain through some examples.

    • Let us take an initially square fluid element and consider its bottttttttt.

    • Technically, the left and the bottom edge of the element intersect at some point. Thus we can say that they are perpendicular to each other. 

    • Now, these two lines tend to rotate in a counterclockwise direction (which is said to be the positive direction). 

    • Toto, show a clearer picture to you let me show you a diagram. So the below-mentioned diagram explains the rotational effect.

    • One of the main points to observe is that the angle between the two lines remains the same, which is 90 degrees. 

    • So the line rotates at the same rate of rotation.

    • Here there is also one of the most essential points about the rate of rotation is that when the case is two dimensional then the fluid elements move in translator motion and then rotate. But while rotating, they deform easily.

    • In order to calculate the rate of rotation, the whole thing is calculated by the scenarios mentioned above, i.e. two lines are taken named a and b respectively. These two lines intersect at a specific point called P ( as mentioned above that this procedure is in two dimensions. Which Means that they are in the XY plane).

    • These lines are being followed and rotated in an infinitesimal increment of time, and that is:

    dt=t2-t1

    • Line a  rotates at some angle aand line b also rotates at a specific angle b. The average rotation angle will be:

    a+b2

    • So the final equation will be as follows:

    ω=ddt(a+b2)


    ω=12(∂v∂x-∂u∂y)

     Linear Strain Rate

    The definition of linear strain rate is as follows:

    Linear strain rate is defined as the rate of increase in length per unit length.

    Some of the important key points related to the linear strain rate are as follows:

    • The linear strain rate depends upon the direction of the line segment and this line segment measures the linear strain.

    • But here important point should be kept in mind i.e. that the linear strain rate cannot be defined as vector or scalar quantity.

    • The linear strain rate can be defined in an arbitrary direction. 

    • The linear strain rate can be defined in Cartesian coordinates by the formula as follows:

    xx=∂u∂x   yy=∂v∂y   zz=∂w∂z

    Volumetric Strain Rate

    The definition of the volumetric strain rate is as follows:

    The rate of increase in the volume of fluid element per unit volume is called the volumetric strain rate.

    Some of the important critical points related to the volumetric strain rate are as follows:

    • In an incompressible flow, the volumetric strain rate is zero.

    • With the increase in volume, the kinematic property is always positive.

    • The other definition word for the volumetric strain rate is called Rate of Volumetric Dilatation. 

    • The rate of volumetric dilatation is remembered by an example. Let us take an example of the iris of expands enlarging when there is less light.

    • The formula of volumetric strain rate in Cartesian coordinates is as follows:

    1VDVDt=1VdVdt=xx+yy+zz=∂u∂x+∂v∂y+∂w∂z

    Shear Strain Rate 

    The definition of the shear strain rate is as follows:

    A shear strain rate is defined at the point as half of the rate of decrease of the angle between two initially perpendicular lines that intersects at some points.

    Some of the important key points related to the shear strain rate are as follows:

    • In order to explain the definition, let us explain through some examples. Let us see a diagram first that is mentioned below:

    • In this diagram, the angle is at first 90 in the lower left corner and upper right corner of the element of fluid the angle decreases so that is a positive shear strain. But the angles at the upper-left and lower-right square fluid element increase so that is negative shear strain.

    • In the Cartesian coordinates system, the shear strain rate will be:

    xy=12∂u∂x+∂v∂x  zx=12∂w∂x+∂u∂z  yz=12∂v∂z+∂w∂y

    Conclusion:

    I hope you have learned a lot through this article. Thank you for reading.

    What is Fluid Kinematics?

    Hello friend. In this article, I will cover essential points related to fluid kinematics, i.e., what fluid kinematics is and how the motion of the fluids can be explained without describing the forces acting on them. Further, I will explain Lagrangian and Euler about the motion of fluid and a lot more. So buckle up, and let’s start.

    What is Fluid kinematics?

    The definition of fluid kinematics is as follows:

    Fluid kinematics is related to fluid motion without considering the forces responsible for the motion.

    The following are some essential key points related to fluid kinematics:

    • The nature of fluid motion is categorized into two types:

      1. Lagrangian
      2. Euler.
    • I will extensively explain both types in upcoming topics.

    • The acceleration, velocity, flow rate, and nature of fluid flow are considered while working on fluid kinematics.

    Lagrangian and Euler Description 

    First of all, I will explain the Lagrangian. So the definition of Lagrangian is as follows:

    Lagrangian Description of fluid flow deals with individual particles and their nature, and the working trajectory of each particle is calculated separately.

    And the definition of Euler is as follows:

    Euler’s Description of fluid flow deals with the concentration of the particles, and the number of particles and diffusion are all calculated.

    The following are some essential key points related to the Lagrangian Description:

    • Lagrangian is all about tracking the path of individual particles. 

    • In this regard, Newton’s Laws are beneficial in detecting the pathways. With the help of their kinetic energy, speed, distance velocity, and acceleration.

    • As we all know, fluid is Continuum in nature. If you are following my fluid mechanic’s articles series, you have forwarded to this word, where I have extensively described the continuum. So it becomes pretty challenging to follow the path of fluids as they deform whenever a direction changes.

    • In the Lagrangian description, the position and velocity of individual particles must be tracked throughout. 

    • To describe through a simple example the balls on the snooker table. In this case, each ball is responsible for its path.

    The following are some essential key points related to the Euler Description:

    • In the case of Euler’s description, the control volume is defined through which the fluid can move in.

    • In this description method, there is no need to track the velocity and position of fluid particles.

    • In this description, space and time are defined within the domain of control volumes.

    • As I have defined in previous articles, pressure is a scalar quantity. So pressure field in case of three-dimensional fluid flow in Cartesian co-ordinates can be defined as follows:

    P = P (x, y, z, t)

    • The velocity field is mentioned as follows:

    V=V(x, y, z, t)

    • The acceleration field is as follows:

    a= a (x, y, z, t)

    • The interesting fact to know is these three field(along with some others but for now only these three fields) variables define the flow field:

    V=(u, v, w)

    V=ux,y,z,ti  +vx,y, z, tj +w(x, y,z,t)k

    Difference between Lagrangian and Euler Description

    I will explain it through a simple example to depict the Lagrangian and Euler description.

    • The example is as simple as one person standing beside the river. So when he goes through the probe, which will move downstream with water, this situation will be classified as Lagrangian. This will be classified as Euler’s description when he anchors the probe in some fixed location in the water.

      Application of Fluid Kinematics

      The applications of fluid Kinematics are as follows:

      Usage in Vehicle

      • The purpose of dealing with Fluid kinematics is that fluid has excellent properties, and they are used almost in every vehicle. So for lubrication purposes and as driving fuel.

      Electricity Generation

      • Anything that moves has kinetic and potential energy and fluids. They are used in hydroelectric power plants for the generation of electricity.

      Air Conditioner and Refrigeration

      • In refrigerators and air conditioners, refrigerants used are fluids. The primary purpose of refrigerants is to absorb the heat (from the room or, in the case of refrigerators, anything that is kept inside them) and keep them cool, then release the heat into the atmosphere. In the case of air conditioners, heat is absorbed from the room to keep them cool and release that heat into the atmosphere. 

      Renewable Energy

      • Surprisingly fluids can be used as a renewable energy resource. One of the simplest and best examples is the water used in tidal power plants for electricity generation. Moreover, a vegetable oil known as biodiesel is used in many vehicles. Wind and air are also used as renewable energy sources. 

      Thermal Power Plants

      • One of the essential resources of electricity in thermal power plants. In thermal power plants, water (used as fluids) is heated to form steam, which then turns on the turbine. The turbine then turns on the generator, which generates electricity. So the purpose of explaining this whole procedure is to explain the importance of fluid in electricity generation.

      So that are the applications of fluid kinematics in our daily life. Dear friends, I will explain two significant ways to describe motion.

      What is Fluid Statics?

      As I have discussed the pressure now I will explain fluid mechanics. The definition of fluid mechanics is as follows:

      Fluid mechanics deals with the properties and characteristics of fluid at rest.

      Some of the important key points related to the fluid statics are as follows:

      • Fluid statics has many properties just as hydrostatics when the fluid is in a liquid state and acts as aerostatics when it is in a gaseous state.

      • The only stress that is in fluid statics is the normal ones other than that there is no shear stress.

      • The main application of fluid statics is to determine the forces that are acting on the floating or the submerged bodies.

      That is a brief introduction to fluid statics further I will explain the forces that are acting on submerged and floating bodies. So without wasting any time let us start.

      Hydrostatics Forces on submerged plane surfaces

      The structure of the surface and the forces that are acting on the surface is explained as follows:

      • As the name suggests, there is a plane surface on which liquid flows and the surface is resting. 

      • The fluid pressure is equally distributed onto the surface.

      • So the set of parallel forces is formed on the surface as a result of hydrostatics forces. 

      • As one side of the surface is facing the fluid pressure whereas the other side is sometimes exposed to the atmosphere and as the result is zero resultant.

      Working Principle

      The working principle along with all the equations that are acting on the surface are explained as follows:

      • First of all, as I have discussed earlier that one side of the plate is completely exposed to the atmosphere and has atmospheric pressure whereas the other side of the plate is completely submerged in the fluid as shown in the diagram.

      • The horizontal surface intersects the plane surface at some angle so that line is considered to be x-axis.

      • Po is the absolute pressure i.e., the pressure that is above the fluid (liquid) also known to be local atmospheric pressure if the fluid or liquid is exposed to the atmosphere.

      • The equation of absolute pressure is:

      P=P0+ρgh

      P=P0+ρg ysinθ (equation 1)

      • Here h is the vertical distance of a specific point to a surface and y is the distance of a point from the x-axis from the point O as shown in the diagram.

      • Now the next step is to find the resultant hydrostatics force and for that, the equation is as follows:

      FR=∫APdA

      • Here we will substitute the value of P from equation 1 and equation 2 will look like this:

      FR=∫A(P=P0+ρg ysinθ) dA

      FR=P=P0A+ρg sinθ∫AydA

      • ∫AydA is the first moment of the area as it is in the y-coordinate and the value is as follows:

      yc=1A∫AydA

      By substituting the value, we get the final result:

      FR=P0A+ρgyc sinθA

      FR=P0+ρghcA

      FR=PcA

      FR=PavgA

      The final result will be stated theoretically:

      The final resultant force is equal to the pressure at the centroid surface and the area.

      Hydrostatic Forces on Submerged curved surfaces:

      The structure of the surface and the forces that are acting on the surface is explained as follows:

      • As the name shows that the curved surface is submerged in liquid and the hydrostatic forces are determined.

      • In this part we have applied the integration of pressure forces that fluctuates when the direction of the surfaces changes.

      • The final force (resultant) is equal and opposite to the force that is acting on the curved surface.

      Working Principle

      The working principle along with all the equations that are acting on the surface are explained as follows:

      • Here the weight of the enclosed liquid is as follows:

      W=ρgυ

      • Here V is the volume of fluid and that is in a downward direction as shown in the figure.

      • the vertical and horizontal forces will be:

      • the horizontal force component on a curved surface:

      FH=FX

      • the vertical force component on the curved surface

      FV=Fy+W

      The final result will be:

      • the horizontal and the vertical component of the hydrostatic force of a curved surface are both equal in case of magnitude and line of action.

      • The horizontal and vertical component is an equal hydrostatic forces acting on horizontal projection along with the weight of the fluid.

      Conclusion:

      I hope you enjoyed reading the article and have an extensive overview of the pressure and fluid statics. Thanks for reading.

      What is Pressure in Fluid Mechanics?

      The article will cover essential aspects of fluid statics and pressure forces applied to the fluid. The article will start with the absolute pressure gauge and the variation of pressure with depth in different gravitational field manometers and barometers, respectively. Then I will explain the forces that deal with fluids, such as hydrostatic force, buoyant force, etc. So, dear friends, without wasting any time, let’s start.

      Pressure

      The definition of pressure according to fluid mechanics is as follows:

      Pressure is the normal force applied by a fluid per unit area.

      Unit of Pressure

      • The units of pressure Pascal is too small to deal with in practical cases. For instance,

      • Kilopascal: 1kPa=103Pa

      • Mega Pascal: 1MPa=106Pa

      • The three common pressure units used are standard atmosphere bar and kilogram-force per square centimeter. 

      • 1bar=105Pa=0.1MPa=100kPa

      • 1atm=101,325Pa=101.325kPa=101325 bars

      • 1 kgf/cm2=9.807 N/ cm2=9.807×m2=9.807×104Pa

      =0.9807bar

      =0.9679 atm

      • The unit of pressure in the English system is pound-force per square inch (psi or lbf/in2)

      Absolute and Gage Pressure

      • The actual pressure at a given position is called absolute pressure. The pressure is measured relative to an absolute vacuum or absolute zero pressure.

      • The difference between the absolute and local atmospheric pressure is called gage pressure.

      • The pressure below the atmospheric pressure is called vacuum pressure.

      Formula of Gage, Absolute, and Vacuum Pressure

      All three of these pressures are interrelated with each. Other, and this is visible with the formulae as mentioned below:

      Pvac=Patm-Pabs

      Pgage=Patm-Pabs

      Diagram Related to Pressure

      The following diagram shows the relation of the pressures from the below-mentioned diagram:

      Pressure Variation according to Depth

      We all know there is no fluid pressure change at rest and in the horizontal position. This phenomenon can further be elaborate on a few points:

      • Assuming a thin layer horizontally of fluid followed by force balance at any point. The pressure increases as the depth increase as there are more layers of fluids, and these layers are being balanced by the pressure increasing.

      • An example can explain the whole phenomenon. 

      • Toto show how pressure changes with the change in depth. We assumed a rectangular fluid element, as shown in the diagram.

      • The length, width, and heights are mentioned on the diagram.

      • The pressure of the fluid is constant, whereas force balance in z direction vertically will be:

      ∑Fz=maz=0

      P2△x-P1△x-ρg△x△z=0

      • Now, we will divide the above equation with delta x △xand will get the below-mentioned equation:

      △P=P2-P1=ρg△z=sz

      • Here, one of the most important things is that the s is the specific weight of fluid.

      • The final statement to be noted is that there is an increase in pressure linearly with an increase in depth.

      • It is essential to note that the pressure force applied by the fluid is always normal at some points to the surface.

      Pressure at Point

      As pressure is a scalar quantity, sometimes it seems to be vector one. The pressure will be the same in any fluid at any point.  To prove this point, let us discuss a scenario.

      • Let us consider fluid element (a wedge shape/ right-angled triangle) at equilibrium.

      • The mean pressures at three surfaces are mentioned as P1, P2, and P3, respectively. 

      • The diagram shows the points clearly.

      • Here, the value along the pressure is the surface area.

      • According to Newton’s second law, the force in the direction of x and z is as follows as △y=1:

      ∑Fx=max=0             P1△z-P3Isinθ = 0     (1)

      ∑Fz=maz=0             P2△x-P3Icosθ-12ρg△x△z = 0         (2)

      • Here, the value of w is the weight of the fluid, and the value is as follows:

      W=mg

      W=ρg△x△z/2

      • The value of △x and △z are as follows:

      x = I cos θ

      △z=I sinθ

      • So, by substituting all the values in equations 1 and 2 and then diving equation 1 with △z and equation 2 with △x then, the final result will be:

      P1-P3= 0     (3)

      P2-P3-12ρg△z=0       (4)

      • Here, in equation 3 △, z drops to 0, and the final result will be:

      P1=P2=P3=P

      Pressure measuring devices

      Numerous devices are used to measure fluid pressure and work on different principles. These devices are explained below briefly.

      Manometer

      The definition of a manometer is explained as follows:

      A manometer is a device in which fluid columns measure pressure differences.

      The important key points about the manometer are explained below:

      • the manometer is used to measure small or moderate pressure differences.

      • If pressure is at a specific position inside any gas tank, then the pressure anywhere in the tank will be the same. But here important point to be noted is that it is for gases only as their gravitational effect is negligible.

      • The basic diagram of the manometer is shown as follows:

      • As we can see, two points in a basic barometer and a height h. So the pressure at point 1 will be the same throughout the tank so  that P1=P2 and the pressure will be by the equation:

      P2=Patm+ρgh

      • Here, h is the height of column fluid, which is in static equilibrium, and as we can see, the column is exposed to the atmosphere.

      • is the density of the fluid, and Patm is the atmospheric pressure. 

      • Here, one important point to be noted is that the height of the tube is independent of the area of the tube.

      Barometer

      The definition of the barometer is as follows:

      A barometer is a device that is used for the measurement of atmospheric pressure.

      The following are some important key points related to the barometer:

      • The structure of the barometer is the inversion of a tube filled with mercury in a container, which is exposed to the atmosphere.

      • The diagram shows the structure of the barometer;

      • Toto calculates the formula of the atmospheric pressure; we will follow the above diagram. As you can see, there is a point B, so this B equals atmospheric pressure. Point C inside the tube is assumed to have zero pressure as there are only mercury vapors above point C, and pressure above that point is low compared to the atmospheric pressure, so for ease, the pressure is taken to be zero. The formula of pressure is as follows:

      Patm=ρgh

      Other Pressure Measuring Devices

      There are many other pressure-measuring devices that are in use in our daily life, and they are briefly explained as follows:

      • Bourdon Tube is a pressure measuring device consisting of a hook like a hollow metal tube that is connected to a dial indicator. There is a fluid inside the tube that is pressurized. When this fluid is being pressurized up to a point then the needle that is on the dial is deflected. The needle is read to zero when the tube is exposed to the atmosphere.

      • There are special types of pressure detectors that can convert the pressure effect into electrical energy and they are called pressure transducers.

      When the mechanical pressure is created when the electric potential is applied to a crystalline form. Such kinds of devices are called Piezoelectric transducers.

      Properties of Fluid

      In the introduction, I will extensively explain the property r and how to impact them are so. Let us start. Then I explain properties that are related to fluid flow.

      First of all, I will start with the word Property. The definition of property is as follows:

      Property

      The word property is defined as any characteristic of the system. There are two main types of the property named intensive and extensive.

      Example

      The examples of property are as follows

      • Temperature -T

      • Pressure - P

      • Mass – m

      Types of Properties 

      Following is a brief explanation of the types of properties.

      Intensive Property

      The intensive properties are the ones that are independent of mass, temperature, density, and pressure. Therefore, they are presented in lowercase letters. But here stands an exceptional case, i.e., the temperature and pressure are only denoted with uppercase letters.

      Example

      The examples of intensive property are as follows:

      • Velocity - v

      • Specific Internal Energy - u

      • Temperature - T

      • Charge Density - ne or ρ

      • Molality - m or b

      Extensive Property

      The extensive property is the ones that depend on the size or extent of the system. They are presented by the uppercase letter, but here is an exceptional case for the mass presented by a lowercase letter. 

      Example

      Extensive properties are usually derived, so the following are some examples.

      • Total Energy

      e= E/m

      • Specific Volume 

      v=V/m

      Specific Property 

      The specific property is the ones that depend on that are derived from either extensive or intensive ones. 

      Example

      One of the simple examples of a specific property is the density of water; as we know, it is an intensive property. So the extensive property (derived ones) is the mass of water volume divided by the volume. Here both the mass of water and volume are extensive properties.

      Continuum

      The term continuum is related to matter in this way: the matter is made of atoms, and their distance and compactness vary from state to state. As in solids, atoms are closely packed, whereas, in liquids, there is some distance. However, in gases, the atoms are spaced widely. So in the continuum, the matter is defined as continuous and homogenous with no holes. 

      The primary purpose of using a continuum is to treat properties as a point function, and there are no jump discontinuities as the properties vary in space continually. This only applies when the system size is large compared to the space in molecules. It is practically applicable in almost every case except exceptional cases.

      Properties related to fluid flow

      At the start of the discussion, I discussed the properties such as intensive and extensive observed during the fluid flow. Now some more properties play a distinct role in the fluid flow and their importance. So without wasting any time, let’s start.

      1. Density

      The density is defined as;

      Density is mass per unit volume.

      Formula:

      ρ=m

      Specific Density

      It is defined as 

      The specific density is the reciprocal of density, i.e., volume per unit mass. 

      Formula:

      υ=Vm

      Factors affecting Density

      There are numerous factors on which the density depends. The most important of all is the temperature and the pressure, which change the nature of the substance. 

      Gases

      In gases, an increase in pressure will decrease the temperature and vice versa.

      Solids and Liquids

      Compared to gases, solids and liquids are incompressible, so an increase or decrease in pressure is negligible. 

      Example 

      In solids and liquids, the temperature is an essential factor that changes the density compared to the pressure. For instance, at the pressure of 1atm, the density of water changes from 998kg/m3 to 975kg/m3. So the difference is about 2.3 percent which is negligible in many cases.

      Relative Density or Specific Gravity

      The definition is as follows:

      The density of the substance is relative to the density of the well-known substance.

      Formula:

      SG=H2O

      SI units of Specific Gravity

      As relative gravity is a dimensionless quantity, so the SI unit of it is as same as the density one, i.e., kg/L or g/cm3 (0.001 times density in kg/m3)

      Specific Gravity of Substances

      The following is the list of some substances with specific gravity at 0˚C.

      Substance


      SG


      Blood

      1.05

      Air (at 1 atm)

      0.0013

      Wood

      0.3-0.9

      Gasoline

      0.7

      Gold 

      19.2

      Seawater

      1.025

      Ethyl Alcohol

      0.79


      Specific Weight

      The definition of specific weight is as follows:

      The weight of a unit volume of a substance is known as specific weight.

      Formula

      s=ρg

      Vapor Pressure and Cavitation


      Vapor Pressure

      The definition of vapor pressure is as follows:

      Vapor pressure is the pressure applied by the vapor of a pure substance at the state of equilibrium with its liquid at a given temperature.

      Some important key points related to the vapor pressure are as follows:

      • It is presented by Pv.

      • Vapor pressure is as same as saturation pressure Pv.=Psat.

      • Sometimes, vapor and partial pressure are considered one thing, but they have two different definitions and applications. 

      • Increase in temperature increases the vapor pressure.

      The following table shows water saturation or vapor pressure at different temperatures.

      Temperature

      ˚C

      Saturation or Vapor Pressure

      kPa

      -10

      0.260

      -5

      0.403

      0

      0.611

      5

      0.872

      10

      1.23

      15

      1.71

      20

      2.34

      Some important terms are related to vapor pressure, and they are named saturation temperature and saturation pressure, respectively. 

      • Saturation pressure is the pressure at which changes in the state of a pure substance occur at a given temperature. It is represented by Psat.

      • Saturation temperature is the temperature at which changes in the state of a pure substance occur at a given pressure. It is represented by Tsat.

      Partial Pressure

      The definition of partial pressure is as follows:

      Partial pressure is the pressure of gas or vapors with a combination mixture of gases.

      Some important key points related to partial pressure:

      • Partial pressure of water vapors has some atmospheric pressure, and the value is 0.3. 

      • The absence of liquid equalized or less than the partial pressure of vapors to the vapor pressure. 

      • At the state of equilibrium, the presence of partial and vapor pressure in the system then the system is saturated.

      • In open lakes, the evaporation rate is managed by the vapor and partial pressure differences.

      Cavitation

      As we know, vapor bubbles in the liquid collapse when they are moved or swept from low regions. The result is the production of high-pressure waves that creates destruction. The reason for explaining this is that the phenomenon is related to cavitation, and the vapor bubbles formed are called cavitation bubbles. The phenomenon mentioned above is called cavitation as it is the leading cause of destruction and causes performance to drop off.

      Some important key points related to cavitation:

      • In designing hydraulics pumps and turbines, this phenomenon (cavitation) is prioritized

      • In flow systems, cavitation is not considered as they result in poor performance, turbulence and noise.

      • For checking whether cavitation is present in the flow system or not, cavitation is observed by a unique tumbling sound.

      Energy and Specific Heat

      We are well known for the term that energy cannot be created nor destroyed but can be transformed from one form to another. There is various form of energy that we observe in our daily life. 

      So I will recall some of the vital energy that is used during the fluid flow:

      Kinetic Energy

      The basic concept of kinetic energy is that anybody or system (comprised of energy) is in motion relative to the reference frame and is said to have kinetic energy. 

      Formula:

      K.E = 12v2

      • Here, v stands for the velocity of the system or body relative to the reference frame.

      Potential Energy

      The potential energy is the energy possessed by the body or system due to elevation in the gravitational field.

      Formula:

      P.E =gz

      • Here, g represents the gravitational acceleration, whereas z represents the elevation of the system or body concerning the reference position. 

      Thermal Energy

      Thermal energy is the energy that is related to the temperature. So it is defined as the energy in the system responsible for temperature.

      Formula

      Q=c ∆T

      • Here ∆T represents the temperature difference, whereas c represents the specific heat.

      After discussing all the energy, one important term related to fluid flow is the Enthalpy. So let us discuss enthalpy.

      Enthalpy

      The enthalpy is the combination of internal energy and the product of volume and pressure. The enthalpy value is calculated with the help of pressure, temperature, and volume, respectively. The energy conservation law says that internal energy changes equal heat transfer. The enthalpy change is assumed to equal the heat transfer if the work changes the volume at constant pressure.

      Formula:

      H=E +PV

      • Here, H is the enthalpy, E stands for internal energy, P stands for pressure, and V stands for the system volume.

      Total Energy

      The sum of all the energy of flowing fluid is called total energy. 

      Formula

      eflowing=K.E+P.E+Enthalpy

      eflowing=h+V22+gz

      Coefficient of Compressibility

      There is an expansion in fluids when they are heated, and they contract when they are cooled. This means that temperature and pressure are two essential parameters responsible for contraction and expansion. The temperature and pressure also change the volume or density of the fluids. But volume or density varies differently from fluid to fluid. So, two properties are related to the volume or density changes to the change in pressure. And they are named Bulk Modulus of Elasticity and Coefficient of volume expansion.

      So let’s explain these two properties without wasting any time.

      Bulk Modulus of Elasticity

      There is a similarity in solids’ and liquids' expansion and contraction principles. So, the definition of the bulk modulus is as follows:

      Bulk Modulus of Elasticity is a property that is the ratio of change in pressure relative to the volume.

      Formula:

      κ = -v(Pv)T= ρ(P∂ρ)T     (1)

      The formula can also be presented concerning the finite changes, as shown below.

      κ≅ -∆P∆vv≅-∆P∆pp

      • Here ∆vv and ∆pp are dimensionless. 

      • The unit of κ is psi or Pa.

      • Here, the temperature is kept constant, so the bulk modulus of elasticity presents the change in pressure to the change in volume and density of the fluid. 

      • The above equation proves that the incompressible substance coefficient of compressibility (Bulk modulus of Elasticity) is infinite.

      • Increase in pressure decreases the volume.

      • The negative sign indicates Pv is a negative quantity, whereas the bulk modulus value is positive.

      An important key point related to Bulk Modulus of Elasticity:

      • Bulk modulus of elasticity is also known as the coefficient of compressibility or bulk modulus of compressibility.

      • If the value of bulk modulus is significant, then firstly, the fluid is incompressible, and then a large amount of pressure is required for a small amount of fractional change in the volume.

      • When the equation is being differentiated, then

      • From the equation, it is evident an increase in one quantity decreases the other and vice versa. From equation 1, we will differentiate the ρ=1/v, and we will get dρ=-dv/v2. So after cancellation, the final result will be:

      dρ=-dvv

      • The inverse of the coefficient of compressibility is called isothermal compressibility. 

      • The formula is as follows:

      α=1=-1v(∂v∂P)T=1(∂ρ∂P)T

      Coefficient of Volume Expansion

      It is observed that there is a drastic change in liquid density when it is increased or decreased. A property named coefficient of volume expansion is responsible for the fluid density difference at constant pressure and variable temperature.

      Formula:

      𝛃=-1v(∂v∂T)P=-1(∂ρ∂T)P

      • The coefficient of volume expansion is represented by beta.

      • At the infinite changes, the formula is shown below:

      -∆vv∆T=-∆pp∆T

      • Here, the pressure is kept constant.

      Important key points related to the coefficient of volume expansion:

      • Increase in temperature increases the value of as they have a direct relationship.

      • ∆T represents the temperature difference in the equation. 

      Viscosity

      If we define viscosity, the most reasonable and appropriate term will be resistance. When the fluid flows, there exist layers of viscosity at that point. There are intermolecular forces in fluid when the fluid is more viscous. So the definition of viscosity will be:

      Viscosity is a property that represents the internal resistance of a fluid to motion.

      Example:

      One of the best examples is the pouring of honey. As you observe, honey is dense and very has strong internal resistance.

      Formula:

      η=2ga2(∆ρ)9v

      • We assume a sphere that is dropped onto the fluid, and then the fluid’s viscosity is measured.

      • Here ∆ρ is the density difference between the fluid and surface

      •  a is the radius of the sphere 

      •  G is the acceleration due to gravity

      Important key points related to viscosity:

      • When one layer moves adjacently to the other, some friction exists, which we named viscosity. The layers are moving at some distance and are named dy. The velocities of the fluids are u and u+du, respectively. 

      • The graphical presentation of the layer velocity versus the distance is shown below.

      • The graph will explain the trends of velocity and distance. As mentioned, two layers are moving adjacently to each other, so the layer that is on top imposes shear stress on the lower layer, and the lower layer, in response, causes shear stress on the upper one. 

      Types of Viscosity

      There are two primary types of viscosity, and they are explained briefly as follows.

      Kinematic Viscosity 

      Following are some essential key points related to kinematic viscosity:

      • Kinematic viscosity is the ratio between dynamic viscosity and fluid density.

      • The formula of kinematic viscosity is as follows:

      υ=

      Here υ is the kinematic viscosity η is the absolute or dynamic viscosity, and ρ is the density of the fluid.

      • When the temperature decreases, kinematic viscosity also decreases.

      Dynamic or Absolute Viscosity

      Following are some essential key points related to dynamic or absolute viscosity:

      • Dynamic viscosity is the ratio of shear stress to the shear strain of motion.

      • Dynamics viscosity helps in the interaction of the molecules dealing with mechanical stress.

      Conclusion:

      I hope you enjoyed reading the article and have an extensive overview of the fluid-flowing properties. Thanks for reading.

      Run Xbox Cloud Gaming on Raspberry Pi 4

      Where To Buy?
      No.ComponentsDistributorLink To Buy
      1Raspberry Pi 4AmazonBuy Now

      Introduction

      Greetings, and welcome to the next section of our Raspberry Pi 4 tutorials. In the last section, we discovered how to set up and run our self-host bitwarden on our Raspberry Pi. We learned how to set up admin panels and perform a wide range of actions, such as limiting the creation of new accounts and users for security purposes. However, in this guide, we will discover how to configure a PS3 or PS4 joystick with our raspberry pi and set up and run Xbox cloud gaming on our Pi 4.

      Components

      • Raspberry pi 4

      • SD card

      • Power supply

      • Ethernet cable or wifi

      • Xbox controller

      • Xbox game pass ultimate subscription

      • USB keyboard

      • USB mouse

      • HDMI cable

      Through a service called Xbox Cloud Gaming, users may play a wide variety of games without having to download any software onto their devices. Here, we'll use Microsoft's Xbox Internet Gaming service to transmit these programs to your Pi 4. A membership to Xbox Gaming Pass Ultimate is required to use this feature. Xbox Gaming Pass is required for this streaming service, but the subscription unlocks a wealth of video game apps.

      Incorporating Xbox internet Game streaming on Pi 4 is a breeze with the help of the Chromium internet browser. Remember that there will be some delay in responding to your inputs, but don't let that deter you from playing most games. As a bonus, this guide will show you how to convert your Raspberry Pi running the "light" version of the Xbox One operating system into a dedicated cloud gaming computer for the Xbox One.

      Regarding game streaming services, Xbox internet Gaming isn't the only option for your Pi 4. Games can also be streamed to your Pi 4 using Google's Stadia program. Alternatively, you can use a streaming service like Steam to play your games on the go. To play games via Xbox Cloud, you'll need to be in a region where it's available.

      Get your Raspberry Pi ready for setup.

      You must fulfill a few prerequisites before you can begin using Xbox internet Gaming on your Pi 4. Here, you'll learn how to update your Raspberry Pi and set up the Chrome internet browser we'll need to connect to the cloud game platform. These instructions have been designed with Pi OS Lite compatibility in mind. The "Lite" version of Xbox internet Gaming will require additional effort.

      To move on, we must ensure that our Raspberry Pi is up-to-date with the latest software. The software has to be updated so that we get the most incredible possible performance with the Xbox internet Gaming platform. You can upgrade your Pi's software to the most recent version using the following two instructions.

      sudo apt update

      sudo apt upgrade -y

      After the update is finished, we can add any other software to our pi four that is required for Xbox internet Gaming. We'll primarily be using the Chrome internet browser, which can be obtained by running the instruction below.

      sudo apt install chromium-browser xserver-xorg x11-xserver-utils xinit openbox bluealsa unclutter

      We'll install just the bare minimum of software to get Chromium up and running on pi 4 OS Lite. Having a controller linked to your pi 4 is the next step. Most Xbox Cloud Gaming titles necessitate the usage of a controller. Despite the inclusion of third-party controller functionality, the Xbox joystick remains the superior option. And if you want to know which controllers work with their internet gaming platform, you can find that information in their official docs. Another option is to use a PlayStation joystick with Pi 4, and we will show you how to do just that.

      How to Configure PlayStation joysticks on a pi 4

      You may have discovered that using a PlayStation joystick with a Raspberry Pi is not a walk in the park. This tutorial is written in the hopes of making the whole thing easier.

      Here at the pi 4 Wiki, we have a comprehensive tutorial for connecting and setting up Ps controllers of all generations. We walk you through installing the six-pair program for PS3 controllers and configuring your joystick to work with your pi four and any Bluetooth-enabled device. The procedure of connecting a PlayStation 4 joystick to a Raspberry Pi via Bluetooth is detailed here, and alternate methods are provided in case your joystick is incompatible with the default implementation of Bluetooth. The pi 4 is compatible with various game controllers, including Xbox joysticks.

      Configure a PlayStation 3 Controller for Use with a pi 4

      It's not easy to get a Ps3 controller working with a pi 4. If you want to use it wirelessly, we'll walk you through the setup process from start to finish. The wired PS3 joystick should function as simply a plug-and-play accessory. When using a PlayStation 3 controller, all of its functions must work correctly, and Sixad does just that. If you want to use a USB micro cable to connect the joystick to the pi 4, you should get one before you start this part of the pi 4 PlayStation tutorial. The configuration of the PS3 joystick for communicating with Wireless controllers is necessary for this.

      Setup of the PlayStation 3 Joystick with the pi 4

      The first step is to install a library, which will allow us to compile the six-pair code. The libusb-dev library enables the software to communicate with USB storage devices.

      sudo apt install libusb-dev

      Now that we have the necessary package loaded, we can get the six-pair script and set up a folder to store it.

      mkdir ~/sixpair

      cd ~/sixpair

      wget http://www.pabr.org/sixlinux/sixpair.c

      Now that we have the six pair code on our pi 4, we can build it with the help of the command below. Use this command to initiate a compilation using the GCC compiler.

      GCC -o sixpair sixpair.c -lusb

      Now that Sixpair has been compiled on our pi 4, we can connect our PS3 joystick to the RPi through its USB micro port. After connecting the joystick, use the following command to start six pair. So that our Wireless device can communicate with the joystick, Six pair will modify its settings.

      sudo ~/sixpair/sixpair

      If the six-pair program has successfully re-paired your PS3 joystick with your RPi's Wireless dongle, you will see the output in the terminal interface that looks like the example below.

      After these modifications, you can disconnect the Playstation 3 joystick from the Pi 4; we won't need it plugged in through USB again unless you upgrade your Wireless adapter. You can either use the bluetoothctl program to communicate to the Playstation 3 joystick or compile and install sixad to manage the connection. We think you should give Wireless a shot because it works well with other wireless devices. Read on to learn more about utilizing Bluetooth to link your PlayStation 3 joystick. If you'd rather learn how to connect the joystick with SIXAD, you can do so below.

      Getting your Playstation 3 joystick set up with bluetoothctl

      Now that the Playstation 3 joystick has been prepped for use with the Pi 4, we can proceed to pair the two devices. The first step is launching the Bluetooth setup tool on pi four by entering the command below.

      sudo bluetoothctl

      Our Bluetooth setup tool is now active, and we can turn on the agent and tell it to use the default agent. To do so, simply enter the two instructions below.

      agent on

      default-agent

      Following the successful execution of the preceding command, the program will begin scanning for new wireless devices, allowing us to locate them.

      scan on

      Any nearby wireless device will immediately become visible in the command prompt. Put these out of your mind for the time being and focus only on the Playstation 3 controller. The controller may now communicate with the pi four by holding the Ps button. The terminal's command line will begin to fill up shortly.

      The MAC address will show in a format similar to the following; be sure to write it down. It's the string of words delineated by colons.

      A MAC address has just become available, so write it down. Now that you have the MAC address, you may put it to use in the subsequent command. By issuing the command below, we hope to establish communication with the gadget and retrieve its unique identifier. You may need to retry this command several times before it works if you've tracked down a MAC address, substitute "YOUR MAC ADDRESS" with it.

      connect YOUR_MAC_ADDRESS

      If your Ps3 joystick stops attempting to connect, please check the status and hit the Playstation key again. If the following text shows in the cli, the connection was established successfully. We can go on to the next phase now that we have the UUIDs.

      We need the MAC address to add the device to our Bluetooth-approved approved list. This enables the controller to connect with the Raspberry Pi without human intervention. We can accomplish this by inputting this command into our Pi 4. Be sure to change "YOUR MAC ADDRESS" to the address you uncovered.

      trust YOUR_MAC_ADDRESS

      After adding your Playstation 3 controller to the authorized list, the terminal should read as follows.

      We may now exit the Bluetooth settings tool on the Pi 4 since the Playstation 3 joystick has been successfully paired with the Pi 4. Type the following commands or press CTRL + D to exit the program.

      Quit

      The RPi can be restarted at this point. This is done to verify that our system performs as expected during testing. To force the Raspberry to restart, type the command below.

      sudo reboot

      After rebooting the Pi 4, you can verify that your joystick appropriately communicates with the device by pressing the Playstation button. The controller's lights will momentarily blink when it connects, but subsequently, assuming everything went smoothly, only one morning will stay on.

      Getting Your Playstation 3 Controller to Work with SIXAD

      We need to install some prerequisite software on our RPi before we can begin compiling and configuring SIXAD. libusb-dev and libbluetooth-dev are required for compiling the sixad program and are essential libraries. Libusb-dev is a collection of source code that enables us to communicate with USB devices connected to a computer. To communicate with the Wireless stack in an OS, Libbluetooth-dev supplies the necessary code. In sixad's setup, this is what monitors for the presence of a Playstation 3 controller when it is plugged into the Pi 4.

      sudo apt install git libbluetooth-dev check install libusb-dev

      sudo apt install joystick pkg-config

      Since we have everything we need, we can download the SIXAD repo from Retropie. We're using Retropie's fork because it includes some bug fixes and has been validated on the Pi 4. You can download the GIT repo onto our Pi 4 using the two commands below.

      cd ~

      git clone https://github.com/RetroPie/sixad.git

      Now that we have the repo downloaded to our Pi 4, we can begin compiling. The following two instructions are all that are needed to compile SIXAD. The first line of code changes directories, and the second line of code builds the program by executing the makefile.

      cd ~/sixad

      make

      Compiling the sixad code was the first step, but there are still a few things to accomplish before we can put it to use. The first step is creating a directory in which sixad stores all its user profiles. Create a new folder by running the command below.

      sudo mkdir -p /var/lib/sixad/profiles

      Let's finish by launching the checkinstall package we set up in the previous section. This program just verifies the current installation and, if necessary, executes the "make install" commands.

      sudo checkinstall

      During installation, you may be prompted to provide information or confirm selections; however, you can safely skip them and hit ENTER to proceed. Following completion of the installation, the following lines should show at your terminal.

      The command below will launch sixad on your Raspberry Pi after completing the installation process.


      sudo sixad --start

      You should be prompted to push the Playstation key on your joystick to ensure proper operation. Connect the joystick to the Pi immediately.

      Since we have sixad functioning, we need to set it the default loader at startup so we can always use our Playstation 3 joystick. The command below will insert sixad into the RPi's boot procedure.

      sudo update-RC.d sixad defaults

      How to Configure a PS4 Controller for Use With a Pi 4

      The Ps4 controller can be used with the Pi 4 in various ways. There are a few of these that are easier to handle than others.

      Wireless USB Adapter from Sony

      To connect your PlayStation 4 joystick to your Pi 4, the Sony Bluetooth Adapter is your best bet. Especially considering that, in theory, the dongle should work immediately upon removal from its packaging and connect with any of the approved Playstation 4 controllers.

      Bluetooth

      To use Bluetooth, you'll need a Pi 4 or a USB wireless adapter in addition to the certified Sony Wireless adaptor. Although this solution should work for most Playstation 4 controllers, some users have reported success with a userspace gamepad driver named ds4drv. If you have already installed the SIXAD utility, you will need to remove it before you can use your Playstation 4 joystick with the Pi 4.

      Universal Serial Bus Cable

      To use your Playstation 4 joystick, simply plug it into a USB port on your computer using the same USB connection you used to connect to your Playstation 4. The Playstation 4 joystick should automatically connect via USB and work without additional setup.

      Setting up BluetoothCTL for your Playstation 4 Controller

      The next instructions are only necessary if you have followed the tutorial on pairing a Playstation 3 controller with a Pi 4 via Bluetooth. In that case, you can skip this part of the process to uninstall SIXAD.

      The PS4 controllers cannot pair or function appropriately with SIXAD installed, so they must be deleted. Simply running the command below on Pi 4 will remove the compiled and configured sixad program we discussed in the PS3 part.

      sudo dpkg -r sixad

      Before setting up the rest of the system, let's double-check that our Pi 4 has the most recent updates by issuing the instructions below.

      We will now start connecting our Playstation 4 controller to the Pi 4. The Bluetooth CLI utility will be used throughout this tutorial. Start up your RPi by entering the command below.

      sudo bluetoothctl

      After starting the bluetoothctl utility, we may activate the client and return it to its default settings by entering the commands below.

      agent on

      default-agent

      We may now begin scanning for devices after activating the agent. Scanning must be started so that our controller appears when we initiate synchronization.

      scan on

      Now is the moment to simultaneously hit the "Share" key and the Playstation button, as depicted in the following diagram. Continue holding them until the joystick's light begins blinking.

      If you see the output in the cli similar to what is shown below, jot down the MAC address. If you take the hex value after the ':' symbol, you have the MAC address.

      If your joystick is still blinking, enter this command as soon as possible. When entering the MAC address, ensure to replace "YOUR MAC ADDRESS" with the actual value. It establishes communication with your Playstation 4 controller when you enter this instruction. Press the "Share" and "PS" keys to make the joystick stop blinking.

      connect YOUR_MAC_ADDRESS

      The following will display in the terminal window if the connection is successful.

      So that the PlayStation 4 controller may instantly link to the Pi 4, we must now include our MAC address in the authorized list.

      trust YOUR_MAC_ADDRESS

      Now that the Wireless dongle on the Raspberry Pi recognizes the Playstation 4 joystick, we can exit the program by typing "quit." The next step is to verify the joystick's functionality.

      Even though the joystick feature may already be present in your Raspbian distribution, let's install it. This set has the software we need to ensure our joystick is functioning correctly. You may get the program installed on your RPi by executing the following Unix command.

      sudo apt install joystick

      Once the joystick library is installed on your Pi 4, you can check js0 and retrieve its values by using the command below.

      sudo jstest /dev/input/js0

      Changing values whenever you move and push buttons on the joystick indicates that your Playstation 4 joystick is ready to use. However, you may need to resort to the userspace drivers if your joystick stubbornly refuses to function. Finally, after getting the joystick set up, we can move on to installing the cloud on the pi four os Desktop.

      Online Xbox Play with Raspberry Pi Desktop OS

      Gaming on the go with Xbox internet Gaming is a breeze with the Pi 4 OS Desktop and Microsoft's cloud service. Instead of devoting your computer solely to Xbox internet Gaming, you can use the desktop OS of pi 4. Chromium and iCloud can be accessed with the click of an icon and by entering the relevant URL, as shown below.

      To access the internet with your RPi, launch the Chrome browser on the desktop. To access this, select the globe icon in your screen's upper right corner.

      Open your internet browser and head to the Xbox internet Gaming website. To access this in Chrome, enter the following URL into the URL bar.

      https://xbox.com/play

      You'll need to sign in with your Xbox credentials if you haven't already done so from your Pi 4. You can access the login page by clicking the "Sign in" button.

      You may see a "your browser is not supported" message after signing in. No need to panic; the XCloud server is compatible with the Chromium internet browser we are using on our Pi 4, so there's no need to switch browsers. To close this panel, click the "X" in its upper right corner.

      Simply clicking on an Xbox game will begin streaming it to your Pi 4. Any gamepad, keyboard, or joystick can be used to navigate this interface.

      There is a notice on the XCloud platform that says your streaming experience might not be ideal. Once you've selected a game for streaming to your Pi 4, you can keep playing by selecting the "CONTINUE ANYWAY" option.

      You have now installed and configured the Xbox Internet Gaming platform to run on your Pi 4. Now that you know how to handle the joystick, you can have a blast playing the video game.

      Playing Games over the cloud on an Xbox using the Pi 4 OS Lite

      There are a few extra hoops to jump through to get the Xbox Internet Gaming platform working on a Pi 4 OS Lite device. After completing these procedures, your Raspberry Pi will automatically log you in and begin running Chromium.

      Configuring Pi 4 for Automatic Login

      If you wish to access Xbox Internet Gaming as soon as you turn on your Pi 4, you'll need to take the following settings. Skipping these will result in a login prompt for the "pi" user before you can use the internet browser.

      We utilize the "Pi 4 Config tool" to set up our RPi so that it automatically enters the console at bootup, skipping the usual login process. The following command can be used to activate this utility on your gadget.

      sudo raspi-config

      Use the ARROW keys to move around the available options. To choose the highlighted item, use the Enter button. Starting with the raspi-config utility, select "System Options" from the drop-down menu. Select it by pressing the Enter button since it is the first choice.

      You'll find "Boot / Auto Login" under "System Options" in the panel. Selecting this menu item may instruct the OS to log us into the console automatically.

      The "Console Autologin" option comes next and must be chosen. If you select this, the Pi 4 will bypass the login screen and go straight to the console, where you can utilize the "pi" account.

      Having made this selection, the RPi Config Wizard can be exited with the ESC key. When prompted, choose "Yes>," and then click the Enter button to restart the computer.

      Setting up Chromium such that it launches alongside X-Server

      Once the RPi is set up to enter the console at startup, the "autostart" file can be edited to initiate the Chrome internet browser. In addition, we need to edit the ".bashrc" file by adding a single line to ensure that the window utility Chromium needs to run launched automatically after the operating system has loaded.

      So, let's begin by editing the "autostart" script in the "/etc/xdg/Openbox" folder. We'll use the nano editor to make the necessary changes to this script.

      sudo nano /etc/xdg/openbox/autostart

      Please copy and paste the lines below at the very end of this script.

      xset s off

      xset s noblank

      xset -dpms

      unclutter &

      sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' ~/.config/chromium/'Local State'

      sed -i 's/"exited_cleanly":false/"exited_cleanly":true/; s/"exit_type":"[^"]\+"/"exit_type":"Normal"/' ~/.config/chromium/Default/Preferences

      chromium-browser --disable-infobars --enable-features=OverlayScrollbar --kiosk 'https://xbox.com/play'

      Our screensaver disable commands are located on the first three lines. We employ unclutter to conceal it merely as an alternative to entirely deactivating the mouse. This is helpful because we'll frequently use the mouse for things like logging in. Finally, we start Chrome on the RPi in kiosk mode, redirecting the browser to the Xbox Internet Gaming site.

      After you've added these commands, save and exit the file. The final step is setting the Pi user's bash account so that the terminal automatically launches the window manager. 

      nano ~/.bash_profile

      This line has to be added at the very end of this document. This line will check whether it is the first time starting the terminal and if so, it will set the "$DISPLAY" property. When these prerequisites are met, the "startx" statement will be executed to launch the window manager.

      [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && startx

      When you're finished adding that line, save and exit the file. If we want to use Chromium immediately, rather than after an RPi reboots, we can launch the window manager directly. When you launch the window manager now, Chrome will also launch because you modified the "autoboot" script earlier.

      Startx

      Be sure you're typing this command into the terminal of your Pi 4 itself. If you try to use it with SSH, you will be disappointed. If you choose, you can force a restart of your RPi by executing the command below.

      sudo reboot

      Utilizing Pi 4 OS Lite for Xbox Live Cloud Gaming

      Once the RPi and Chrome have been set up, Xbox Live Games can be accessed. Your Pi's internet browser should automatically launch to the Xbox Game Pass portal.

      To use Xbox Internet Gaming for the first time, you'll need to sign in using your Xbox credentials. To access the login page, please click the image below. In any case, the "Sign In" button on this page will get you started with the login procedure if you didn't notice it before.

      After logging in, you may notice a message indicating that your browser isn't supported. Since this is a Chromium-based internet browser, the "X" in the corner can be used to close the current window.

      We can now play games on our Pi 4 by streaming them through Microsoft's Live service with Xbox Game Pass. Make sure the controller is plugged into the Pi before choosing a game. Xbox Cloud platform also allows you to use your controller for menu navigation.

      Here's a notification to let you know that the internet browser you're using isn't supported, which will appear whenever you try to play a video game that requires it. Selecting "CONTINUE ANYWAY" will allow you to disregard this notice safely.

      We can play "Phoenix Point" through the Xbox Internet Gaming service, broadcast directly to our Pi 4 in the image below. The stream may not appear where you expect it to when it first begins. However, once play begins, things should correct themselves.


      Conclusion

      Now you should be able to play Xbox games through the internet on your Pi 4. Because it is included with Xbox Game Pass, Xbox internet Gaming allows you access to various games. To a large extent, this video game streaming platform runs smoothly on the Raspberry Pi 4. There may be spikes in latency now and then, but if you play video games that don't necessitate pinpoint controls, you can probably overlook them. The following tutorial will teach how to utilize Raspberry Pi 4 as a radio streaming and broadcasting device.

      Basic Operations on Matrices in MATLAB

      Hey peeps, welcome to The Engineering Projects. We are talking about matrices, and if you want to learn them from scratch, you must go to the introduction to matrices in MATLAB. Today, we are learning how to perform different arithmetic operations on matrices. You will also see some interesting commands that are only applicable to the matrices. Here, it is important to notice that in MATLAB, the matrices are performed in the command window and there is no need to have the programming skills to perform them. Even if you are new to programming, you can easily perform the operations in MATLAB. We’ll discuss different basic operations on the matrices and will also perform each of them in MATLAB. Most of them are urinary operations and some of them are binary. Here is a small glimpse of today’s topics:

      • What is a matrix?

      • What are some basic operations of matrices?

      • What is an identity matrix?

      • How can we use the simple commands of MATLAB to perform complex and time-taking calculations with matrices?

      An Introduction to Matrices

      We all know what matrices are matrices. Yet, it is important to learn the basic definition of the matrices because this will create a map of how the basic operations on the matrices are performed. So, a matrix is defined as:

      “A matrix is a two-dimensional array with entries of the same kind in the form of real or complex data, and it takes the shape of an ordered rectangular array surrounded by a square bracket.”

      The thing to notice here is, that the data present in the matrices are of the same kind and therefore, we can perform a simple operation on each of the entries by simply applying it at once to the whole matrix.

      Now, have a look at the basic operations on the matrices. 

      Basic Operations on the Matrices

      There are several operations that can be performed on the matrices. Some of them are unary operations ( those operations that require only one matrix for the application) and most of them are binary operations that require two matrices for the performance. When you observe different types of each of them, we are going through the definition of each of them, and at the end, you will also practice each of them in MATLAB. So, have a look at the definition of each of them. 

      The Addition of the Matrices

      Yes, as you can guess, addition is a binary function, and you need two matrices to perform the addition of the matrices. The addition of the matrix takes place when both of the matrices have the same number of rows and columns. Each entry is added to the corresponding entry of the other matrix, and in this way, we get the resultant matrix with the same number of rows and columns. 

      One must keep in mind that addition is a commutative operation, which means if we have two matrices named A and B, respectively, then the addition process follows the rule given below:

      A+B=B+A

      All other rules are the same as the simple addition, but here, the equal number of rows and columns of the matrix is an additional rule that must be followed. 

      Subtraction of the Matrices

      As with the addition, the subtraction of the matrices is a binary operation, it requires the same order of both the matrices and does not follow the commutative rule. It means:

      A-B!=B-A

      And that makes sense. During the subtraction of B from A, the element on B at a particular location is subtracted from the element present on the corresponding entry of A. So, if the value of this particular element is less than the element subtracted from it, we get the answer in minus. Therefore, subtraction is not commutative.

      Multiplication of the Matrices

      The multiply operation in the matrices is somehow a little bit different from the normal multiplication. Two types of multiplication occur in the matrices:

      1. Multiplying the whole matrix with a scalar

      2. Multiplying two matrices 

      Multiplying a single number with the whole matrix is called scalar multiplication. If we are multiplying a number k with the matrix, the multiplication of k with the matrix provides us with a resultant matrix that has each entry having the value k times more than before multiplication.

      On the other hand, when two matrices are multiplied, the key point to remember is:

      During the multiplication of two matrices A and B, the number of rows of matrix A must be equal to the number of columns of matrix B; otherwise, the multiplication is impossible.

      Hence, if you are asked to multiply the matrices, this must be the first condition that you check. So, here is the procedure of matrix multiplication.

      • Check the number of rows and columns of matrices A and B.

      • Multiply each element of row 1 of matrix A with the column of matrix B. 

      • Add all the results of this multiplication together. 

      • Now, repeat the same procedure with the other rows of matrix A with the columns of matrix B.

      • In the end, you will get the resultant matrix that has the same number of rows as matrix A. 

      Therefore, the multiplication of the matrix is non-commutative and therefore we can say:

      AxB!=BxA

      This will be more clear when you learn the example in the next section. 

      Basic Operations on Matrix in MATLAB

      The solutions to the operations that we have mentioned above are time taking and require a number of steps to be followed. The same results, but in a better manner, can be obtained with the help of MATLAB. Just follow the steps to perform these operations in MATLAB. 

      Fire up your MATLAB software. 

      • Go to the command window.

      • Start writing the following code to make a matrix A in the command window:

      A=[ 2 5 8; 1 8 2; 4 6 9]

      • The resultant matrix will be shown on the screen. 

      • Now write the following code just below the matrix formed before:

      B=[1 5 2; 4 8 9; 2 7 3]

      The same result will be shown for matrix B. 

      • Now, to perform the addition of matrix A and B, write the following command in the command window:

      A+B

      It will show the results. 

      • Now write A-B. 

      You will get the results. 

      If you are performing all the operations according to the instructions, your screen will look like the following image:

      For the multiplication of both types, there are different commands. For the scalar multiplication, we are using the simple command given next:

      2*A

      It will provide us with a matrix that has two times the values of matrix A.

      For the multiplication of two matrices, the command A.*B is used. Here, the question arises why we are using the dot in between the A and B.  Have a look at the results of the different types of multiplication. We have mentioned the results when we used this command and a simple command of multiplication as A*B.

      Both types have different results. It is because using a dot between the A and B tells the compiler that we want the multiplication of each element with the other, and in this way, the authentic procedure for the multiplication is used as we have mentioned above in the multiplication section.

      Similarly, we are testing the same condition while we want the square of the matrix. We all know that a square means that each and every value is multiplied by itself. On the other hand, if we simply apply a formula to multiply value 2 with the whole matrix, we’ll get the double of each value but not the square. Let’s see this in action in MATLAB.

      You can clearly examine the difference between all the values. If we want to have the square of each element of matrix A, we have to use the third command with a dot between the matrices' names.

      Identity Matrix 

      In the discussion in the previous lecture, when we were talking about the types of matrices, we mentioned a type called the identity matrix. It is the matrix that has the arrangement of elements in such a way that only diagonal values are 1, and all the other values in the matrix are zero. It is an interesting type of matrix, and when talking about the procedure for having an identity matrix in MATLAB, it is more interesting. The following command is used to make an identity matrix:

      eye(x,y)

      Where,

      x=number of columns

      y=numbers of rows

      So basically, we are just telling the size of the matrix and MATLAB provides us with the result in a second, according to our wish. It may seem that it is a less common type of matrix, but that is not true. For many calculations, where the long and time-taking data is to be converted into a relatively simple identity matrix is used. It is also useful in systems where only binary data is used for calculations. There are some other uses of the identity matrix, but we are not going to discuss them because they are out of the scope of this lecture.

      Let’s see this in MATLAB:

      Interesting Commands Related to Matrix in MATLAB

      MATLAB provides us with great ease in dealing with the matrices and we can use them to easily get quick and easy access to our data. So go to the command window of your MATLAB again and run the following commands on it. It's fun. To compile all the things into just one table, we have added the commands that have been discussed in the early sections of this lecture.


      Command

      Description

      A=[1 3 6; 4 8 2; 6 11 3]

      It forms a matrix with the name A which has three rows and three columns with the same entries mentioned in the bracket.

      A(2,1)

      It provides us with the elements present in the second row and third column. 

      size(A)

      It shows us the size of matrix A, which is the number of rows and columns, respectively. 

      length(A)

      It is used to know the maximum number of rows or columns. It provides us with only one number, either of the rows or columns, which has the maximum value among two.

      A(:)

      It is the way to convert the whole matrix into a single column with all the entries one after the other in a vertical manner.

      A(:,2)=[ ]

      It is used to delete the 2nd column (or any other that is specified) and show the resultant matrix.

      A(1,:)=[ ]

      It deletes the first row and second column, then provides us with a matrix having the remaining entries.

      ones(2,4)

      It results in a matrix that contains two rows and four columns, but all the entries are one. 

      A’

      It is used to get the complement of the matrix A.

      These are some very basic commands that are related to the information that we have provided you till now. A great number of commands are also associated with the matrices in MATLAB, and we are going to discuss most of them in our discussion, but it is not possible to cover all of them in a single lecture. 

      Thus, today we learned a lot about matrices. We have observed some very basic but specific actions that are only possible when data is in the form of matrices. It was interesting to know that we could easily perform long calculations in MATLAB with the help of simple commands in no time. We have seen some interesting commands in MATLAB with detailed descriptions. We have also examined the output at each and every step. There are some other functions of MATLAB that help us get the results of complex commands in seconds. You must practice more by changing the elements or the numbers of rows and columns and check what results from you get with the same commands. In our next lecture, we have a lot of information about matrices.

      Introduction to Matrix in MATLAB

      Hello, learners welcome to The Engineering Projects. We are working on MATLAB, and in this tutorial, you are going to learn a lot about matrices in MATLAB. We are going to learn them from scratch, but we will avoid unnecessary details about the topic. So, without wasting time, have a look at the topics that you will learn in detail.

      • What is an array?

      • What is the matrix?

      • How can we declare a matrix in MATLAB?

      • What are the different types of matrices?

      • Can we find the unknown values of two equal matrices?

      • How can we solve the simultaneous equation in MATLAB?

      What is an Array?

      In this world of technology, the use of data is everywhere, and therefore, we can say there is a need for arrays in every field. You will find the reason soon. But before this, look at the introduction of an array.

       An array is a simple data structure that contains a collection of data presented in contiguous memory locations.

      So, the term “contiguous” used in the definition tells us that the data is in a continuous format, so we are not required to search here and there because the data is in a structured format. Moreover, arrays are of many kinds, such as

      • Two-dimensional arrays

      • Three-dimensional arrays

      In different types of cases, the suitable array is picked up so that we may get the best result with limited memory occupancy. With this type of foundation concept, we can now move forward toward our main topic, which is matrices. 

      What is a Matrix?

      In real-life applications and in higher studies, matrices are used in plenty in different forms, and therefore, we have decided to talk about them from a very basic level since it is important to understand the key features of the topics we are studying. Moreover, matrices are introduced in early classes, and it is important to refresh the basics in our minds so that we may proceed to the more complex problems. Here is the definition of "matrix":

      A matrix is a two-dimensional array in the form of an ordered rectangular array enclosed by a square bracket that has entries of the same kind in it in the form of real or complex data.

      The plural of the matrix is matrices, and sometimes the rectangular bracket is replaced by the parentheses according to the case. Just look at the image given below:

      This is a matric that contains nine elements, and you can also name this matric anything you want. In this way, it becomes easy to deal with more than one matrix, and you will see this action soon.

      Order of a Matrix

      To proceed forward, you must know the types of matrix and, for this, it is important to know the order of the matrix.

      The matrix given above is a square matrix and the horizontal lines are called columns, whereas the vertical entries are termed the rows of that particular matrix.

      If we represent the rows with the name m and the columns as n, then the order of the matrix is given as:

      mxn

      In this way, it is clear that the matrices given above have the order 3x4. If it seems to be an unnecessary thing to you, think again, because, with the help of order, we can know the type of a matrix and then perform different types of operations on it. But before this, have a look at some code in MATLAB to design matrices of different kinds. 

      Code for the Simple Matrix

      The Matrix is easily used in MATLAB, and you can start working with it by following the simple steps given below:

      • Start your MATLAB software.

      • Go to the command window.

      • Start writing the following code:

      A=[23 14 -8 33; 17 -102 0 37;3 -31 98 4];

      • Press enter. 

      In the image given overhead, these are the same entries that we have seen in the image given above, and in MATLAB, you will see the following result:

      The square bracket is not shown on the sides of the array in MATLAB. As you can see, the semicolon after every three entries indicates that the row is completed and the MATLAB compiler has to start the other row. 

      Here, A shows the name of the matrix that is compulsory, and you can name your matrix any word. If you do not follow the exact format and provide the number of entries different in rows, you will get the error. Once you know how to get started, you are ready to learn about the types of matrices.

      Types of Matrices

      There are several different types of matrices, and you can perform different arithmetic operations on the matrices only if they are of the same kind. This condition is not applied to all the operations, but most of them follow these rules. Here are some important types of matrices.

      Row Matrix

      A row matrix contains only one row and it is one of the simplest forms of a matrix. In this way, we get the matrix with a horizontal shape. The order of this matrix is:

      mxn=1xn

      Where n may be any number. 

      Column Matrix

      As you can guess, the column matrix is a type of matrix containing only one column and one or multiple rows. In this way, we get a matrix that has a vertical shape. Have a look at the order of a column matrix:

      mxn=mx1

      Where m may be any number, but the value of n is always one.

      Square Matrix

      A square matrix always has the number of rows and columns equal. It means, that no matter what the total number of entries is, the number of entries in each row and column must always be equal. In other words,

      m=n

      When you examine the example of a square matrix, you will get the reason why it is called so. The shape of this type of matrix is always square.

      Rectangular Matrix

      A rectangular matrix is one that has the arrangement of elements in such a way that the number of rows of the matrix is not equal to the number of columns. The same statement can be represented in the equation given next:

      m!=n

      Therefore, the matrix formed is in a rectangular shape, either in vertical format or horizontal format, according to the number of rows and columns.

      Diagonal Matrix

      We all know that the diagonal is the line or area that joins the upper left area with the lower right area of a rectangular or square. By the same token, a diagonal matrix is the one that contains all the diagonal values equal to zero and s in such a way that all the values other than the diagonal are zero. It will be clearer when you see the example of the diagonal matrix. We have set the examples of all the types of matrices that we have defined previously into a single MATLAB screen so you may have the best idea of each of them.

      Code and Output

      Moreover, here you can observe that instead of naming the matrices A, B, and so on, we have used the real names of the matrices for a clear declaration. Your homework is to make examples of each of them by yourself for the sake of practicing.

      Finding the Unknown Values Between Two Matrices

      Do you remember when we said the order of the matrix matters? This is one of the uses of an order of a matrix. Suppose we have two matrices named A and B, declaring that both are equal. This means that each corresponding value of a matrix A at position row 1 column 1 is equal to the corresponding value of the same position of matrix B. This is true for all the remaining values q of both matrices. Let me be clear with one example. Have a look at the picture given below:

      So, the value of r and, in return, the value of all r variables in each entry can be easily obtained by following the rules of the equation. It is one of the simplest examples of doing so, but in real life, we face complex problems. So, we use MATLAB for simplicity and accurate results. Have a look at the MATLAB code where we are going to show you an application of you can easily solve the simultaneous equation in MATLAB as well. 

      Solving Simultaneous Equations in MATLAB

      By using the property of the matrix of equality in more than one matrix, we can easily solve the simultaneous equations that are difficult and time taking if we solve them by hand. So let's see how we can declare and solve the simultaneous equation in MATLAB.

      Code:

      syms x y

      equa1= 6*x + 9*y==13;

      equa2= 9*x + 6*y==12;

      [A,B]= equationsToMatrix([equa1,equa2],[x,y])

      z=linsolve(A,B)

      Output:

      Understanding the Code

      To understand this code, you have to learn the basic definition of the function we have used in the code. It is the equationsToMatrix function. 

      equationsToMatrix Function

      The equationsToMatrix is a pre-defined function of MATLAB that converts the linear equation into a matrix so that we can use different operations on it more efficiently. It does it in the same way as we do in real life while solving the simultaneous equation with pen and paper. There are three types of syntax if this particular function. The one that we have used has the following syntax:

      [A,b] = equationsToMatrix(eqns,vars)

      Here, a minimum of two equations are required and the variables have the same condition. You must keep all the functions in mind and have to follow the exact syntax. Otherwise, it will show an error.

      linsolve Function in MATLAB

      In MATLAB, to solve the linear equation, we use this pre-defined function as it works in two ways:

      1. LU factorization with partial pivoting when in equation AB=X, A is a square. 

      2. QR factorization, otherwise.

      In our case, it has used the QR factorization. Now, you are able to understand the code clearly. 

      • First of all, the syms sign tells MATLAB that we are defining the variables. These may be one or more. But, we wanted two variables here, and we named them x and y. 

      • Now, we simply provide the values of the equation to MATLAB and store both of them into variables named equa1 and equa2 respectively. 

      • The values of variables and equations are fed into the eqautionToMatrix function to convert the linear simultaneous equation into a matrix for easy solving. 

      • In the end, we simply named a matrix z and told MATLAB that we wanted the value of variables x and y.

      Simultaneous Equation in MATLAB: Method 2

      By the same token, we can use the other method that is similar to it but the way it solves the equation is a little bit different. 

      Code:

      syms x y

      equa1= 6*x + 9*y==13;

      equa2= 9*x + 6*y==12;sol=solve([equa1,equa2],[x,y])

      asol=sol.x

       bsol=sol.y

      Output:

      Here, the only pone this is to understand. sol.x and sol.y are the functions that are used by the compiler to find the value of variables x and y respectively. You can use any variable with this sol function, after naming them at the beginning. After that, a variable is used to store and present the value of the answer obtained.

      It was an interesting lecture about the matrix, and we worked a lot from scratch to the end on many topics. We have defined the arrays and seen the introduction of the matrix. We also found information about the types of matrices. Once we have a grip on the basics, we learn that a matrix can be used to find the unknown value of two matrices, and as an application of this method, we found the values of the variable by using linear equations and learned how to declare, use, and solve the linear equation with the help of matrices in MATLAB.

      Syed Zain Nasir

      I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

      Share
      Published by
      Syed Zain Nasir