Muhammad al-xorazmiy nomidagi toshkent axborot texnologiyalari universiteti kompyuter injiniringi fakulteti algoritmlarni loyihalash fani bo



Yüklə 489,09 Kb.
tarix27.04.2023
ölçüsü489,09 Kb.
#103280

O’ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI


MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
KOMPYUTER INJINIRINGI FAKULTETI
ALGORITMLARNI LOYIHALASH FANI BO’YICHA BAJARGAN

Labaratoriya ishi.
Bajardi:Haydarov H.
Tekshirdi:Murodilloyeva Z.
TOSHKENT—2023
1-labaratoriya ishi.
Matritsalar ustida amallar.
Misol:

Kodi: Quyidagi kod python dasturlash tilida.


Import numpy as np

# A va B matritsalarni tasodifiy sonlar bilan to’ldirish
A = np.array([[5,3,-1],[2,0,4],[3,5,-1]])
B = np.array([[1,4,16],[-3,-2,0],[5,7,2]])

# (2(A-B)+AB) ni hisoblash


result = 2 * (A – B) + np.dot(A, B)

# Natijani ekranga chiqarish


print(“A matritsa:\n”, A)
print(“B matritsa:\n”, B)
print(“2(A-B)+AB:\n”, result)

Natija:



2-labaratoriya ishi.
1-topshiriq.

Kodi:
from scipy.integrate import quad

# integrallash kerak bo'lgan funksiya
def f(x):
return (pow((0.4*x+1.7),1/2))/(1.5*x+pow((x*x+1.3),1/2))

# oraliq a va b qiymatlari


a = 1.2
b = 2.6
n=10
h=(b-a)/n

y=a
s=0


for i in range(1,n+1):
y=a+i*h
s=s+2*f(y)
s=s*h/2
print(f"Natija:{s}")

Natija:



2-topshiriq.


Integralni trapetsiya usulida ishlash.

Kodi:
import math


def trapetsiya(f, a, b, n):
h = (b - a) / n
sum = 0.5 * (f(a) + f(b))
for i in range(1, n):
x_i = a + i * h
sum += f(x_i)
return h * sum

def f(x):


return 1/(pow((3*x*x-1),0.5))

# integrallash oraligi


a = 1.4
b = 2.1

# n
n = 10

# Trapetsiya formulasi yordamida integrallarni hisoblash
integral_value = trapetsiya(f, a, b, n)

# natijani chiqarish


print(f"Natija:{integral_value}")

Natija:

3-topshiriq.
Integralni Simpson usulida ishlash.

Kodi:
import math


def simpson(f, a, b, n):
h = (b - a) / n
s = f(a) + f(b)

for i in range(1, n, 2):


s += 4 * f(a + i * h)
for i in range(2, n-1, 2):
s += 2 * f(a + i * h)

return (h / 3) * s


def f(x):


return (math.log10(x*x+1))/x

# integrallash oraligi


a = 0.8
b = 1.6

# n
n = 10

# Simpson formulasi yordamida integrallarni hisoblash
integral_value = simpson(f, a, b, n)

# natijani chiqarish


print(f"Natija:{integral_value}")

Natija:



3-labaratoriya ishi.
Simpleks usuli.


Kodi:

import pulp

# Masalani yaratamiz


problem = pulp.LpProblem("Profit", pulp.LpMaximize)

# O'zgaruvchilarni yaratamiz


x1 = pulp.LpVariable('x1', lowBound=0, cat='Continuous')
x2 = pulp.LpVariable('x2', lowBound=0, cat='Continuous')
x3 = pulp.LpVariable('x3', lowBound=0, cat='Continuous')

# funksiyani qo'shamiz


problem += 7*x1 + 9*x2 - 5*x3

# Shartlarni qo'shamiz


problem += 2*x1 + 3*x2 + 4*x3 <= 8
problem += x1 + 2*x2 + x3 <= 5
problem += 6*x1 + 3*x2 + 5*x3 <= 15

# Masalani ishlaymiz


status = problem.solve()

# Natijalarni chiqaramiz


print("F(max): ", pulp.value(problem.objective))
print("x ning qiymatlari:")
for variable in problem.variables():
print(variable.name, " = ", variable.varValue)
Dastur natijasi:


import pulp

# Masalani yaratamiz


problem = pulp.LpProblem("Profit", pulp.LpMaximize)

# O'zgaruvchilarni yaratamiz


x1 = pulp.LpVariable('x1', lowBound=0, cat='Continuous')
x2 = pulp.LpVariable('x2', lowBound=0, cat='Continuous')

problem += 2*x1 - 3*x2

# Shartlarni qo'shamiz
problem += -x1 + 2*x2 <= 2
problem += -x1 + x2 >= -1
problem += x2 <= 2

status = problem.solve()



# Natijalarni chiqaramiz
print("F(max): ", pulp.value(problem.objective))
print("x ning qiymatlari:")
for variable in problem.variables():
print(variable.name, " = ", variable.varValue)
Natija:



Bajardi:Haydarov Hayotjon.


Yüklə 489,09 Kb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin