Question

Locked

Can one make it solve a 5*5 matrix using gauss jordan elimination

By sneceesay77 ·
this will compute a 3*3 matrix I would like someone to compute a 5*5 matrix using Borlan C++ builder.

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
double P1,P2,P3;
int a1=Edit1->Text.ToInt();
int a2=Edit2->Text.ToInt();
int a3=Edit3->Text.ToInt();
int a4=Edit4->Text.ToInt();
int a5=Edit5->Text.ToInt();
int a6=Edit6->Text.ToInt();
int a7=Edit7->Text.ToInt();
int a8=Edit8->Text.ToInt();
int a9=Edit9->Text.ToInt();
int b1=Edit10->Text.ToInt();
int b2=Edit11->Text.ToInt();
int b3=Edit12->Text.ToInt();
// Declaring and initializing my arrays
double R1[]={a1,a4,a7,b1};
double R2[]={a2,a5,a8,b2};
double R3[]={a3,a6,a9,b3};


//using the format below
// (a11 a12 a13 |b1) ( 1 a b |nb1)
// (a21 a22 a23 |b2) =======>>> ( 0 c d |nb2)
// (a31 a32 a33 |b3) ( 0 0 e |nb3)

double r21=R2[0]-R2[0]/R1[0]*R1[0]; //making a21 to be 0
double r22=R2[1]-R2[0]/R1[0]*R1[1]; //Finding the new value of a22
double r23=R2[2]-R2[0]/R1[0]*R1[2]; //Finding the new value of a23
double r2b=R2[3]-R2[0]/R1[0]*R1[3]; //Finding the new value of b3

///////////////////////////
double r31=R3[0]-R3[0]/R1[0]*R1[0];
double r32=R3[1]-R3[0]/R1[0]*R1[1];
double r33=R3[2]-R3[0]/R1[0]*R1[2];
double r3b=R3[3]-R3[0]/R1[0]*R1[3];


/////////////////////////
double R11[]={a1,a4,a7,b1};
double R21[]={r21,r22,r23,r2b};
double R31[]={r31,r32,r33,r3b};
////////////////


//double v1=R31[1]- R31[1]/R21[1]*R21[1];
double v2=R31[2]- R31[1]/R21[1]*R21[2];
double vb=R31[3]- R31[1]/R21[1]*R21[3];


///////////////

//double N1[]={a1,a4,a7,b1};
//double N2[]={r21,r22,r23,r2b};
//double N3[]={r31,v1,v2,vb};

if(v2!=0){
P3=vb/v2;
Form1->Label1->Caption=P3;
}else if(v2==0){
Form1->Label1->Caption="X3 does not exist";
}
if(r22!=0){
P2=(r2b-r23*P3)/r22;
Form1->Label2->Caption=P2;
} else if(r22==0){
Form1->Label2->Caption="X2 does not exist";
}
if(a1!=0){
P1=(b1-a7*P3-a4*P2)/a1;
Form1->Label3->Caption=P1;
}else if(a1==0){
Form1->Label3->Caption="X1 does not exist";

//printing out the values;

//Form1->Label8->Caption="ACTUALLY IT IS A TOUGH ASSIGNMENT!!!!!!";
}


}
//---------------------------------------------------------------------------

This conversation is currently closed to new comments.

0 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Share your knowledge
Back to Peripheral Forum
0 total posts (Page 1 of 1)  

Related Discussions

Related Forums