Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

1

NUMERICAL METHODS
(PRACTICAL)
#ASSIGNMENT-4

NAME – ABHISHEK KUMAR PASWAN


ROLL NO – 21/632
COURSE – B Sc . MATHEMETICAL SCIENCE
SEMESTER – 6
TEACHER – H KHARBANDA MAAM
(* Name - Riya Rawal
Roll No - 21/705 *)

(* Qus1 Solve the following system of equations using Gauss Elimination method
2x-2y+3z=2 , x+2y-z=3 , 3x-y+2z=1 *)

mat = {{2, - 2, 3, 2}, {1, 2, - 1, 3}, {3, - 1, 2, 1}}


Out[31]=

{{2, - 2, 3, 2}, {1, 2, - 1, 3}, {3, - 1, 2, 1}}

In[32]:= MatrixForm[mat]
Out[32]//MatrixForm=
2 -2 3 2
1 2 -1 3
3 -1 2 1

In[33]:= mat〚1〛 = 1/2 * mat〚1〛

Out[33]=
3
1, - 1, , 1
2

In[34]:= MatrixForm[mat]
Out[34]//MatrixForm=
3
1 -1 1
2
1 2 -1 3
3 -1 2 1

In[35]:= mat〚2〛 = mat〚2〛 - mat〚1〛


mat〚3〛 = mat〚3〛 - 3 * mat〚1〛
Out[35]=
5
0, 3, - , 2
2
Out[36]=
5
0, 2, - , - 2
2

In[37]:= MatrixForm[mat]
Out[37]//MatrixForm=
3
1 -1 1
2
5
0 3 - 2
2
5
0 2 - -2
2

In[38]:= mat〚2〛 = mat〚2〛 - mat〚3〛


Out[38]=

{0, 1, 0, 4}
2

In[39]:= MatrixForm[mat]
Out[39]//MatrixForm=
3
1 -1 1
2
0 1 0 4
5
0 2 - -2
2

In[40]:= mat〚1〛 = mat〚1〛 + mat〚2〛


Out[40]=
3
1, 0, , 5
2

In[41]:= MatrixForm[mat]
Out[41]//MatrixForm=
3
1 0 5
2
0 1 0 4
5
0 2 - -2
2

In[42]:= mat〚3〛 = mat〚3〛 - 2 * mat〚2〛


Out[42]=
5
0, 0, - , - 10
2

In[43]:= mat〚1〛 = mat〚1〛 + 3 / 5 * mat〚3〛


Out[43]=

{1, 0, 0, - 1}

In[44]:= MatrixForm[mat]
Out[44]//MatrixForm=
1 0 0 -1
0 1 0 4
5
0 0 - - 10
2

In[45]:= mat〚3〛 = -2 / 5 * mat〚3〛


Out[45]=
{0, 0, 1, 4}

In[46]:= MatrixForm[mat]
Out[46]//MatrixForm=
1 0 0 -1
0 1 0 4
0 0 1 4

In[47]:= Print"The solution is(x,y,z)=(", mat1, 4, ",", mat2, 4, ",", mat3, 4 ")."

The solution is(x,y,z)=(- 1,4,4 ).


(* Name - Riya Rawal
Roll No - 21/705 *)

(*Solve the following system of equations using Gauss-Jordan Method:


2x + 4y + 6z = 22, 3x + 8y + 5z = 27,-x + y + 2z = 2 *)

In[4]:= mat = {{2, 4, 6, 22}, {3, 8, 5, 27}, {- 1, 1, 2, 2}}


Out[4]= {{2, 4, 6, 22}, {3, 8, 5, 27}, {- 1, 1, 2, 2}}

In[5]:= MatrixForm[mat]
Out[5]//MatrixForm=
2 4 6 22
3 8 5 27
-1 1 2 2

In[6]:= mat〚1〛 = 1/2 * mat〚1〛


Out[6]= {1, 2, 3, 11}

In[7]:= mat〚2〛 = mat〚2〛 - 3 * mat〚1〛


mat〚3〛 = mat〚3〛 + mat〚1〛

Out[7]= {0, 2, - 4, - 6}

Out[8]= {0, 3, 5, 13}

In[9]:= MatrixForm[mat]
Out[9]//MatrixForm=
1 2 3 11
0 2 -4 -6
0 3 5 13

In[10]:= mat〚1〛 = mat〚1〛 - mat〚2〛


Out[10]=

{1, 0, 7, 17}

In[11]:= MatrixForm[mat]
Out[11]//MatrixForm=
1 0 7 17
0 2 -4 -6
0 3 5 13

In[12]:= mat〚2〛 = 1 / 2 * mat〚2〛


Out[12]=

{0, 1, - 2, - 3}

In[13]:= MatrixForm[mat]
Out[13]//MatrixForm=
1 0 7 17
0 1 -2 -3
0 3 5 13
2

In[14]:= mat〚3〛 = mat〚3〛 - 3 mat〚2〛

Out[14]=
{0, 0, 11, 22}

In[15]:= MatrixForm[mat]
Out[15]//MatrixForm=
1 0 7 17
0 1 -2 -3
0 0 11 22

In[16]:= mat〚3〛 = 1 / 11 * mat〚3〛


Out[16]=

{0, 0, 1, 2}

In[17]:= MatrixForm[mat]
Out[17]//MatrixForm=
1 0 7 17
0 1 -2 -3
0 0 1 2

In[18]:= mat〚1〛 = mat〚1〛 - 7 * mat〚3〛


mat〚2〛 = mat〚2〛 + 2 * mat〚3〛
Out[18]=

{1, 0, 0, 3}
Out[19]=
{0, 1, 0, 1}

In[20]:= MatrixForm[mat]
Out[20]//MatrixForm=
1 0 0 3
0 1 0 1
0 0 1 2

In[21]:= RowReduce[mat] // MatrixForm


Out[21]//MatrixForm=
1 0 0 3
0 1 0 1
0 0 1 2

In[22]:= Print"The solution is(x,y,z)=(", mat1, 4, ",", mat2, 4, ",", mat3, 4 ")."

The solution is(x,y,z)=(3,1,2 ).


(* Name - Riya Rawal
Roll No - 21/705 *)

(* Qus3 3. Find the inverse of the following matrix using Gauss-Jordan Method:

A =1 1 1, 2 -3 4,


3 4 5 *)

mat1 = {{1, 1, 1}, {2, - 3, 4}, {3, 4, 5}}

Out[2]= {{1, 1, 1}, {2, - 3, 4}, {3, 4, 5}}

In[3]:= Det[mat]
Out[3]= - 12

In[49]:= A = {{1, 1, 1, 1, 0, 0}, {2, - 3, 4, 0, 1, 0}, {3, 4, 5, 0, 0, 1}}


Out[49]=

{{1, 1, 1, 1, 0, 0}, {2, - 3, 4, 0, 1, 0}, {3, 4, 5, 0, 0, 1}}

In[50]:= MatrixForm[A]
Out[50]//MatrixForm=
1 1 1 1 0 0
2 -3 4 0 1 0
3 4 5 0 0 1

In[51]:= A〚2〛 = A〚2〛 - 2 * A〚1〛


A〚3〛 = A〚3〛 - 3 * A〚1〛
Out[51]=

{0, - 5, 2, - 2, 1, 0}
Out[52]=

{0, 1, 2, - 3, 0, 1}

In[53]:= MatrixForm[A]
Out[53]//MatrixForm=
1 1 1 1 0 0
0 -5 2 -2 1 0
0 1 2 -3 0 1

In[54]:= A〚1〛 = A〚1〛 - A〚3〛


Out[54]=

{1, 0, - 1, 4, 0, - 1}

In[55]:= MatrixForm[A]
Out[55]//MatrixForm=
1 0 -1 4 0 -1
0 -5 2 -2 1 0
0 1 2 -3 0 1
2

In[56]:= A〚2〛 = -1 / 5 * A〚2〛


Out[56]=
2 2 1
0, 1, - , , - , 0
5 5 5

In[57]:= MatrixForm[A]
Out[57]//MatrixForm=
1 0 -1 4 0 -1
2 2 1
0 1 - - 0
5 5 5
0 1 2 -3 0 1

In[58]:= A〚3〛 = A〚3〛 - A〚2〛


Out[58]=
12 17 1
0, 0, , - , , 1
5 5 5

In[59]:= MatrixForm[A]
Out[59]//MatrixForm=
1 0 -1 4 0 -1
2 2 1
0 1 - - 0
5 5 5
12 17 1
0 0 - 1
5 5 5

In[60]:= A〚3〛 = 5 / 12 * A〚3〛


Out[60]=
17 1 5
0, 0, 1, - , , 
12 12 12

In[61]:= MatrixForm[A]
Out[61]//MatrixForm=
1 0 -1 4 0 -1
2 2 1
0 1 - - 0
5 5 5
17 1 5
0 0 1 -
12 12 12

In[62]:= A〚1〛 = A〚1〛 + A〚3〛


Out[62]=
31 1 7
1, 0, 0, , , - 
12 12 12

In[63]:= MatrixForm[A]
Out[63]//MatrixForm=
31 1 7
1 0 0 -
12 12 12
2 2 1
0 1 - - 0
5 5 5
17 1 5
0 0 1 -
12 12 12
3

In[64]:= A〚2〛 = A〚2〛 + 2 / 5 * A〚3〛


Out[64]=
1 1 1
0, 1, 0, - , - , 
6 6 6

In[65]:= MatrixForm[A]
Out[65]//MatrixForm=
31 1 7
1 0 0 -
12 12 12
1 1 1
0 1 0 - -
6 6 6
17 1 5
0 0 1 -
12 12 12

In[4]:= Inverse[mat1] // MatrixForm


Out[4]//MatrixForm=
31 1 7
-
12 12 12
1 1 1
- -
6 6 6
17 1 5
-
12 12 12
(* Name - Riya Rawal
Roll No - 21/705 *)

In[5]:= (*Find the inverse of the following matrix using Gauss-Jordan Method:
A =0 1 2,1 2 3,3 1 1 *)

mat1 = {{0, 1, 2}, {1, 2, 3}, {3, 1, 1}}

Out[5]= {{0, 1, 2}, {1, 2, 3}, {3, 1, 1}}

In[6]:= Det[mat1]
Out[6]= -2

In[20]:= A = {{0, 1, 2, 1, 0, 0}, {1, 2, 3, 0, 1, 0}, {3, 1, 1, 0, 0, 1}}


Out[20]=

{{0, 1, 2, 1, 0, 0}, {1, 2, 3, 0, 1, 0}, {3, 1, 1, 0, 0, 1}}

In[21]:= MatrixForm[A]
Out[21]//MatrixForm=
0 1 2 1 0 0
1 2 3 0 1 0
3 1 1 0 0 1

In[22]:= A〚1〛 = A〚1〛 + A〚2〛


Out[22]=
{1, 3, 5, 1, 1, 0}

In[23]:= A〚2〛 = A〚2〛 - A〚1〛


A〚3〛 = A〚3〛 - 3 * A〚1〛
Out[23]=
{0, - 1, - 2, - 1, 0, 0}
Out[24]=

{0, - 8, - 14, - 3, - 3, 1}

In[25]:= MatrixForm[A]
Out[25]//MatrixForm=
1 3 5 1
1 0
0 -1 -2 -1
0 0
0 - 8 - 14 - 3 - 3 1

In[26]:= A〚2〛 = - 1 * A〚2〛

Out[26]=
{0, 1, 2, 1, 0, 0}

In[27]:= MatrixForm[A]
Out[27]//MatrixForm=
1 3 5 1 1 0
0 1 2 1 0 0
0 -8 - 14 -3 -3 1
2

In[28]:= A〚1〛 = A〚1〛 - 3 * A〚2〛


A〚3〛 = A〚3〛 + 8 * A〚2〛
Out[28]=

{1, 0, - 1, - 2, 1, 0}
Out[29]=

{0, 0, 2, 5, - 3, 1}

In[30]:= MatrixForm[A]
Out[30]//MatrixForm=
1 0 -1 -2 1 0
0 1 2 1 0 0
0 0 2 5 -3 1

In[31]:= A〚3〛 = 1 / 2 * A〚3〛


Out[31]=
5 3 1
0, 0, 1, , - , 
2 2 2

In[32]:= MatrixForm[A]
Out[32]//MatrixForm=
1 0 -1 -2 1 0
0 1 2 1 0 0
5 3 1
0 0 1 -
2 2 2

In[33]:= A〚1〛 = A〚1〛 + A〚3〛


A〚2〛 = A〚2〛 - 2 * A〚3〛
Out[33]=
1 1 1
1, 0, 0, , - , 
2 2 2
Out[34]=

{0, 1, 0, - 4, 3, - 1}

In[35]:= MatrixForm[A]
Out[35]//MatrixForm=
1 1 1
1 0 0 -
2 2 2
0 1 0 -4 3 -1
5 3 1
0 0 1 -
2 2 2

In[7]:= Inverse[mat1] // MatrixForm


Out[7]//MatrixForm=
1 1 1
-
2 2 2
-4 3 -1
5 3 1
-
2 2 2

You might also like