Gauss Jordan Method

In the last article about solving the roots of given linear equations, we have discussed Gauss Elimination method. In that method we just go on eliminating one variable and keep on decreasing number of equations. Finally we get only one equation, with only one variable. We put this value in former equations to get values of other roots.

Similarly there is another method for finding the roots of given set of linear equations, this method is known as Gauss Jordan method. This method is same that of Gauss Elimination method with some modifications. In Gauss Jordan method we keep number of equations same as given, only we remove one variable from each equation each time. Thus finally we get same number of equations with only one variable in each equation. Thus we can find out roots of given set of linear equation.

Let me explain each step in detail:

Let us consider set of three equations as follows:

a1x+b1y+c1z=d1…………………1)

a2x+b2y+c2z=d2…………………2)

a3x+b3y+c3z=d3…………………3)

Solution:

Step 1):

Eliminate ‘x’ from 2nd and 3rd equation using 1st equation as follows:

eq.(2) – (a2/a1)*eq.(1) ;  eq.(3) – (a3/a1)*eq.(1) ;

When we solve above two equations, we get two new equations in ‘y’ and ‘z’

Write first and these two equations as follows:

a1x+b1y+c1z=d1         …………4)

b1’y+c1’z=d1’              …………..5)

b2’y+c2’z=d2’            …………..6)

Step 2):

Eliminate ‘y’ from 4th and 6th equation using 5th equation as follows:

eq.(4) – (b1/b1’)*eq.(5)  ;  eq.(6) – (b2’/b1’)*eq.(5) ;

When we solve above two equations, we get two new equations, write these equations in the following form. (Note that we are writing 5th equation as it is and defining it as 8th equation)

a1”x+c1”=d1”       …………….7)

b1’y+c1’z=d1’       …………….8)

c2”z=d2”              ..…………..9)

Don’t get over exited, here we don’t use value of z from 9th equation directly. Since it is not an elimination method.

Step 3):

Eliminate ‘z’ from 7th and 8th equation using 9th equation as follows:

eq.(7) – (c1”/c2”)*eq.(9) ; eq.(c1’/c2”)*eq.(9);

After solving above two equation, we directly get two new equations contains only one variable each.

Let us discuss Gauss Jordan method by solving one simple set of linear equation.

Example:

Find roots of following set of linear equations:

x+y+z=9…………………1)

2x-3y+4z=13…………..2)

3x+4y+5z=40…………..3)

Solution:

Step 1):

Eliminate ‘x’ from 2nd and 3rd equation using 1st equation as follows:

eq.(2) – 2*eq.(1)  ;  eq.(3) – 3*eq.(1)

x+y+z=9………………..4)

-5y+2z=-5….……………5)

y+2z=13………………….6)

Step 2):

Eliminate ‘y’ from 4th and 6th equation using 5th equation as follows:

eq.(4)+(1/5)*eq.(5)  ;  eq.(6)+(1/5)*eq.(5)  ;

x+(7/5)z=8  ……………….7)

-5y+2z=-5    ..…………….8)

(12/5)z=12   ….…………..9)

Step 3):

Eliminate ‘z’ from 7th and 8th equation using 9th equation as follows:

eq.(7)-(7/12)*eq.(9) ;  eq.(8) – (5/6)*eq.(9)

x=1; -5y=-15  i.e. y=3; Z=5.

You may also like:

 

Jacobi’s iteration method with MATLAB Program

Iterative methods for solving linear equations:

The preceding methods of solving simultaneous linear equations are known as direct methods as they yield exact solution. On the other hand an iterative method is that in which we starts from an approximation to the true solution and obtain better and better approximation from a computation cycle repeated as often as may be necessary for achieving desired accuracy. Simple iteration methods can be devised for systems in which the coefficient of leading diagonal are large compared to others.

There are two iterative methods as follows:

1)      Jacobi’s iteration method.

2)     Gauss Seidel iteration method.

Today we are just concentrating on first method that is Jacobi’s iteration method. We will see second method (Gauss Seidel iteration method) for solving simultaneous equations in next post. After that i will show you how to write a MATLAB program for solving roots of simultaneous equations using Jacobi’s Iterative method.

Jacobi’s iteration method:

Let us consider set of simultaneous equations as follows:

a1x+b1y+c1z=d1…………………1)                                           

a2x+b2y+c2z=d2…………………1)                                           

a3x+b3y+c3z=d3…………………1)           

If a1, b2, c3 are large as compare to other coefficient then solving these for x,y, and z respectively. Then the system can be written in the form:

x = (k1) – (l1)y – (m1)z…………..2)

y = (k2) – (l2)x – (m2)z…………….2)

z = (k3) – (l3)x – (m3)y…………….2)

Let us starts with the initial approximations x0=k1, y0=k2 and z0=k3.(by putting x=y=z=0 in right hand side above equation)

Then the second approximation is given by,

x1 = (k1) – (l1)y0 – (m1)z0…………..3)

y1= (k2) – (l2)x0 – (m2)z0…………….3)

z1 = (k3) – (l3)x0 – (m3)y0…………….3)

Third approximation is given by,

x2 = (k1) – (l1)y1 – (m1)z1…………..4)

y2= (k2) – (l2)x1 – (m2)z1…………….4)

z2 = (k3) – (l3)x1 – (m3)y1…………….4)

This process is repeated till difference between two consecutive approximations is negligible.

Let us understand this method in detail by solving one simple example.

Example:

Solve following set of simultaneous equations using Jacobi’s iterative method.

20x+y-2z=17

3x+20y-z=-18

2x-3y+20z=25

Solution:

We write the given equations in the following form:

x = (1/20)(17-y+2z)……………..1)

y = (1/20)(-18-3x+z)…………….1)

z = (1/20)(25-2x+3y)……………1)

Substitute x0=y0=z0=0 in above equation we get,

x1 = (1/20)(17);  y1 = (1/20)(-18);  z1=(1/20)(25).

Or x1=0.85;  y1=-0.90;  z1=1.25

Put x1, y1 and z1 in equation (1)

x2 = 1.02;  y2 = -0.965;  z2 = 1.03.

Put x2, y2 and z2 in equation (1)

x3 = 1.001;  y3 = -1.001;  z3 = 1.003.

Put x3, y3 and z3 in equation (1)

x4 = 1.0004;  y4 = -1;  z4=0.99975

Put x4, y4 and z4 in equation (1)

x5 = 1;  y5 = -1;  z5=1

 

Now it is sufficient. If you observe above two sets of roots, they are almost same.

Hence the roots of given simultaneous equations using Jacobi’s iterative method are:

x=1;  y = -1;  z=1

MATLAB program for Jacobi’s iterative method:

MATLAB code for Jacobi's iterative method
MATLAB code for Jacobi’s iterative method

You may also like:

Tags: Jacobi’s iteration method MATLAB Program.

Gauss elimination method

Gauss elimination method :

Introduction:

Carl Friedrich Gauss
Carl Friedrich Gauss

Many times we are required to find out solution of linear equations. We also know that, we can find out roots of linear equations if we have sufficient number of equations. For example if we have to calculate three unknown variables, then we must have three equations. Many times we have solved such problems by eliminating one of the root and keep on decreasing number of variables. But in some cases it is not possible or it will take more time to solve.

Gauss elimination method is one of the simple and famous methods used for finding roots of linear equations. Let us discuss this method assuming we have three linear equations in x, y and z. That is we have to find out roots of that equations (values of x, y and z).

Steps to find out roots of linear equations using Gauss elimination method:

In this method we just eliminate ‘x’ from first equation using second and third equation. After that we get only two equations with two unknowns. Similarly, we then eliminate ‘y’ from first (among two equations that we get from last step) equation using second equation. Finally we get single equation in z having constant in its right side. Now we can find ‘z’, using ‘z’ we can find ‘y’, similarly ‘x’.

Don’t get confused, I will explain each step clearly.

Let us consider three linear equations as follows:

a1x+b1y+c1z=d1…………………1)                                           

a2x+b2y+c2z=d2…………………2)                                           

a3x+b3y+c3z=d3…………………3)

From above three equations we are asked for finding values of x, y and z (values of a1, b1, c1,……..,d3 are given).                 

Step 1: Eliminate ‘x’ from first equation using second and third equation. For doing this we have to subtract 1st eq. from 2nd eq. by making coefficient of ‘x’ (of 1st equation) equals to coefficient of ‘x’ (of 2nd equation). Similarly we have to do same thing for third equation.

In short we have to solve following equations:

eq.(2) – (a2/a1)*eq.(1) and eq.(3) – (a3/a1)*eq.(1)

We get two new equations in y and z as follows:

b2’y+c2’z=d2’……..4)

b3’y+c3’z=d3’……..5)

Step 2: similarly, we have to eliminate ‘y’ from 4th equation using 5th equation.

We have to solve following equation.

eq.(5) – (b3’/b2’)*eq.(4)

we get c3”z=d3”……………6)

solving above equation we get, z=d3”/c3”

Step 3: Finally we have to put above value of ‘z’ in equation 4) (or (5)), then we get ‘y’. now we have two roots (y and z). put ‘y’ and ‘z’ in eq.(1) (or (2) or eq.(3)), we will get ‘x’.

Example 1:

Find the roots of following equations using Gauss Elimination method.

X + 4y – z = -5 ………….1)

X + y – 6z = -12…………2)

3x – y – z = 4      ………3)

Solution:

Step 1: Perform eq.(2) – (a2/a1)*eq.(1) and eq.(3) – (a3/a1)*eq.(1)

We get,                                              3y +5z =7……………4)

And

                                                        -13y +2z = 19…………..5)

Step 2: Now perform eq.(5) – (b3’/b2’)*eq.(4)

We get, -13y + 2z – (-13/3)*(3y + 5z) = 19 + (13/3)*7

71z = 148

i.e. z=148/71.

Step 3: From eq.(5) – 13y = 19 – 2*(148/71)

                                = 19 – 296/71

Y= -81/71

From eq.(1) x+4(-81/71)-148/71=-5

Therefore, x=117/71.

Thus roots of given linear equations using Gauss elimination method is

X=117/71; y=-81/71; z=148/71.

 

Example 2:

Find roots of following linear equations using Gauss Elimination method:

2x+y+z=10………1)

3x+2y+3z=18……..2)

X+4y+9z=16………..3)

Solution :

Step 1: Perform eq.(2)-(3/2)*eq(1)   and   eq(3)-(1/2)*eq(1)

We get,                                                  y+3z=6…………4)

And                                                   7y+17z=22……….5)

Step 2: Perform eq(5) – 7*eq(4)

We get, -4z=-20

i.e. z=5;

Step 3: From equation (5) y=-63/7 i.e. y=-9

From equation (1) 2x=14   i.e. x=7

Thus the roots of given linear equations is

X=7; y=-9; z=5.

You may also like:

Tags: Gauss elimination method with MATLAB Program.

lagrange interpolation with MATLAB Program

lagrange interpolation:

Introduction: 

Lagrange’s Interpolation Formula is used to determine the value of any function f(x), which is known at discrete points. That is if we have any function with its value at different points such as, at x=0, 1, 2… So using Lagrange’s Interpolation Formula, we can determine value of that function at any point.

Derivation:

We can derive the Lagrange’s Interpolation formula by using Newton’s divided difference formula. If f(x) is approximated with an Nth degree polynomial then the Nth divided difference of f(x) constant and (N+1)th divided difference is zero. That is

 1

as we know Lagrange’s interpolation is Nth degree polynomial approximation to f(x) and the Nth degree polynomial passing through (N+1) points is unique hence the Lagrange’s and Newton’s divided difference approximations are one and the same. However, Lagrange’s interpolation formula is very useful for the computer programming while Newton’s difference formula is convenient for the hand calculations.

Question: Given set of values of x and y (5,12),(6,13),(9,14),(11,16)
Find the value of x corresponding to y=15 using lagrange interpolation

Solution:

Tabular the given data:

y:  12  13  14  16

x:   5    6    9    11

Applying lagrange interpolation formula,

x(y)=(y-13)(y-14)(y-16)*5/(12-13)(12-14)(12-16)+

(y-12)(y-14)(y-16)*6/(13-12)(13-14)(13-16)+

(y-12)(y-13)(y-16)*9/(14-12)(14-13)(14-16)+

(y-12)(y-13)(y-14)*11/(16-12)(16-13)(16-14).

By putting y=15 we get x(15)=11.5

MATLAB code for lagrange interpolation formula:

%Created by myclassbook.org
%Created on 26 May 2013
%lagrange interpolation formula

% Question: Given set of values of x and y (5,12),(6,13),(9,14),(11,16)
% Find the value of x corresponding to y=15 using lagrange interpolation

clc;
clear all;
close all;
y=[12 13 14 16]; %Change here for different function
x=[5 6 9 11];
a=15;

%Applying Lagrange’s Interpolation:
ans1=((a-y(2))*(a-y(3))*(a-y(4)))*x(1)/((y(1)-y(2))*(y(1)-y(3))*(y(1)-y(4)));
ans2=((a-y(1))*(a-y(3))*(a-y(4)))*x(2)/((y(2)-y(1))*(y(2)-y(3))*(y(2)-y(4)));
ans3=((a-y(1))*(a-y(2))*(a-y(4)))*x(3)/((y(3)-y(1))*(y(3)-y(2))*(y(3)-y(4)));
ans4=((a-y(1))*(a-y(2))*(a-y(3)))*x(4)/((y(4)-y(1))*(y(4)-y(2))*(y(4)-y(3)));

m=ans1+ans2+ans3+ans4;

y
x
fprintf(‘the value of x corresponding to y=15 is %f’,m);

Image format :

MATLAB code for lagrange interpolation
MATLAB code for lagrange interpolation

Simpson’s 3/8th Rule MATLAB Program example

Simpson’s 3/8th Rule MATLAB Program example:

Question: Evaluate the integral x^4 within limits -3 to 3 using Simpson’s 3/8th Rule.

Solution:

Let y(x)=x^4

here a=-3 and b=3

therefore (b-a)=6

let ‘n’ be the number of intervals. assume n=6 in this case.

also h=(b-a)/n = 6/6 =1

x: -3  -2  -1  0  1  2  3

y: 81  16  1  0  1  16  81

According to Simpson’s 3/8th Rule:

answer= (3h/8)*[(y1+y7)+3*(y2+y3+y5+y6)+2*(y4)]

answer=(3/8)*[(81+81)+3*(16+1+1+16)+2*(0)]

answer=99.

MATLAB code for Simpson’s 3/8th rule :

%Created by myclassbook.org (Mayuresh)
%Created on 24 May 2013
%Question: Evaluate the integral x^4 within limits -3 to 3

clc;
clear all;
close all;

f=@(x)x^4; %Change here for different function
a=-3;b=3; %Given limits
n=b-a; %Number of intervals
h=(b-a)/n;
p=0;

for i=a:b
p=p+1;
x(p)=i;
y(p)=i^4; %Change here for different function
end

l=length(x);
x
y
answer=(3*h/8)*((y(1)+y(l))+3*(y(2)+y(3)+y(5)+y(6))+2*(y(4)))

Image Format :

MATLAB program for Simpon's three-eighth rule
MATLAB program for Simpon’s three-eighth rule

Second Example :

Question: Evaluate the integral 1/(1+x) within limits 0 to 6 using Simpson’s 3/8th rule.

Solution:

Let y(x)=1/(1+x)

here a=0 and b=6

therefore (b-a)=6

let ‘n’ be the number of intervals. assume n=6 in this case.

also h=(b-a)/n = 6/6 =1

x: 0                  1                    2              3                  4               5               6

y: 1.0000   0.5000   0.3333   0.2500   0.2000   0.1667   0.1429

According to Simpson’s 3/8th rule:

answer= (3h/8)*[(y1+y7)+3*(y2+y3+y5+y6)+2*(y4)]

answer=1.9660

MATLAB code for Simpson’s 3/8th rule :

%Created by myclassbook.org (Mayuresh)
%Created on 24 May 2013
%Question: Evaluate the integral 1/(1+x) within limits 0 to 6

clc;
clear all;
close all;

f=@(x)1/(1+x); %Change here for different function
a=0;b=6; %Given limits
n=b-a; %Number of intervals
h=(b-a)/n;
p=0;

for i=a:b
p=p+1;
x(p)=i;
y(p)=1/(1+i); %Change here for different function
end

l=length(x);
x
y
answer=(3*h/8)*((y(1)+y(l))+3*(y(2)+y(3)+y(5)+y(6))+2*(y(4)))

Image Format:

MATLAB code for Simpon's three-eighth rule
MATLAB code for Simpon’s three-eighth rule

You may also like:

Simpson’s 1/3rd rule MATLAB Program examples

Simpson’s 1/3rd  rule MATLAB Program examples:

Question: Evaluate the integral x^4 within limits -3 to 3 using Simpson’s 1/3 rd rule.

Solution:

Let y(x)=x^4

here a=-3 and b=3

therefore (b-a)=6

let ‘n’ be the number of intervals. assume n=6 in this case.

also h=(b-a)/n = 6/6 =1

x: -3  -2  -1  0  1  2  3

y: 81  16  1  0  1  16  81

According to Simpson’s 1/3rd  rule:

answer= (h/3)*[(y1+y7)+2*(y3+y5)+4*(y2+y4+y6)]

answer=(1/2)*[(81+81)+2*(1+1)+4*(16+0+16)]

answer=98.

MATLAB code for Simpson’s 1/3rd rule :

 

%Created by myclassbook.org (Mayuresh)
%Created on 24 May 2013
%Question: Evaluate the integral X^4 within limits 3 to -3

clc;
clear all;
close all;

f=@(x)x^4; %Change here for different function
a=-3;b=3; %Given limits
n=b-a; %Number of intervals
h=(b-a)/n;
p=0;

for i=a:b
p=p+1;
x(p)=i;
y(p)=i^4; %Change here for different function
end

l=length(x);
x
y
answer=(h/3)*((y(1)+y(l))+2*(y(3)+y(5))+4*(y(2)+y(4)+y(6)))

Image Format:

MATLAB code for Simpson's one third rule
MATLAB code for Simpson’s one third rule

Second Example :

Question: Evaluate the integral 1/(1+x) within limits 0 to 6 using Simpson’s 1/3 rd rule.

Solution:

Let y(x)=1/(1+x)

here a=0 and b=6

therefore (b-a)=6

let ‘n’ be the number of intervals. assume n=6 in this case.

also h=(b-a)/n = 6/6 =1

x: 0                  1                    2              3                  4               5               6

y: 1.0000   0.5000   0.3333   0.2500   0.2000   0.1667   0.1429

According to Simpson’s 1/3 rd rule.

answer= (h/3)*[(y1+y7)+2*(y3+y5)+4*(y2+y4+y6)]

answer=1.9587.

MATLAB code for Simpson’s 1/3rd rule :

%Created by myclassbook.org (Mayuresh)
%Created on 24 May 2013
%Question: Evaluate the integral 1/(1+x) within limits 0 to 6

clc;
clear all;
close all;

f=@(x)1/(1+x); %Change here for different function
a=0;b=6; %Given limits
n=b-a; %Number of intervals
h=(b-a)/n;
p=0;

for i=a:b
p=p+1;
x(p)=i;
y(p)=1/(1+i); %Change here for different function
end

l=length(x);
x
y
answer=(h/3)*((y(1)+y(l))+2*(y(3)+y(5))+4*(y(2)+y(4)+y(6)))

Image Format:

MATLAB code for Simpson's one third rule
MATLAB code for Simpson’s one third rule

 

tags: simpson method matlab basic example

MATLAB Programming for Trapezoidal rule with example

Trapezoidal Rule :

Derivation:

The derivation for obtaining formula for Trapezoidal rule is given by, 

1

Question: Evaluate the integral x^4 within limits -3 to 3 using Trapezoidal rule.

Solution:

Let y(x)=x^4

here a=-3 and b=3

therefore (b-a)=6

let ‘n’ be the number of intervals. assume n=6 in this case.

also h=(b-a)/n = 6/6 =1

x: -3  -2  -1  0  1  2  3

y: 81  16  1  0  1  16  81

According to trapezoidal rule:

answer= (h/2)*[(y1+y7)+2*(y2+y3+y4+y5+y6)]

answer=(1/2)*[(81+81)+2*(16+1+0+1+16)]

answer=115.

MATLAB code for Trapezoidal rule :

%Created by myclassbook.org (Mayuresh)
%Created on 24 May 2013
%Question: Evaluate the integral X^4 within limits 3 to -3

clc;
clear all;
close all;

f=@(x)x^4; %Change here for different function
a=-3;b=3; %Given limits
n=b-a; %Number of intervals
h=(b-a)/n;
p=0;

for i=a:b
p=p+1;
x(p)=i;
y(p)=i^4; %Change here for different function
end

l=length(x);
x
y
answer=(h/2)*((y(1)+y(l))+2*(sum(y)-y(1)-y(l)))

Image format :

MATLAB code for Trapazoida lrule
MATLAB code for Trapazoida lrule

Second Example :

Question: Evaluate the integral 1/(1+x) within limits 0 to 6 using Trapazoidal rule.

Solution:

Let y(x)=1/(1+x)

here a=0 and b=6

therefore (b-a)=6

let ‘n’ be the number of intervals. assume n=6 in this case.

also h=(b-a)/n = 6/6 =1

x: 0                  1                    2              3                  4               5               6

y: 1.0000   0.5000   0.3333   0.2500   0.2000   0.1667   0.1429

According to trapazoidal rule:

answer= (h/2)*[(y1+y7)+2*(y2+y3+y4+y5+y6)]

answer=2.0214.

MATLAB code for Trapazoidal rule :

%Created by myclassbook.org (Mayuresh)
%Created on 24 May 2013
%Question: Evaluate the integral 1/(1+x) within limits 0 to 6

clc;
clear all;
close all;

f=@(x)1/(1+x); %Change here for different function
a=0;b=6; %Given limits
n=b-a; %Number of intervals
h=(b-a)/n;
p=0;

for i=a:b
p=p+1;
x(p)=i;
y(p)=1/(1+i); %Change here for different function
end

l=length(x);
x
y
answer=(h/2)*((y(1)+y(l))+2*(sum(y)-y(1)-y(l)))

Image Format:

MATLAB program for Trapazoidalrule1
MATLAB program for Trapazoidalrule1

Newton’s Forward Interpolation Formula with MATLAB Example

Newton’s Forward Interpolation Formula with MATLAB Example :

Interpolation:

Introduction:

In everyday life, sometimes we may require to find some unknown value with the given set of observations. For example, the data available for the premium, payable for a policy of Rs.1000 at age x, is for every fifth year. Suppose, the data given is for the ages 30, 35, 40, 45, 50 and we are required to find the value of the premium at the age of 42 years, which is not directly given in the table. Here we use the method of estimating an unknown value within the range with the help of given set of observation which is known as interpolation.

Definition of interpolation:

Given the set of tabular values (x0, y0), (x1, y1),…,(xn, yn) satisfying the relation y=f(x) where the explicit nature of f(x) is not known, it is required to find a simpler function say ф(x), such that f(x) and ф(x) agree at the set of tabulated points. Such a process is called as interpolation.

If we know ‘n’ values of a function, we can get a polynomial of degree (n-1) whose graph passes through the corresponding points. Such a polynomial is used to estimate the values of the function at the values of x.

We will study two different interpolation formula based on finite differences, when the values of x are equally spaced. The first formula is:

Newton’s forward difference interpolation formula:

The formula is stated as:

1

Where ‘a+ph’ is the value for which the value of the function f(x) is to be estimated. Here ‘a’ is the initial value of x and ‘h’ is the interval of differencing.

Question:

Table gives the distance between nautical miles of the visible horizon for the given height in feet above the earth surface.  Find the value of y when x= 218 feet .

newtons forward interpolation formula
newtons forward interpolation formula

MATLAB program for Newtons forward interpolation formula :

newtons forward interpolation formula 1
newtons forward interpolation formula 1
newtons forward interpolation formula 2
newtons forward interpolation formula 2

You may also like:

 

Gauss Seidel – MATLAB Program and Algorithm

Gauss Seidel – MATLAB Program and Algorithm

Introduction:

We have studied in the last article that, the preceding methods of solving simultaneous linear equations are known as direct methods as they yield exact solution. On the other hand an iterative method is that in which we starts from an approximation to the true solution and obtain better and better approximation from a computation cycle repeated as often as may be necessary for achieving desired accuracy. Simple iteration methods can be devised for systems in which the coefficient of leading diagonal are large compared to others.

In the last article about solving roots of given simultaneous equations, we have studied Jacobi’s iterative method. Similarly there is another method for solving roots of simultaneous equations which is called as Gauss Seidel Iterative Method. After that we will see MATLAB program on how to find roots of simultaneous equations using Gauss Seidel Method.

Let us consider set of simultaneous equations as follows:

a1x+b1y+c1z=d1…………………1)                                           

a2x+b2y+c2z=d2…………………1)                                           

a3x+b3y+c3z=d3…………………1)     

We then solve above equation for x, y and z respectively. Then the system can be written in the form:

x = (k1) – (l1)y – (m1)z…………..2)

y = (k2) – (l2)x – (m2)z…………….2)

z = (k3) – (l3)x – (m3)y…………….2)

     

Gauss Seidel Method is a modification of Jacobi’s iteration method as before we starts with initial approximations, i.e. x0=y0=z0=0 for x, y and z respectively.

Substituting y=y0, z=z0 in the equation x1=k1, then putting x=x1, z=z0 in the second of equation (2) i.e. (y1) = (k2) – (l2)x1 – (m2)z0

Substituting x=x1, y=y1 in the third of equation (2)

i.e. (z1) = (k3) – (l3)x1 – (m3)y1  and so on.

As soon as new approximation for an unknown is found it is immediately used in the next step. This process is then repeated till desired degree of accuracy is obtained.

Let us discuss Gauss Seidel method by solving one simple example.

Example: 

Find the roots of following simultaneous equations using Gauss Seidel method.

20x+y-2z=17…………..1)

3x+20y-z=-18…………..1)

2x-3y+20z=25…………..1)

Solution :

Let us write the given equation in the form as:

x = (1/20)(17-y+2z)……………..2)

y = (1/20)(-18-3x+z)…………….2)

z = (1/20)(25-2x+3y)……………2)

we starts approximation by x0=y0=z0=0.

Substituting y=y0 and z=z0 in right hand side of first of equation (2)

X1 = 17/20=0.85

In second of equation second put x=x1 and z=z0

Y1 = (1/20)(-18-3*0.85) = -1.0275

Put x=x1, y=y1 in third of equation (2)

Z1 = (1/20)(25-2*0.85+3*-1.0275) = 1.011

Similarly we get,

x2=1.002; y2 =-0.9998; z2 =0.9998

x3 =1.0000; y3 =-1.0000; z3 =1.0000

x4 =1.0000; y4 =-1.0000; z4 =1.0000

Now it is sufficient. If you observe above two sets of roots, they are almost same.

Hence the roots of given simultaneous equations using Gauss Seidel Method are:

x=1;  y = -1;  z=1

MATLAB program for Gauss Seidel Method:

MATLAB code for Gauss Seidel method
MATLAB code for Gauss Seidel method

 

False position (regula falsi) method matlab program , algorithm , flowchart

False position method:

The false position method or regula falsi method is a term for problem-solving methods in arithmetic, algebra, and calculus. In simple terms, these methods begin by attempting to evaluate a problem using test (“false”) values for the variables, and then adjust the values accordingly.

False Position method  is the oldest method for finding the real roots of an equation f(x)=0. Also this method is closely resembled with Bisection method.

In False Position method we choose two points x0 and x1, such that f(x0) and f(x1) are of opposite sign. So the abscissa of point where the chords cuts the x-axis (y=0) is given by,

1

This is the first approximation to the root.

If now f(x0) and f(x2) are of opposite sign then the root lies between x0 and x2, so by replacing x1 by x2.

By using the following equation we obtain the second approximation:

2

Similarly, we can obtain next approximations using same equations as above. After certain approximations (when two consecutive approximations are almost same) we will get our final answer. At the end of this article, we will see how to write MATLAB program for the False Position method.

Let us solve one simple problem for clear understanding.

Example:

Find the real root of the equation  x^3-2x-5=0 by using false position method.

Solution:

Let f(x) = x^3-2x-5

F(2) = -1 = negative

F(3) = 16 = positive

Hence the roots of given equation lies between (2,3)

Let us find first approximation (x2) by taking x0=2, x1=3,

X2 = x0 – {(x1 – x0)/[f(x1) – f(x0)]}*f(x0)

Therefore, x2 = 2 – [(3-2)/(16+1)]*(-1) = 2.0588

Here, f(x2) = f(2.0588) = -0.3908 = negative

Hence, roots of given equation lies between (2.0588,3)

X3 = x1 – {(x2 – x1)/[f(x2) – f(x1)]}*f(x1)

Therefore, x3 = 2.0588 – [(3-2.0588)/(16+0.3908)]*(-0.3908) = 2.0813

Here, f(x3) = f(2.0813) = -0.1469 = negative

Hence roots lies between (2.0813,3).

Therefore, x4=2.0896

 Here, f(x4)=-0.0547

 Hence root lies between (2.0896,3)

 Therefore, x5=2.0927

 Here, f(x5)=-0.0202

 Hence root lies between (2.0927,3)

 Therefore, x6=2.0939

 Here, f(x6)=-0.0075

 Hence root lies between (2.0939,3)

 Therefore, x7=2.0943

 Here, f(x8)=-0.0027

 Hence root lies between (2.0943,3)

 Therefore, x9=2.0945

 Here, f(x9)=-0.0010

 Hence root lies between (2.0945,3)

 Therefore, x10=2.0945

 Now x9 and x10 are equal, therefore we can stop here.

So our final answer is x=2.0945.

MATLAB program for False Position Method:

 

False Position Method MATLAB Program
False Position Method MATLAB Program

 

Plot of Error of False Position Method
Plot of Error of False Position Method

Click on the following button to download the MATLAB program for false position method.

Download Button

 

You may also like: