C++Learn C++

Learn How To Write A C++ App To Solve A 7 Diagonal Matrix

C++ is a great programming language to calculate engineering problems, it is one of the best for those operations. Delphi is also a super-fast compiled programming language that you can use in engineering problems. In this post we will explain how to write a C++ app to solve millions of unknowns in equations by using the Successive Over Relaxation Iteration Method. Haven’t you always wanted to hear that it’s possible to do some hard and difficult work merely by over-relaxing? 😉

In mathematics there are Implicit Equations and we Engineers are mostly faced with solving numerical equations about real life problems. Thermodynamics, fluid mechanics, mechanism theories, structure Analysis, and many other engineering areas requires us to solve many unknown equations. Sometimes calculations like these should be in real time or should be simulating time fractions very precisely. Generally, these implicit equations are exposed on a 1D, 2D or 3D grid examples (i.e compressed on uncompressed fluid flow, thermal distributions) and these grids has nodes with parameters (i.e., Velocity, Pressure, Temperature etc.)

In mathematics, an implicit equation is a relation of the form R(x1,…, xn) = 0, where R is a function of several variables. In example, the implicit equation of the unit circle is is x2 + y2 − 1 = 0. More complex equations can be given as equations about to solve first and second law of thermodynamics, Momentum Equations, Naiver-Stokes Equations etc.

An Implicit Function is a function that is defined by an implicit equation, that relates one of the variables, considered as the valueof the function, with the others considered as the arguments. These Implicit Equations can be solved by using iteration methods.

In this post we will learn to solve a 7-diagonal matrix by using successive over relaxation (SOR) iteration method In C++.

Solving 7 Diagonal Matrix

One of the most popular method is SOR Successive Over Relaxation Iteration Method (SOR). This method can be used to solve problems on 1D, 2D and 3D problems. In Numerical Linear Algebra, the Successive Over-Relaxation (SOR) Method is a variant of the  Gauss–Seidel method for solving a linear system equations, resulting in faster convergence. A similar method can be used for any slowly converging iterative processes.

If the problem is on a 3D grid (for example heat transfer on in a cube is 3D problem) this will produce 7 diagonal matrix forms. Because each 3D grid nodes on this cube connected to with left, right, front, back, up and down nodes (or they are called East, West, North, South, Up and Down) except the faces, corners and the edges. That means there will be maximum 7 variables in each lines of the 2D matrix.

Simply equations in a matrix form can be written as below.

In this equation;
M is 2D matrix (2 bars shows that it is 2D matrix),
U is 1D matrix form of unknown parameters from the each node,
q is 1D matrix form of right side of the equation.

These A matrixes can be shown as below here,

Let’s starting coding with defining our matrix forms. This matrix can be written as below,

We can print this matrix with formatting as below,

Linear equations can be solved by The Successive Over Relaxation (SOR) Method. Here we developed a SOR Revised Method (SORR) in a C++ app as below,

For example, we can calculate unknowns with maximum 1000 iterations by using this function as below,

C++ is a great programming language to solve these kinds of equations.

This is no time to relax! Download a free trial of RAD Studio today and try out SOR in your own C++ App.

close

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux and some other operating systems. Dr. Yilmaz Yoru was born in 1974, Eskisehir-Turkey. He graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later he started to work in the same university as an assistant. He received his MSc and PhD degrees from the same department of the same university. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations.
Related posts
C++Learn C++

How To Make Your C++ Compiler Fly Much Faster

C++C++11C++14C++17Introduction to C++Learn C++

This Is How To Join Two Wide Strings In Modern C++ Software

C++C++11C++14C++17Learn C++

How To Use The All-Powerful swscanf function In Your C++ App

C++ComponentsLanguage FeatureLearn C++

How To Use A Sharpen Effect in C+ Software On Windows?