SlideShare a Scribd company logo
1 of 4
Download to read offline
www.engineeringwithsandeep.com| Student Assignment
Assignment No. 04
Solve the set of linear equations
04.04.2021
Shivam Choubey
Student No: CFDB30321004
www.engineeringwithsandeep.com| Student Assignment
Gauss Elimination
% solve Gauss elimination method consider
% 2a+2b-c+d=4
% 4a+3b-c+2d=6
% 8a+5b-3c+4d=12
%3a+3b-2c+2d=6
% checking A^-1*b
A=[2 2 -1 1;4 3 -1 2;8 5 -3 4;3 3 -2 2];
b=[4 6 12 6]';
[n, n] = size(A);
[n, k] = size(b);
x = zeros(n,k); %%initial value
for i = 1:n-1
m = -A(i+1:n,i)/A(i,i);
A(i+1:n,:) = A(i+1:n,:) + m*A(i,:);
b(i+1:n,:) = b(i+1:n,:) + m*b(i,:);
end;
disp("Matrix before back substitution ")
A
% Use back substitution to find unknowns
x(n,:) = b(n,:)/A(n,n);
for i = n-1:-1:1
x(i,:) = (b(i,:) -
A(i,i+1:n)*x(i+1:n,:))/A(i,i);
end
disp("Value of a ,b ,c & d ")
x
disp("Checking result")
disp("inverse of A")
val=inv(A)
disp("Value of a,b,c &d ")
val*b
Ouput
>> Gauss
Matrix before back substitution
A =
2.0000 2.0000 -1.0000 1.0000
0 -1.0000 1.0000 0
0 0 -2.0000 0
0 0 0 0.5000
Value of a ,b ,c & d
x =
1
1
-1
-1
Checking result
inverse of A
val =
0.5000 1.0000 0.2500 -1.0000
0 -1.0000 -0.5000 0
0 0 -0.5000 0
0 0 0 2.0000
Value of a,b,c &d
ans =
1
1
-1
-1
www.engineeringwithsandeep.com| Student Assignment
Gauss Jordan Method
function [x,err]=gauss_jordan_elim(A,b)
A=[2 2 -1 1;4 3 -1 2;8 5 -3 4;3 3 -2 2];
b=[4 6 12 6]';
[n,m]=size(A);
Aa=[A,b];
for i=1:n
[Aa(i:n,i:n+1),err]=gauss_pivot(Aa(i:n,i:n+1));
if err == 0
Aa(1:n,i:n+1)=gauss_jordan_step(Aa(1:n,i:n+1),i);
end
end
x=Aa(:,n+1);
A=0;
www.engineeringwithsandeep.com| Student Assignment
Continue code
function A1=gauss_jordan_step(A,i)
[n,m]=size(A);
A1=A;
s=A1(i,1);
A1(i,:) = A(i,:)/s;
k=[[1:i-1],[i+1:n]];
for j=k
s=A1(j,1);
A1(j,:)=A1(j,:)-A1(i,:)*s;
end % end of for loop
function [A1,err]=gauss_pivot(A)
[n,m]=size(A);
A1=A;
err = 0;
if A1(1,1) == 0
check = logical(1);
i = 1;
end
gauss_jordon
ans =
1
1
-1
-1
Checking
inv(A)
ans =
1.0000 -0.5000 0.5000 -1.0000
1.0000 0.5000 -0.5000 0
-1.0000 1.5000 -0.5000 0
-4.0000 1.5000 -0.5000 2.0000
>> inv(A)*b
ans =
1
1
-1
-1

More Related Content

What's hot

Algebra 7 Point 5
Algebra 7 Point 5Algebra 7 Point 5
Algebra 7 Point 5
herbison
 
Germany population keynote
Germany population keynoteGermany population keynote
Germany population keynote
Evan Franz
 
Derivadas ( jesus crespo)
Derivadas ( jesus crespo)Derivadas ( jesus crespo)
Derivadas ( jesus crespo)
jesusacb
 
1.2 expansion and factorization
1.2 expansion and factorization1.2 expansion and factorization
1.2 expansion and factorization
MARA
 
Ninth grade 4th period study guide key
Ninth grade 4th period study guide keyNinth grade 4th period study guide key
Ninth grade 4th period study guide key
Joshua Gerrard
 
CM1.4 Algorithms, python and SAGE
CM1.4 Algorithms, python and SAGECM1.4 Algorithms, python and SAGE
CM1.4 Algorithms, python and SAGE
A Jorge Garcia
 
Lista plantão 05 - 7º ano
Lista plantão 05 - 7º anoLista plantão 05 - 7º ano
Lista plantão 05 - 7º ano
Prof. Materaldo
 
Lista plantão 04 - 7º ano
Lista plantão   04 - 7º anoLista plantão   04 - 7º ano
Lista plantão 04 - 7º ano
Prof. Materaldo
 
Mate factorización por binomio - 2º
Mate   factorización por binomio - 2ºMate   factorización por binomio - 2º
Mate factorización por binomio - 2º
brisagaela29
 
C2 mate factorización por binomio - 5º
C2 mate   factorización por binomio - 5ºC2 mate   factorización por binomio - 5º
C2 mate factorización por binomio - 5º
brisagaela29
 

What's hot (19)

Algebra 7 Point 5
Algebra 7 Point 5Algebra 7 Point 5
Algebra 7 Point 5
 
No factorization,no complex methods -Simplest method to solve quadratic equa...
No factorization,no complex methods -Simplest method to solve  quadratic equa...No factorization,no complex methods -Simplest method to solve  quadratic equa...
No factorization,no complex methods -Simplest method to solve quadratic equa...
 
Ch02 22
Ch02 22Ch02 22
Ch02 22
 
Germany population keynote
Germany population keynoteGermany population keynote
Germany population keynote
 
Derivadas ( jesus crespo)
Derivadas ( jesus crespo)Derivadas ( jesus crespo)
Derivadas ( jesus crespo)
 
1.2 expansion and factorization
1.2 expansion and factorization1.2 expansion and factorization
1.2 expansion and factorization
 
Calculo mental 2019 5 to1
Calculo mental 2019  5 to1Calculo mental 2019  5 to1
Calculo mental 2019 5 to1
 
How to check if your multiplication is correct
How to check if your multiplication is correctHow to check if your multiplication is correct
How to check if your multiplication is correct
 
Productos notables
Productos notablesProductos notables
Productos notables
 
Ninth grade 4th period study guide key
Ninth grade 4th period study guide keyNinth grade 4th period study guide key
Ninth grade 4th period study guide key
 
Math basic
Math basicMath basic
Math basic
 
CM1.4 Algorithms, python and SAGE
CM1.4 Algorithms, python and SAGECM1.4 Algorithms, python and SAGE
CM1.4 Algorithms, python and SAGE
 
Lista plantão 05 - 7º ano
Lista plantão 05 - 7º anoLista plantão 05 - 7º ano
Lista plantão 05 - 7º ano
 
Lista plantão 04 - 7º ano
Lista plantão   04 - 7º anoLista plantão   04 - 7º ano
Lista plantão 04 - 7º ano
 
Proofs day 2
Proofs day 2Proofs day 2
Proofs day 2
 
Mate factorización por binomio - 2º
Mate   factorización por binomio - 2ºMate   factorización por binomio - 2º
Mate factorización por binomio - 2º
 
C2 mate factorización por binomio - 5º
C2 mate   factorización por binomio - 5ºC2 mate   factorización por binomio - 5º
C2 mate factorización por binomio - 5º
 
2 punto medio
2 punto medio2 punto medio
2 punto medio
 
Real Numbers
Real NumbersReal Numbers
Real Numbers
 

Similar to Solve the set of linear equations

Final exam g8 correction
Final exam g8 correctionFinal exam g8 correction
Final exam g8 correction
zeinabze
 
Sesion de aprendizaje de ecuacion de primer grado algebra pre universitaria c...
Sesion de aprendizaje de ecuacion de primer grado algebra pre universitaria c...Sesion de aprendizaje de ecuacion de primer grado algebra pre universitaria c...
Sesion de aprendizaje de ecuacion de primer grado algebra pre universitaria c...
Demetrio Ccesa Rayme
 
Sesión de Aprendizaje : Ecuación de primer grado Algebra pre-universitaria c...
Sesión de Aprendizaje :  Ecuación de primer grado Algebra pre-universitaria c...Sesión de Aprendizaje :  Ecuación de primer grado Algebra pre-universitaria c...
Sesión de Aprendizaje : Ecuación de primer grado Algebra pre-universitaria c...
Demetrio Ccesa Rayme
 
Sesión de Aprendizaje Ecuación de Primer Grado Algebra pre-universitaria cc...
Sesión de Aprendizaje   Ecuación de Primer Grado Algebra pre-universitaria cc...Sesión de Aprendizaje   Ecuación de Primer Grado Algebra pre-universitaria cc...
Sesión de Aprendizaje Ecuación de Primer Grado Algebra pre-universitaria cc...
Demetrio Ccesa Rayme
 

Similar to Solve the set of linear equations (20)

Matematicas para ingenieria 4ta edicion - john bird
Matematicas para ingenieria   4ta edicion - john birdMatematicas para ingenieria   4ta edicion - john bird
Matematicas para ingenieria 4ta edicion - john bird
 
Matrices 44.4
Matrices 44.4Matrices 44.4
Matrices 44.4
 
Diagnostic_Exam_Grade_7_Mathematics.docx
Diagnostic_Exam_Grade_7_Mathematics.docxDiagnostic_Exam_Grade_7_Mathematics.docx
Diagnostic_Exam_Grade_7_Mathematics.docx
 
Final exam g8 correction
Final exam g8 correctionFinal exam g8 correction
Final exam g8 correction
 
Sesion de aprendizaje de ecuacion de primer grado algebra pre universitaria c...
Sesion de aprendizaje de ecuacion de primer grado algebra pre universitaria c...Sesion de aprendizaje de ecuacion de primer grado algebra pre universitaria c...
Sesion de aprendizaje de ecuacion de primer grado algebra pre universitaria c...
 
Vector Algebra One Shot #BounceBack.pdf
Vector Algebra One Shot #BounceBack.pdfVector Algebra One Shot #BounceBack.pdf
Vector Algebra One Shot #BounceBack.pdf
 
Dynamic Programming Matrix Chain Multiplication
Dynamic Programming Matrix Chain MultiplicationDynamic Programming Matrix Chain Multiplication
Dynamic Programming Matrix Chain Multiplication
 
Algebra 1 week 10 learn it
Algebra 1 week 10 learn itAlgebra 1 week 10 learn it
Algebra 1 week 10 learn it
 
Solution of matlab chapter 1
Solution of matlab chapter 1Solution of matlab chapter 1
Solution of matlab chapter 1
 
Sect3 7
Sect3 7Sect3 7
Sect3 7
 
Bca3010 computer oriented numerical methods
Bca3010  computer oriented numerical methodsBca3010  computer oriented numerical methods
Bca3010 computer oriented numerical methods
 
Sesión de Aprendizaje : Ecuación de primer grado Algebra pre-universitaria c...
Sesión de Aprendizaje :  Ecuación de primer grado Algebra pre-universitaria c...Sesión de Aprendizaje :  Ecuación de primer grado Algebra pre-universitaria c...
Sesión de Aprendizaje : Ecuación de primer grado Algebra pre-universitaria c...
 
Sesión de Aprendizaje Ecuación de Primer Grado Algebra pre-universitaria cc...
Sesión de Aprendizaje   Ecuación de Primer Grado Algebra pre-universitaria cc...Sesión de Aprendizaje   Ecuación de Primer Grado Algebra pre-universitaria cc...
Sesión de Aprendizaje Ecuación de Primer Grado Algebra pre-universitaria cc...
 
Soal tiu tes cpns 2019 part 1
Soal tiu tes cpns 2019 part 1Soal tiu tes cpns 2019 part 1
Soal tiu tes cpns 2019 part 1
 
Chapter 6 algebraic expressions iii
Chapter 6   algebraic expressions iiiChapter 6   algebraic expressions iii
Chapter 6 algebraic expressions iii
 
Tugas mtk 1.01
Tugas mtk 1.01Tugas mtk 1.01
Tugas mtk 1.01
 
Solucionario c.t. álgebra 5°
Solucionario c.t.   álgebra 5°Solucionario c.t.   álgebra 5°
Solucionario c.t. álgebra 5°
 
ikh323-05
ikh323-05ikh323-05
ikh323-05
 
solving quadratic equations using quadratic formula
solving quadratic equations using quadratic formulasolving quadratic equations using quadratic formula
solving quadratic equations using quadratic formula
 
CP Lecture 1
CP Lecture 1CP Lecture 1
CP Lecture 1
 

More from shivam choubey

Airfoil Analysis(NACA 0012 ) Ansys Fluent
Airfoil Analysis(NACA 0012 ) Ansys FluentAirfoil Analysis(NACA 0012 ) Ansys Fluent
Airfoil Analysis(NACA 0012 ) Ansys Fluent
shivam choubey
 

More from shivam choubey (10)

Simulation Investigation of Separated Nozzle Flows
Simulation Investigation of Separated Nozzle FlowsSimulation Investigation of Separated Nozzle Flows
Simulation Investigation of Separated Nozzle Flows
 
steady state CFD simulation on basic shapes and calculate Cd value
steady state CFD simulation on basic shapes and calculate Cd valuesteady state CFD simulation on basic shapes and calculate Cd value
steady state CFD simulation on basic shapes and calculate Cd value
 
External Aerodynamics (Ahmed body)
External Aerodynamics (Ahmed body)External Aerodynamics (Ahmed body)
External Aerodynamics (Ahmed body)
 
Airfoil Analysis(NACA 0012 ) Ansys Fluent
Airfoil Analysis(NACA 0012 ) Ansys FluentAirfoil Analysis(NACA 0012 ) Ansys Fluent
Airfoil Analysis(NACA 0012 ) Ansys Fluent
 
Couette flow Ansys simulation
Couette flow Ansys simulationCouette flow Ansys simulation
Couette flow Ansys simulation
 
Mixing elbow simulation Ansys
Mixing elbow simulation AnsysMixing elbow simulation Ansys
Mixing elbow simulation Ansys
 
sin cos & tan (Plot using MATLAB)
sin cos  & tan (Plot using MATLAB)sin cos  & tan (Plot using MATLAB)
sin cos & tan (Plot using MATLAB)
 
The Singular Value Decomposition theroy + example
 The Singular Value Decomposition theroy + example  The Singular Value Decomposition theroy + example
The Singular Value Decomposition theroy + example
 
1-D Steady Heat conduction FDM
1-D Steady Heat conduction FDM1-D Steady Heat conduction FDM
1-D Steady Heat conduction FDM
 
The finite volume method for diffusion problems
The finite volume method for diffusion problemsThe finite volume method for diffusion problems
The finite volume method for diffusion problems
 

Recently uploaded

Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 

Solve the set of linear equations

  • 1. www.engineeringwithsandeep.com| Student Assignment Assignment No. 04 Solve the set of linear equations 04.04.2021 Shivam Choubey Student No: CFDB30321004
  • 2. www.engineeringwithsandeep.com| Student Assignment Gauss Elimination % solve Gauss elimination method consider % 2a+2b-c+d=4 % 4a+3b-c+2d=6 % 8a+5b-3c+4d=12 %3a+3b-2c+2d=6 % checking A^-1*b A=[2 2 -1 1;4 3 -1 2;8 5 -3 4;3 3 -2 2]; b=[4 6 12 6]'; [n, n] = size(A); [n, k] = size(b); x = zeros(n,k); %%initial value for i = 1:n-1 m = -A(i+1:n,i)/A(i,i); A(i+1:n,:) = A(i+1:n,:) + m*A(i,:); b(i+1:n,:) = b(i+1:n,:) + m*b(i,:); end; disp("Matrix before back substitution ") A % Use back substitution to find unknowns x(n,:) = b(n,:)/A(n,n); for i = n-1:-1:1 x(i,:) = (b(i,:) - A(i,i+1:n)*x(i+1:n,:))/A(i,i); end disp("Value of a ,b ,c & d ") x disp("Checking result") disp("inverse of A") val=inv(A) disp("Value of a,b,c &d ") val*b Ouput >> Gauss Matrix before back substitution A = 2.0000 2.0000 -1.0000 1.0000 0 -1.0000 1.0000 0 0 0 -2.0000 0 0 0 0 0.5000 Value of a ,b ,c & d x = 1 1 -1 -1 Checking result inverse of A val = 0.5000 1.0000 0.2500 -1.0000 0 -1.0000 -0.5000 0 0 0 -0.5000 0 0 0 0 2.0000 Value of a,b,c &d ans = 1 1 -1 -1
  • 3. www.engineeringwithsandeep.com| Student Assignment Gauss Jordan Method function [x,err]=gauss_jordan_elim(A,b) A=[2 2 -1 1;4 3 -1 2;8 5 -3 4;3 3 -2 2]; b=[4 6 12 6]'; [n,m]=size(A); Aa=[A,b]; for i=1:n [Aa(i:n,i:n+1),err]=gauss_pivot(Aa(i:n,i:n+1)); if err == 0 Aa(1:n,i:n+1)=gauss_jordan_step(Aa(1:n,i:n+1),i); end end x=Aa(:,n+1); A=0;
  • 4. www.engineeringwithsandeep.com| Student Assignment Continue code function A1=gauss_jordan_step(A,i) [n,m]=size(A); A1=A; s=A1(i,1); A1(i,:) = A(i,:)/s; k=[[1:i-1],[i+1:n]]; for j=k s=A1(j,1); A1(j,:)=A1(j,:)-A1(i,:)*s; end % end of for loop function [A1,err]=gauss_pivot(A) [n,m]=size(A); A1=A; err = 0; if A1(1,1) == 0 check = logical(1); i = 1; end gauss_jordon ans = 1 1 -1 -1 Checking inv(A) ans = 1.0000 -0.5000 0.5000 -1.0000 1.0000 0.5000 -0.5000 0 -1.0000 1.5000 -0.5000 0 -4.0000 1.5000 -0.5000 2.0000 >> inv(A)*b ans = 1 1 -1 -1