Solving System of Equations using MATLAB


This is a continuation of my previous post, in which we learned how to find out roots of any equation using MATLAB. In this post, we will try to solve a system of equations. In Engineering, we frequently encounter with such problems in which we have to solve system of equations.

One of the easiest ways to solve system of equations is ‘The Matrix Inverse Method’.

Suppose we are given the following equations.


We can write these equations in the form of matrix:


or


Using the same idea, we can solve system with any number of equations.

Let’s take a practical example related to electrical engineering.

Suppose you are given the following circuit and you are asked to calculate the current through all the resistance.

Our first step is to find out the equations using KCL and KCL. I assume that you know how to use KCL and KCL to find the equations. Using KCL and KCL, we have


Solving by ‘Inverse Matrix Method’



I am sure you don’t want to solve this manually if you have a choice of using MATLAB. It may be difficult for you but not at all for MATLAB.

MATLAB has built-in function to calculate the inverse of a matrix. Using this function, we can easily calculate the required unknowns buy simple matrix multiplication of Inverse of A and b.

Here a code for you guys:


clc
clear
A=[25,0,2,-10,0,0;0,10,0,10,0,2;0,0,2,0,100,2;1,0,-1,0,1,0;-1,1,0,-1,0,0;0,1,0,0,1,-1]
b=[130;460;590;0;0;0]
x=inv(A)*b

Advertisements

, , ,

  1. #1 by studio reklamy lubin on December 14, 2013 - 9:54 pm

    Thank you, I have recently been searching for info about this topic
    for ages and yours is the best I have found
    out so far. But, what about the bottom line? Are you positive in regards
    to the source?

  1. Numerical Analysis using MATLAB « Hammad Ansari's Blog
  2. Matrix Catalog Blog

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: