Mustaqil ishi mavzu: Gauss usuli yordamida tenglamalar sistemasini yechish algoritmi Tekshirdi


Download 27.94 Kb.
bet2/2
Sana17.06.2023
Hajmi27.94 Kb.
#1541294
1   2
Bog'liq
Gauss usuli

Yechish. Birinchi tenglamani ketma – ket 1,3,2 sonlarga ko`paytirib, so`ngra ikkinchi, uchinchi va to`rtinchi tenglamalardan birinchi tenglamani ayirsak,
π‘₯1 + 2π‘₯2 βˆ’ 3π‘₯3 + 5π‘₯4 = 1
{ π‘₯2 βˆ’ 10π‘₯3 + 17π‘₯4 = βˆ’2
βˆ’π‘₯2 + 10π‘₯3 βˆ’ 17π‘₯4 = 2
βˆ’π‘₯2 + 10π‘₯3 βˆ’ 17π‘₯4 = 2
sistemaga ega bo`lamiz.
Endi ikkinchi tenglamani uchinchi va to`rtinchi tenglamalarga qo`shib, natijada quyidagi sistemani hosil qilamiz:
π‘₯1 + 2π‘₯2 βˆ’ 3π‘₯3 + 5π‘₯4 = 1
{ π‘₯2 βˆ’ 10π‘₯3 + 17π‘₯4 = βˆ’2
0 = 0
0 = 0
Oxirgi ikkita tenglama
0 βˆ™ π‘₯1 + 0 βˆ™ π‘₯2 + 0 βˆ™ π‘₯3 + 0 βˆ™ π‘₯4 = 0
ko`rinishdagi tenglama bo`lib, u noma’lumning har qanday qiymatida ham o`rinli bo`lgani uchun uni tashlab yuboramiz.
Ikkinchi tenglamani qanoatlantiradigan noma`lumning qiymatini topsh uchun π‘₯3 va π‘₯4 larga ixtiyoriy qiymatlarni beramiz. Masalan, π‘₯3 = 𝛼, π‘₯4 = 𝛽 bo`lsin, u holda π‘₯2 = 10𝛼 βˆ’ 17𝛽 βˆ’ 2 bo`ladi. Bu π‘₯2, π‘₯3, π‘₯4 larning qiymatlarini birinchi tenglamaga qo`yib π‘₯1 = βˆ’17𝛼 + 29𝛽 + 5 ni topamiz. Sistemaning yechimi
π‘₯1 = βˆ’17𝛼 + 29𝛽 + 5;
π‘₯2 = 10𝛼 βˆ’ 17𝛽 βˆ’ 2; π‘₯3 = 𝛼; π‘₯4 = 𝛽
bo`lib 𝛼 va 𝛽 ning ixtiyoriy qiymatlarida berilgan sistemaning hamma yechimlarini beradi.
6 – misol. Quyidagi chiziqli tenglamalar sistemasini Gauss usuli bilan yeching:
π‘₯1 + π‘₯2 βˆ’ 3π‘₯3 = 7
{2π‘₯1 + 3π‘₯2 + π‘₯3 = 1
2π‘₯1 βˆ’ π‘₯2 + 2π‘₯3 = 6
Yechish. Birinchi tenglamaning barcha hadlarini 2 ga ko`paytirib, undan ikkinchi va uchinchi tenglamalarni ayiramiz. Natijada quyidagi ko`rinishdagi sistemaga ega bo`lamiz:
π‘₯1 + π‘₯2 βˆ’ 3π‘₯3 = 7
{ βˆ’π‘₯2 βˆ’ 7π‘₯3 = 13
3π‘₯2 βˆ’ 8π‘₯3 = 8
Ikkinchi va uchinchi tenglamalar faqat π‘₯2 va π‘₯3 nomalumlarga ega. Ikkinchi tenglamaning hadlarini 3 ga ko`paytirib, uchinchi tenglamaga qo`shamiz. Natijada quyidagi sistema hosil bo`ladi:
π‘₯1 + π‘₯2 βˆ’ 3π‘₯3 = 7
{ βˆ’π‘₯2 βˆ’ 7π‘₯3 = 13
βˆ’π‘₯3 = 13
Uchinchi tenglamadan: π‘₯3 = βˆ’13, buni ikkinchi tenglamaga qo`yib π‘₯2 noma`lumni topamiz:
βˆ’π‘₯2 βˆ’ 7 βˆ™ (βˆ’13) = 13,
π‘₯2 = 78
π‘₯3 va π‘₯2 noma’lumlarning qiymatlarini birinchi tenglamaga qo`yib π‘₯1 noma’lumni topamiz.
π‘₯1 + 78 βˆ’ 3 βˆ™ (βˆ’13) = 7, π‘₯1 = βˆ’110
Javob: (-110, 78, -13)

Gauss usulining C# dasturlash tizimida ko’rinishi



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace Equations_Solver
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}


private void button1_Click(object sender, EventArgs e)
{
textBox2.Clear();
double[][] rows = new double[textBox1.Lines.Length][];
for (int i = 0; i < rows.Length; i++)
{
rows[i] = (double[])Array.ConvertAll(textBox1.Lines[i].Split(' '), double.Parse);
}


int length = rows[0].Length;
for (int i = 0; i < rows.Length - 1; i++)
{
for (int j = i; j < rows.Length; j++)
{
double[] d = new double[length];
for (int x = 0; x < length; x++)
{
if (i == j && rows[j][i] == 0)
{
bool changed = false;
for (int z = rows.Length - 1; z > i; z--)
{
if (rows[z][i] != 0)
{
double[] temp = new double[length];
temp = rows[z];
rows[z] = rows[j];
rows[j] = temp;
changed = true;
}
}
if (!changed)
{
textBox2.Text += "No Solution\r\n";
return;
}
}
if (rows[j][i] != 0)
{
d[x] = rows[j][x] / rows[j][i];
}
else
{
d[x] = rows[j][x];
}
}
rows[j] = d;
}
for (int y = i + 1; y < rows.Length; y++)
{
double[] f = new double[length];
for (int g = 0; g < length; g++)
{
if (rows[y][i] != 0)
{
f[g] = rows[y][g] - rows[i][g];
}
else
{
f[g] = rows[y][g];
}
}
rows[y] = f;
}
}
double val = 0;
int k = length - 2;
double[] result = new double[rows.Length];
for (int i = rows.Length - 1; i >= 0; i--)
{
val = rows[i][length - 1];
for (int x = length - 2; x > k; x--)
{
val -= rows[i][x] * result[x];
}
result[i] = val / rows[i][i];
if (result[i].ToString() == "NaN" || result[i].ToString().Contains("Infinity"))
{
textBox2.Text += "No Solution Found!\n";
return;
}
k--;
}
for (int i = 0; i < result.Length; i++)
{
textBox2.Text += string.Format("X{0} = {1}\r\n", i + 1, Math.Round(result[i], 10));
}
}
}
}
Download 27.94 Kb.

Do'stlaringiz bilan baham:
1   2




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