2-мustaqilta’limishhisoboti Fan- “Algoritmlarniloyihalash” Bajardi: Ergasheva Sevara Tekshirdi: Bobonazarov Akmal


Download 258.6 Kb.
bet4/4
Sana18.06.2023
Hajmi258.6 Kb.
#1562060
1   2   3   4
Bog'liq
Ergasheva

1-Amaliy mashg‘ulotimavzusi: Algoritmlarni loyihalash. Algoritmkorrektvasamaradorliginibaholash.

Ishningmaqsadi:Berilganmasalalaruchunalgoritmtuzish, ularnibaholashkriteriyalaribo’yichatahlilqilish, qiyinlikdarajasinibaholashnio’rganish
1-topshiriq.
Quyidagi transsendent tenglamani oraliqni teng ikkiga bo’lish va oddiy iteratsiya usuli yordamida yechimini aniqlovchi dastur tuzing:

#include


using namespace std;
double f(double x)
{
return sin(x)/(pow(x*x*x+x*x,0.25))-3*cos(x);

}
int main()


{
double a,b,c,e;
cout<<"a va b sonlarni kiriting ";
cin>>a>>b;
cout<<"aniqlikni kiriting ";
cin>>e;
while (fabs(b-a)>=e)
{
c=(a+b)/2.0;
if (f(a)*f(c)<0)
b=c;
else
a=c;
}
c=(a+b)/2.0;
cout<<"x ning qiymati "<
int n;
cin>>n;
double x[n];
int ER;
int c;
cout<<"\n\nTenglamalar sonini kiriting..";
cin>>c;

//total elements


int t=n+c;

double C[c][t+1]; //={0};


cout<<"\n\nSimplex jadval koeffitsentlarini kiriting"<for (int i=0; ifor(int j=0; jcin>>C[i][j];
}
}

double Zc[t]; //={0};


cout<<"\n\nMaqsad funksiya koeffitsenlarini kiriting..";
for(int i = 0; icin>>Zc[i];
}
//Verification of the input data

cout<<"\n\nThe Objective Function is Z = ";


for (int i=0; i
cout<}

for (int i=n; i
cout<if (i

}
//Contition for iteration


double Zsol[t+1]; //Zj array


double ratio[c]; //Ratio array
double Bv[c]; //basic values array
for (int i=0; iBv[i]=0;
}

double Zfin[t];


double Zfin_max;
Zfin_max = 1;
int Ce;

double ratio_min;


int Re;
int iter;
iter = 1;
//compute Zj

cout<<"\n\nZj = ";


for(int j=0; j<=t; j++){
for(int i=0; iZsol[j] += Bv[i]*C[i][j];
}
cout<}
//compute Cj-Zj

cout<<"\n\nCj - Zj = ";


for(int i=0; iZfin[i] = Zc[i] - Zsol[i];
//cout<}
//Compute (Cj - Zj)max == Zfin_max

Zfin_max = Zfin[0];


Ce = 0;
for(int i=1; iif( Zfin_max < Zfin[i]) {
Zfin_max = Zfin[i] ;
Ce=i;
}

else {
cout<<"\n\nChosing nex Cj-Zj";


}
}

cout<<"\n\n\nMaximum value of Cj - Zj = "<

//compute Ratio


cout<<"\n\n\nRatio array is R = ";


for(int i=0; iratio[i] = C[i][t]/C[i][Ce];
cout<}
//Compute min Ratio

cout<<"\n\n\nMinimum value f ratio is ";


ratio_min = 2500;
Re = 0;

for (int i=0; i
if(ratio_min > fabs(ratio[i]) ){
ratio_min = fabs(ratio[i]) ;
Re = i;
}
}

cout<
double Iter_C[c][t+1];

while(Zfin_max>0){


cout<<"\n\n\nIteration "<

//Entering column and exiting row


cout<<"\n\nEntering column is "<cout<<"\n\nKeyElement is "<Bv[Re] = Zc[Ce];
//Calculation for rows
// cout<<"\n\nEntering row coeff are ";
cout<<"\n\nFor entering row, old values and new values are ";

for(int j=0; j
cout<<"\t"<Iter_C[Re][j] = C[Re][j] / C[Re][Ce];
cout<<"\t"<}

// cout<<"\n\nOther columns coeff are ";


cout<<"\n\nFor other rows, old values and new values are ";
for(int i=0; iif (i != Re){
for(int j=0; j<=t; j++){
cout<<"\t"<double a = C[i][Ce] * C[Re][j] / C[Re][Ce];
Iter_C[i][j] = C[i][j] - a;
cout<<"\t"<}
cout<<"\n";
}
}

//compute Zj


cout<<"\n\n\nZj = ";


//re-assigning Zj to 0


for(int i=0; i<=t; i++){
Zsol[i] = 0;
}

for(int j=0; j<=t; j++){


for(int i=0; iZsol[j] += Bv[i]*Iter_C[i][j];
}
cout<}
//compute Cj-Zj

cout<<"\n\n\nCj - Zj = ";


for(int i=0; iZfin[i] = Zc[i] - Zsol[i];
//cout<}
//Compute (Cj - Zj)max == Zfin_max

Zfin_max = Zfin[0];


Ce = 0;
for(int i=1; iif(Zfin_maxZfin_max=Zfin[i];
Ce=i;
}

else {
// cout<<"\n\nChosing nex Cj-Zj";


}
}

cout<<"\n\n\nMaximum value of Cj - Zj = "<

if(Zfin_max<0) {


goto end;
}

//compute Ratio


cout<<"\n\n\nRatio array is R = ";


for(int i=0; iratio[i] = Iter_C[i][t]/Iter_C[i][Ce];
cout<}
//Compute min Ratio

cout<<"\n\n\nMinimum value f ratio is ";


ratio_min =2500;
Re = 0;

for (int i=0; i
if(ratio_min > fabs(ratio[i]) ){
ratio_min = fabs(ratio[i]);
Re = i;
}
}

cout<
for(int i=0; ifor(int j=0; j<=t; j++){
C[i][j] = Iter_C[i][j];
}
}

iter++;

end:cout<<"\n\nPlease check ";
}

cout<<"\n\n\n";


for(int i=0; i
for(int j=0; j<=t; j++){
cout<}
cout<<"\n";
}

cout<
return 0;
}



3-topshiriq:





#include


#include
using namespace std;

int main() {


//Input Data


cout<<"\n\nUzgaruvchilar sonini kiriting..";


int n;
cin>>n;
double x[n];
int ER;
int c;
cout<<"\n\nTenglamalar sonini kiriting..";
cin>>c;

//total elements


int t=n+c;

double C[c][t+1]; //={0};


cout<<"\n\nSimplex jadval koeffitsentlarini kiriting"<for (int i=0; ifor(int j=0; jcin>>C[i][j];
}
}

double Zc[t]; //={0};


cout<<"\n\nMaqsad funksiya koeffitsenlarini kiriting..";
for(int i = 0; icin>>Zc[i];
}
//Verification of the input data

cout<<"\n\nThe Objective Function is Z = ";


for (int i=0; i
cout<}

for (int i=n; i
cout<if (i

}
//Contition for iteration


double Zsol[t+1]; //Zj array


double ratio[c]; //Ratio array
double Bv[c]; //basic values array
for (int i=0; iBv[i]=0;
}

double Zfin[t];


double Zfin_max;
Zfin_max = 1;
int Ce;

double ratio_min;


int Re;
int iter;
iter = 1;
//compute Zj

cout<<"\n\nZj = ";


for(int j=0; j<=t; j++){
for(int i=0; iZsol[j] += Bv[i]*C[i][j];
}
cout<}
//compute Cj-Zj

cout<<"\n\nCj - Zj = ";


for(int i=0; iZfin[i] = Zc[i] - Zsol[i];
//cout<}
//Compute (Cj - Zj)max == Zfin_max

Zfin_max = Zfin[0];


Ce = 0;
for(int i=1; iif( Zfin_max < Zfin[i]) {
Zfin_max = Zfin[i] ;
Ce=i;
}

else {
cout<<"\n\nChosing nex Cj-Zj";


}
}

cout<<"\n\n\nMaximum value of Cj - Zj = "<

//compute Ratio


cout<<"\n\n\nRatio array is R = ";


for(int i=0; iratio[i] = C[i][t]/C[i][Ce];
cout<}
//Compute min Ratio

cout<<"\n\n\nMinimum value f ratio is ";


ratio_min = 2500;
Re = 0;

for (int i=0; i
if(ratio_min > fabs(ratio[i]) ){
ratio_min = fabs(ratio[i]) ;
Re = i;
}
}

cout<
double Iter_C[c][t+1];

while(Zfin_max>0){


cout<<"\n\n\nIteration "<

//Entering column and exiting row


cout<<"\n\nEntering column is "<cout<<"\n\nKeyElement is "<Bv[Re] = Zc[Ce];
//Calculation for rows
// cout<<"\n\nEntering row coeff are ";
cout<<"\n\nFor entering row, old values and new values are ";

for(int j=0; j
cout<<"\t"<Iter_C[Re][j] = C[Re][j] / C[Re][Ce];
cout<<"\t"<}

// cout<<"\n\nOther columns coeff are ";


cout<<"\n\nFor other rows, old values and new values are ";
for(int i=0; iif (i != Re){
for(int j=0; j<=t; j++){
cout<<"\t"<double a = C[i][Ce] * C[Re][j] / C[Re][Ce];
Iter_C[i][j] = C[i][j] - a;
cout<<"\t"<}
cout<<"\n";
}
}

//compute Zj


cout<<"\n\n\nZj = ";


//re-assigning Zj to 0


for(int i=0; i<=t; i++){
Zsol[i] = 0;
}

for(int j=0; j<=t; j++){


for(int i=0; iZsol[j] += Bv[i]*Iter_C[i][j];
}
cout<}
//compute Cj-Zj

cout<<"\n\n\nCj - Zj = ";


for(int i=0; iZfin[i] = Zc[i] - Zsol[i];
//cout<}
//Compute (Cj - Zj)max == Zfin_max

Zfin_max = Zfin[0];


Ce = 0;
for(int i=1; iif(Zfin_maxZfin_max=Zfin[i];
Ce=i;
}

else {
// cout<<"\n\nChosing nex Cj-Zj";


}
}

cout<<"\n\n\nMaximum value of Cj - Zj = "<

if(Zfin_max<0) {


goto end;
}

//compute Ratio


cout<<"\n\n\nRatio array is R = ";


for(int i=0; iratio[i] = Iter_C[i][t]/Iter_C[i][Ce];
cout<}
//Compute min Ratio

cout<<"\n\n\nMinimum value f ratio is ";


ratio_min =2500;
Re = 0;

for (int i=0; i
if(ratio_min > fabs(ratio[i]) ){
ratio_min = fabs(ratio[i]);
Re = i;
}
}

cout<
for(int i=0; ifor(int j=0; j<=t; j++){
C[i][j] = Iter_C[i][j];
}
}

iter++;

end:cout<<"\n\nPlease check ";
}

cout<<"\n\n\n";


for(int i=0; i
for(int j=0; j<=t; j++){
cout<}
cout<<"\n";
}

cout<
return 0;
}

Download 258.6 Kb.

Do'stlaringiz bilan baham:
1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling