/* GAUSS-JORDAN INDIRGEME YONTEMI
SELCUK UNV.BYL.MÜH.TEZSYZ YÜKSEK LYSANS
SAYISAL ANALYZ DERSY ÖDEV - 2
HAZIRLAYAN MAHMUT ACAR (...1043)
*/
#include <iostream>
#include <stdlib.h>
using namespace std;
float HazirDizi( float a[3][4]); // Hazyr girilmis bir dizinin kullanylmasy
float DiziGiris(float a[3][4]); // kullanycynyn kendi dizisini girebilmesi
int main(int argc, char *argv[])
{ // de?i?kenlerin tanymlanmasy
int a,i,j,satir,sutun;
float p1,p2;
string secim="e";
p1,p2=0;
satir=3;
sutun=satir+1;
float q[3][4];
system("cls");
cout<<" \n HAZIR DIZIYI KULLANMAK ISTER MISINIZ ? (e/h)";
cin>>secim;
if ((secim=="e") or (secim=="E")) HazirDizi(q); else DiziGiris(q);
// pivot elemana bölüyoruz
for ( j=0; j<sutun;j++){
p1=q[0][0];
q[0][j]/=p1;
}
cout<<"---------------------------\n";
for (i=0; i<(satir-1); i++){
for(a=i+1; a<satir; a++){
p1=q[a][i];
for(j=0; j<sutun; j++){ q[a][j]=q[a][j]/p1;} // satyry pivot elemana böl
p2=q[i][i];
for(j=0; j<4; j++){q[a][j]=q[a][j]-(q[i][j]/p2);}// sütünlara göre syfyrla
}
}
//
for( i=0;i<satir;i++){
p1=q[i][i];
for (j=0;j<sutun;j++){
q[i][j]=q[i][j]/p1; }
}
for(a=(satir-2); a>-1; a--){
for(i=(satir-1); i>a; i--){
p1=q[a][i];
for (j=1; j<sutun; j++){ q[a][j]=q[a][j]-(p1*q[i][j]);}
}
}
cout<<"\nElde Edilen Dizi \n";
for( i=0;i<satir;i++){
for (j=0;j<sutun;j++){
cout<<q[i][j]<<" ";}
cout<<endl; }
cout<<endl;
for (i=0; i<satir;i++){ cout<<" X"<<i<<"="<<q[i][3]<<endl;}
system("PAUSE");
return 0;
}
float HazirDizi( float a[3][4])
{
a[0][0]=1; a[0][1]=-1; a[0][2]=5; a[0][3]=10;
a[1][0]=2; a[1][1]=1; a[1][2]=1; a[1][3]=5;
a[2][0]=-3; a[2][1]=-2; a[2][2]=3; a[2][3]=-2;
cout<<"-------Giris Dizisi--------\n";
for( int w=0; w<3 ;w++){ for (int t=0; t<4;t++){
if (t<3) cout<<" "<<a[w][t]<<" X"<<t+1<<" "; else cout<<"="<<a[w][t];
} cout<<endl; }
return a[3][4];
}
float DiziGiris( float a[3][4])
{
system("cls");
cout<<"\nDizinin Katsayilarini Giriniz\n\n";
for (int w=0;w<3;w++){
for (int t=0; t<4;t++){ if (t<3) {cout<<"X"<<t+1<<"=";cin>>a[w][t];} else {cout<<"Y=";cin>>a[w][t];} }
}
cout<<"-------Giris Dizisi--------\n";
for( int w=0; w<3 ;w++){ for (int t=0; t<4;t++){
if (t<3) cout<<" "<<a[w][t]<<" X"<<t+1<<" "; else cout<<"="<<a[w][t];
} cout<<endl; }
}
mahmut acar
acarmahmut@hotmail.com