1-amaliy mashg’ulot topshiriqlari
-amaliy mashg’ulot topshiriqlari
Download 1.56 Mb.
|
6 ta Vazifaaaaa
- Bu sahifa navigatsiya:
- Kiruvchi ma’lumotlar
- Quyidagi funksiyani to’rtburchaklar, Trapetsiya va Simpson formulalari yordamida taqribiy hisoblash dasturini tuzing. Har bir talaba guruh jurnalidagi raqami bo’yicha bitta masala uchun dastur tuzadi.
- 3-amaliy mashg’ulot topshiriqlari 1-topshiriq
- Quyidagi transsendent tenglamani oraliqni teng ikkiga bo’lish va oddiy iteratsiya usuli yordamida yechimini aniqlovchi dastur tuzing
- Quyidagi transsendent tenglamani Nyuton va Vatarlar usuli yordamida yechimini aniqlovchi dastur tuzing
2-amaliy mashg’ulot topshiriqlari
1-topshiriq Quyidagi masalalar uchun algoritm va dastur kodini yozing. Har bir talaba o’zining jurnaldagi raqami bo’yicha bittadan masalani yechadi. Masalalar kam bo’lganda sanoq tartib boshidan boshlanadi. Masalan, 20 masala bo’lsa, 21-o’rindagi talaba 1-masalani, 22-o’rindagi talaba 2-masalani yechadi. Bir o`lchamli sonli massiv max elеmеnti bilan k chi elеmеnti o’rnini almashtiring. max elementdan bir necha bo’lishi mumkin. Kiruvchi ma’lumotlar: Birinchi satrda n (1<=n <=100). Ikkinchi satrda n ta butun son (-100<=a[i]<=100). Uchinchi satrda k (1<=k<=100) Dastur kodi: #include #include int main() { int n; std::cout << "Massivning o'lchamini kiriting (n): "; std::cin >> n; std::vector std::cout << "Massiv elementlarini kiriting:" << std::endl; for (int i = 0; i < n; i++) { std::cin >> array[i]; } int k;
std::cin >> k; int maxElement = array[0]; for (int i = 1; i < n; i++) { if (array[i] > maxElement) { maxElement = array[i]; } } int temp = array[k - 1]; array[k - 1] = maxElement; std::cout << "Yangi massiv:" << std::endl; for (int i = 0; i < n; i++) { std::cout << array[i] << " "; } std::cout << std::endl; return 0; } 2-topshiriq Quyidagi masalalar uchun algoritm va dastur kodini yozing. Har bir talaba o’zining jurnaldagi raqami bo’yicha bittadan masalani yechadi. Masalalar kam bo’lganda sanoq tartib boshidan boshlanadi. Masalan, 20 masala bo’lsa, 21-o’rindagi talaba 1-masalani, 22-o’rindagi talaba 2-masalani yechadi. Quyidagi funksiyani to’rtburchaklar, Trapetsiya va Simpson formulalari yordamida taqribiy hisoblash dasturini tuzing. Har bir talaba guruh jurnalidagi raqami bo’yicha bitta masala uchun dastur tuzadi. #include #include double f(double x) { return sin(x) / pow(cos(x), 3); } double approximateIntegralRectangles(double a, double b, int n) { double h = (b - a) / n; double integral = 0.0; for (int i = 0; i < n; i++) { double x = a + i * h; integral += f(x); } integral *= h; return integral; } double approximateIntegralTrapezoid(double a, double b, int n) { double h = (b - a) / n; double integral = 0.0; for (int i = 0; i <= n; i++) { double x = a + i * h; if (i == 0 || i == n) { integral += f(x) / 2; } else { integral += f(x); } } integral *= h; return integral; } double approximateIntegralSimpson(double a, double b, int n) { if (n % 2 != 0) { std::cout << "Error: n should be an even number for Simpson's rule." << std::endl; return 0.0; } double h = (b - a) / n; double integral = 0.0; for (int i = 0; i <= n; i++) { double x = a + i * h; if (i == 0 || i == n) { integral += f(x); } else if (i % 2 == 0) { integral += 2 * f(x); } else { integral += 4 * f(x); } } integral *= h / 3; return integral; } int main() { double a = 0.0; double b = 1.0; int n; std::cout << "Enter the number of intervals (n): "; std::cin >> n; double integralRectangles = approximateIntegralRectangles(a, b, n); double integralTrapezoid = approximateIntegralTrapezoid(a, b, n); double integralSimpson = approximateIntegralSimpson(a, b, n); std::cout << " To'rtburchaklar yordamida taxminiy integral: " << integralRectangles << std::endl; std::cout << " Trapetsiya qoidasi yordamida taxminiy integral: " << integralTrapezoid << std::endl; std::cout << " Simpson qoidasi yordamida taxminiy integral: " << integralSimpson << std::endl; return 0; } 3-amaliy mashg’ulot topshiriqlari 1-topshiriq Quyidagi masalalar uchun algoritm va dastur kodini yozing. Har bir talaba o’zining jurnaldagi raqami bo’yicha bittadan masalani yechadi. Masalalar kam bo’lganda sanoq tartib boshidan boshlanadi. Masalan, 20 masala bo’lsa, 21-o’rindagi talaba 1-masalani, 22-o’rindagi talaba 2-masalani yechadi. Quyidagi transsendent tenglamani oraliqni teng ikkiga bo’lish va oddiy iteratsiya usuli yordamida yechimini aniqlovchi dastur tuzing: 2x-lgx=3
#include #include double f(double x) { return 2 * x - log10(x) - 3; } double g(double x) { return (2 * x - 3) / log(10); } double solveEquation(double a, double b, double epsilon) { double x0 = (a + b) / 2; double x1 = g(x0); double error = std::abs(x1 - x0); while (error >= epsilon) { x0 = x1; x1 = g(x0); error = std::abs(x1 - x0); } return x1; } int main() { double a, b, epsilon; std::cout << "Intervalni kiriting [a, b]: "; std::cin >> a >> b; std::cout << "Kerakli aniqlikni kiriting (epsilon): "; std::cin >> epsilon; double solution = solveEquation(a, b, epsilon); std::cout << "Taxminiy yechim: " << solution << std::endl; return 0; } Bu kodda, f funksiyasi berilgan transsendent tenglamaning solishtiruvchi tomoni ifodalaydi (2x - log10(x) - 3). g funksiyasi esa oraliqni teng ikkiga bo'lish formulasi bilan f(x) / log(10) ifodalangan. solveEquation funksiyasi oraliqni teng ikkiga bo'lish va oddiy iteratsiya usuli yordamida yechimni topish uchun ishlatiladi. main funksiyasida foydalanuvchidan tenglamaning qiymatlarini va epsilon (xato limiti) ni olish uchun so'raladi. solveEquation funksiyasi oraliqni teng ikkiga bo'lish va oddiy iteratsiya usulidan foydalanarak yechimni hisoblayadi. Dastur natijasida aniqlovchi qiymat (Approximate solution) ekranga chiqariladi. 2-topshiriq Quyidagi masalalar uchun algoritm va dastur kodini yozing. Har bir talaba o’zining jurnaldagi raqami bo’yicha bittadan masalani yechadi. Masalalar kam bo’lganda sanoq tartib boshidan boshlanadi. Masalan, 20 masala bo’lsa, 21-o’rindagi talaba 1-masalani, 22-o’rindagi talaba 2-masalani yechadi. Quyidagi transsendent tenglamani Nyuton va Vatarlar usuli yordamida yechimini aniqlovchi dastur tuzing: x(x+1)2=2 Dastur kodi: #include #include double f(double x) { return x * pow(x + 1, 2) - 2; } double df(double x) { return 3 * pow(x, 2) + 4 * x + 1; } double solveEquationNewtonRaphson(double x0, double epsilon, int maxIterations) { double x = x0; int iterations = 0; double error = std::numeric_limits while (error >= epsilon && iterations < maxIterations) { double dx = f(x) / df(x); x = x - dx; error = std::abs(dx); iterations++; } return x; } double solveEquationSecant(double x0, double x1, double epsilon, int maxIterations) { double x2; int iterations = 0; double error = std::numeric_limits while (error >= epsilon && iterations < maxIterations) { x2 = x1 - f(x1) * (x1 - x0) / (f(x1) - f(x0)); error = std::abs(x2 - x1); x0 = x1; x1 = x2; iterations++; } return x2; } int main() { double x0, x1, epsilon; int maxIterations; std::cout << "Dastlabki taxminni x0 kiriting: "; std::cin >> x0; std::cout << "Kerakli aniqlikni kiriting (epsilon): "; std::cin >> epsilon; std::cout << "Maksimal takrorlash sonini kiriting: "; std::cin >> maxIterations; double solutionNewtonRaphson = solveEquationNewtonRaphson(x0, epsilon, maxIterations); double solutionSecant = solveEquationSecant(x0, x0 + 0.01, epsilon, maxIterations); std::cout << "Nyuton-Rafson usuli yordamida taxminiy yechim: " << solutionNewtonRaphson << std::endl; std::cout << "Sekant usuli yordamida taxminiy yechim: " << solutionSecant << std::endl; return 0; } Download 1.56 Mb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling