1-amaliy ishi # O'quvchilar soni list shaklida berilgan students = [20, 25, 30, 15, 10]


Download 489.29 Kb.
Sana09.04.2023
Hajmi489.29 Kb.
#1345921
Bog'liq
saidikrom Algoritmlar


Samarqand filiali Kompyuter injenering fakulteti ATS yo’nalishi 21-08 guruh talabasi Choriyev Saidikromning Algoritmlarni loyihalsh fanidan bajargan
1-amaliy ishi

# O'quvchilar soni list shaklida berilgan
students = [20, 25, 30, 15, 10]


# Parta yetishini hisoblash uchun funksiya yaratamiz
def count_desks(students):
desks = 0
for s in students:
desks += s // 2 + s % 2 # har bir sinf uchun parta soni hisoblanadi
return desks


# Natijani chop etamiz
print("Parta soni:", count_desks(students))





# Matritsa
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]


# Matritsani vertikalga nisbatan ko'chirish
def vertical_flip(matrix):
for row in matrix:
row.reverse() # Har bir qatorni teskari tartibda qo'yamiz
return matrix


# Matritsaning eski holati
print("Eski matritsa:")
for row in matrix:
print(row)


# Matritsaning yangi holati
print("Yangi matritsa:")
for row in vertical_flip(matrix):
print(row)



# Ikki matritsani ulash orqali katta matritsa hosil qilish
def merge_matrices(matrix1, matrix2):
n = len(matrix1)
merged_matrix = []
for i in range(n):
merged_matrix.append(matrix1[i] + matrix2[i])
return merged_matrix


# Matritsalar
matrix1 = [[1, 2], [3, 4]]
matrix2 = [[5, 6], [7, 8]]


# Katta matritsa
merged_matrix = merge_matrices(matrix1, matrix2)


# Katta matritsaning natijasi
for row in merged_matrix:
print(row)



from scipy.integrate import quad
import math


# integrand funksiya
def integrand(x):
return (5 + x ** 2) * math.sin(x)


# Integralni yechish
result, error = quad(integrand, -2, 2)


# Natijani chiqarish
print(f"Integral natijasi: {result}")



# Funksiya
def f(x):
return math.sin(x) / ((x 3 + x 2) 0.25) - 3 * math.cos(x)


# Boshlang'ich taxmin
x0 = 1


# Taxmin qilish
epsilon = 1e-6
while True:
# Funksiya qiymatini hisoblash
fx0 = f(x0)
# Taxmin x yangilash
x1 = x0 - fx0 / (math.cos(x0) / ((x0 3 + x0 2) 0.25) - 3 * math.sin(x0) / (4 * (x0 3 + x0 2) ** 1.5))
# Taxmin o'zgaruvchisini hisoblash
delta_x = abs(x1 - x0)
# Taxminni yangilash
x0 = x1
# Taxmin kriteriyasini tekshirish
if delta_x < epsilon:
break


# Natijani chiqarish
print(f"tenglama yechimi natijasi: {x0}")



Nyutonda
# Funksiyani aniqlash
def f(x):
return x 3 - 3 * x 2 + 2 * x - 4


# Funksiyani differensiyalashgan funksiya
def df(x):
return 3 * x ** 2 - 6 * x + 2


# Boshlang'ich taxmin
x0 = 1.5


# Taxmin qilish
epsilon = 1e-6
while True:
# Funksiyani qiymatini hisoblash
fx0 = f(x0)
# Differensiyalangan funksiyani qiymatini hisoblash
dfx0 = df(x0)
# Yangi taxminni hisoblash
x1 = x0 - fx0 / dfx0
# Taxmin o'zgaruvchisini hisoblash
delta_x = abs(x1 - x0)
# Taxminni yangilash
x0 = x1
# Taxmin kriteriyasini tekshirish
if delta_x < epsilon:
break


# Natijani chiqarish
print(f"nyuton usuli yordamida tenglama yechimi natijasi: {x0}")


Vatarda:
# Funksiyani aniqlash
def f(x):
return x 3 - 3 * x 2 + 2 * x - 4


# Boshlang'ich taxmin
x0 = 1.5


# Taxmin qilish
epsilon = 1e-6
while True:
# Funksiyani qiymatini hisoblash
fx0 = f(x0)
# Yangi taxminni hisoblash
x1 = x0 - fx0 * (x0 - 1.5) / (f(x0 - fx0) - fx0)
# Taxmin o'zgaruvchisini hisoblash
delta_x = abs(x1 - x0)
# Taxminni yangilash
x0 = x1
# Taxmin kriteriyasini tekshirish
if delta_x < epsilon:
break


# Natijani chiqarish
print(f"vatarlar usuli yordamida tenglama yechimi natijasi: {x0}")
Download 489.29 Kb.

Do'stlaringiz bilan baham:




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