1-topshiriq variantlari Variant parametrlarini quyidagicha aniqlang: n


Download 47.94 Kb.
Sana02.06.2024
Hajmi47.94 Kb.
#1836664
Bog'liq
Algaritm amaliy 1-ish


1-topshiriq variantlari
Variant parametrlarini quyidagicha aniqlang: n1={N/3}+1; n2={N/5}+1; n3={N/7}+1, bu yerda N talabalarning potokdagi nomeri. {N/3} bu N sonini 3 ga bo’lgandagi qoldig’i. Misol: N=7 {7/3}=1.
Tenglamani hosil qiling:


  1. Tenglamaning yechim joylashgan oralig’ini toping. Vatarlar usuli yordamida ildizlarni e=10-5 aniqlik bilan hisoblash algoritmini tuzing. Bunday aniqllika erishish uchun zarur qadamlar sonini aniqlang.

  2. Ushbu masalani Nyuton usuli orqali yechish algoritmini tuzing. Ikkala usulda ham yechimlarni oling. Ko’rib chiqilgan usullar samaradorligini taqqoslang.

  3. Chiziqli dasturlash masalasini hosil qiling:


Geometrik usulda mumkin bo’lgan yechimlar sohasini toping. Tayanach yechimlarni aniqlang. Optimal yechimni toping.
Egizak masalani shakllantiring va u uchun CHDM tuzib, tayanch yechimlarni aniqlang. Shuningdek geometrik usulda optimal yechimni toping.

  1. CHDM ni simpleks usulida hisoblang. Topilgan yechimlardan iqtisodiy tahlil o’tkazing. Tegishli matematik modelni ishlab chiqarishni takomillashtirish bo’yicha tavsiyalarni shakllantiring.




1.
#include
#include

using namespace std;

int main() {
double num, guess, error, prev_guess;
int iteration_count = 0;

// Ildizning qiymatini foydalanuvchi kiritadi


cout << "Ildizni hisoblash uchun bir son kiriting: ";
cin >> num;

// Tahminlash uchun boshlang'ich qiymat


guess = num / 2;

// Aniq soatlar bilan yechim topish


do {
prev_guess = guess;
guess = (guess + num / guess) / 2;
error = abs(guess - prev_guess);
iteration_count++;
} while (error > 1e-5);

// Natijani chiqarish


cout << "Ildizning qiymati: " << guess << endl;
cout << "Yechim uchun zarur takrorlashlar soni: " << iteration_count << endl;

return 0;


}
2.
#include
#include

using namespace std;

int main() {
double num, guess, error, prev_guess;
int iteration_count = 0;

// Ildizning qiymatini foydalanuvchi kiritadi


cout << "Ildizni hisoblash uchun bir son kiriting: ";
cin >> num;

// Tahminlash uchun boshlang'ich qiymat


guess = num / 2;

// Aniq soatlar bilan yechim topish


do {
prev_guess = guess;
guess = guess - (guess * guess - num) / (2 * guess);
error = abs(guess - prev_guess);
iteration_count++;
} while (error > 1e-5);

// Natijani chiqarish


cout << "Ildizning qiymati: " << guess << endl;
cout << "Yechim uchun zarur takrorlashlar soni: " << iteration_count << endl;

return 0; #include


#include

using namespace std;

#define N3int main()
{
double A[N][N] = {{2,3,1}, {6,7,3}, {4,5,1}};
double B[N] = {5,7,3};
double x[N], y[N], e =1e-5, d;

for (int i =0; i < N; i++)


{
x[i] = B[i] / A[i][i];
}

do {
for (int i =0; i < N; i++)


{
y[i] = x[i];
x[i] = B[i];
for (int j =0; j < N; j++)
{
if (i != j)
{
x[i] -= A[i][j] * x[j];
}
}
x[i] /= A[i][i];
}
d =0;
for (int i =0; i < N; i++)
{
d += pow(x[i] - y[i],2);
}
} while (sqrt(d) > e);

double min_value = x[0];


double max_value = x[0];

for (int i =1; i < N; i++)


{
if (x[i] < min_value)
{
min_value = x[i];
}
if (x[i] > max_value)
{
max_value = x[i];
}
}

cout << "Minimal yechim: " << min_value << endl;


cout << "Maksimal yechim: " << max_value << endl;

return0;
}


}
3.
#include
#include

using namespace std;

#define N3int main()
{
double A[N][N] = {{2,3,1}, {6,7,3}, {4,5,1}};
double B[N] = {5,7,3};
double x[N], y[N], e =1e-5, d;

for (int i =0; i < N; i++)


{
x[i] = B[i] / A[i][i];
}

do {
for (int i =0; i < N; i++)


{
y[i] = x[i];
x[i] = B[i];
for (int j =0; j < N; j++)
{
if (i != j)
{
x[i] -= A[i][j] * x[j];
}
}
x[i] /= A[i][i];
}
d =0;
for (int i =0; i < N; i++)
{
d += pow(x[i] - y[i],2);
}
} while (sqrt(d) > e);

double min_value = x[0];


double max_value = x[0];

for (int i =1; i < N; i++)


{
if (x[i] < min_value)
{
min_value = x[i];
}
if (x[i] > max_value)
{
max_value = x[i];
}
}

cout << "Minimal yechim: " << min_value << endl;


cout << "Maksimal yechim: " << max_value << endl;

return0;
}


4.
#include
#include

using namespace std;

typedef vector VD;
typedef vector VVD;

const double EPSILON = 1e-10;

bool is_near_zero(double value) {
return (value > 0 ? value : -value) < EPSILON;
}

bool solve_simplex(VVD& A, VD& b, VD& c, VD& x) {


int n = c.size(), m = b.size();

// Endirish ko'rsatkichlarini qo'shamiz


VVD table(m + 1, VD(n + m + 1));
VD solution(n + m + 1);

// Ko'rsatkich jadvalida elementlarni qo'shamiz


for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
table[i][j] = A[i][j];
}
}

// Slack o'zgaruvchilarini ko'rsatkich jadvalida qo'shamiz


for (int i = 0; i < m; i++) {
table[i][n + i] = 1;
}

// Target funksiyasi ustunlarini ko'rsatkich jadvalida qo'shamiz


for (int j = 0; j < n; j++) {
table[m][j] = c[j];
}

// Ustunlar ustidan Qirg'izilgan qismi hisoblaymiz


for (int i = 0; i < m; i++) {
solution[n + i] = b[i];
}

// Negative target funksiyasi ustunlarini aniqlaymiz


int k = 0;
for (int j = 0; j < n; j++) {
if (c[j] < c[k]) {
k = j;
}
}

// Simpleks usulidan foydalanib yechimni topamiz


while (true) {
if (table[m][k] > -EPSILON) {
break;
}

int l = -1;


for (int i = 0; i < m; i++) {
if (table[i][k] < EPSILON) {
continue;
}
if (l == -1 || (solution[n + i
] / table[i][k] < solution[n + l] / table[l][k]) {
l = i;
}
}
if (l == -1) {
return false;
}

Download 47.94 Kb.

Do'stlaringiz bilan baham:




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