Kompyuter injeneringi




Download 0,73 Mb.
Sana15.05.2024
Hajmi0,73 Mb.
#234766
Bog'liq
Algoritmlarni loyihalash.



TATU NURAFSHON FILIALI KOMPYUTER INJENERINGI FAKULTETI “KOMPYUTER INJENERINGI” YO’NALISHI 210-22 GURUH TALABASI NAZIRQULOV BARKAMOLNING ALGORITMLARNI LOYIHALASH FANIDAN.
3-SHAXSIY TOPSHIRIG’I.

1.Masala
#include


#include
using namespace std;

// Funksiya, iste'molchining iste'mol qilish mablag'ini hisoblash uchun


double calculateUtility(double x1, double x2) {
// Masalada berilgan funksiya (masalan, iste'molchining foydasi)
return 2 * x1 + 3 * x2;
}

// Funksiya, mablag'lar orasidagi masofani hisoblash uchun


double calculateDistance(double x1, double x2, double y1, double y2) {
return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
}

int main() {


// Iste'molchining mablag'larini (x1, x2) va joylashganliklarini (y1, y2) aniqlash
double x1, x2, y1, y2;
cout << "Iste'molchining birinchi mablag'ini kiriting: ";
cin >> x1;
cout << "Iste'molchining ikkinchi mablag'ini kiriting: ";
cin >> x2;
cout << "Birinchi joylashganlikni kiriting: ";
cin >> y1;
cout << "Ikkinchi joylashganlikni kiriting: ";
cin >> y2;

// Foydani hisoblash


double utility = calculateUtility(x1, x2);

// Masofani hisoblash


double distance = calculateDistance(x1, x2, y1, y2);

cout << "Iste'molchining foydasi: " << utility << endl;


cout << "Masofa: " << distance << endl;

return 0;


}


2.Masala.


#include
#include
using namespace std;

// Funksiya, Fur'e koeffitsientlarini hisoblash


void calculateFourierCoefficients(double a0, double an[], double bn[], int N) {
for (int n = 1; n <= N; ++n) {
an[n] = /* hisoblash formulasi */;
bn[n] = /* hisoblash formulasi */;
}
}

// Funksiya, Fur'e qatorini yaratish


double evaluateFourierSeries(double a0, double an[], double bn[], int N, double x) {
double sum = a0 / 2.0;
for (int n = 1; n <= N; ++n) {
sum += an[n] * cos(n * x) + bn[n] * sin(n * x);
}
return sum;
}

int main() {


// Fur'e koeffitsientlarini hisoblash uchun kerakli o'zgaruvchilar
double a0, an[100], bn[100];
int N;

// Funksiya qiymatlari


// Bu oraliqda f(x) qiymatlari kiritilishi mumkin, masalan, f(x) = sin(x) uchun
double f_values[] = {0.707, 1, 0.707, 0, -0.707, -1, -0.707, 0};

// X qiymatlari


double x_values[] = {0, M_PI_4, M_PI_2, 3 * M_PI_4, M_PI, 5 * M_PI_4, 3 * M_PI_2, 7 * M_PI_4};

// Fur'e koeffitsientlarini hisoblash


// Ushbu misol uchun, masalan, N = 3 olsa kerak
N = 3;
calculateFourierCoefficients(0, an, bn, N);

// Fur'e qatoridan f(x) qiymatlarini hisoblash va chiqarish


cout << "X qiymati\t\tF(x) qiymati\t\tFur'e qator qiymati" << endl;
for (int i = 0; i < 8; ++i) {
double fur_x = evaluateFourierSeries(a0, an, bn, N, x_values[i]);
cout << x_values[i] << "\t\t\t" << f_values[i] << "\t\t\t" << fur_x << endl;
}

return 0;


}

Download 0,73 Mb.




Download 0,73 Mb.