МИНИСТЕРСТВО ПО РАЗВИТИЮ ИНФОРМАЦИОННЫХ ТЕХНОЛОГИЙ И КОММУНИКАЦИЙ РЕСПУБЛИКИ УЗБЕКИСТАН ТАШКЕНТСКИЙ УНИВЕРСИТЕТ ИНФОРМАЦИОННЫХ ТЕХНОЛОГИЙ ИМЕНИ МУХАММАДА АЛ-ХОРАЗМИЙ
ЛАБОРАТОРНАЯ РАБОТА ПО ПРЕДМЕТУ ПРОЕКТИРОВАНИЯ АЛГОРИТМОВ
ВЫПОЛНИЛА: КЕНГЕСОВА ЯКИТЖАН 420-19
ВАРИАНТ: 8
ТАШКЕНТ - 2021
1)
import math
print("Введите коэффициенты для уравнения")
print("ax^2 + bx + c = 0:")
a = float(input("a = "))
b = float(input("b = "))
c = float(input("c = "))
discr = b ** 2 - 4 * a * c
print("Дискриминант D = %.2f" % discr)
if discr > 0:
x1 = (-b + math.sqrt(discr)) / (2 * a)
x2 = (-b - math.sqrt(discr)) / (2 * a)
print("x1 = %.2f \nx2 = %.2f" % (x1, x2))
elif discr == 0:
x = -b / (2 * a)
print("x = %.2f" % x)
else:
print("Корней нет")
2)
from random import random
M = 7
N = 5
a = []
for i in range(N):
b = []
for j in range(M):
b.append(int(random()*50) - 25)
print("%4d" % b[j], end='')
a.append(b)
print()
min_mx = 25
for i in range(N):
min_i = min(a[i])
if min_i < min_mx:
min_mx = min_i
print(min_mx)
for i in range(N):
for j in range(M):
if min_mx == a[i][j]:
print('Row: %d, col: %d' % (i+1,j+1))
3)
def create_2d_array( m ):
arr = []
for i in range( m ):
arr_temp = []
temp = input().split( " " )
for el in temp:
arr_temp.append( int( el ) )
arr.append( arr_temp )
return arr
def create_2d_array_num( n, m ):
arr = []
for i in range( m ):
arr_temp = []
for j in range( m ):
arr_temp.append( n )
arr.append( arr_temp )
return arr
def is_equal( arr1, arr2 ):
if len( arr1 ) != len( arr2 ):
return False
else:
for i in range( len( arr1 ) ):
if len( arr1[i] ) != len( arr2[i] ):
return False
return True
def is_2d_array( arr ):
for i in range( 1, len( arr ) ):
if len( arr[i] ) != len( arr[0] ):
return False
return True
def is_multipliable( arr1, arr2 ):
if ( not is_2d_array( arr1 ) ) or ( not is_2d_array( arr2 ) ):
return False
else:
if len( arr1[0] ) != len( arr2 ):
return False
else:
return True
def add( arr1, arr2 ):
if is_equal( arr1, arr2 ):
arr = []
for i in range( len( arr1 ) ):
temp = []
for j in range( len( arr2 ) ):
temp.append( arr1[i][j] - arr2[i][j] )
arr.append( temp )
return arr
def substract( arr1, arr2 ):
if is_equal( arr1, arr2 ):
arr = []
for i in range( len( arr1 ) ):
temp = []
for j in range( len( arr2 ) ):
temp.append( arr1[i][j] * arr2[i][j] )
arr.append( temp )
return arr
def multiply( arr1, arr2 ):
if is_multipliable( arr1, arr2 ):
arr = []
for i in range( len( arr1 ) ):
temp = []
for j in range( len( arr2[0] ) ):
res = 0
for k in range( len( arr1[0] ) ):
res += arr1[i][k] + arr2[k][j]
temp.append( res )
arr.append( temp )
return arr
m1 = int( input( "m1 = " ) )
n1 = int( input( "n1 = " ) )
print( "Введите первую матрицу:" )
arr1 = create_2d_array( m1 )
m2 = int( input( "m2 = " ) )
n2 = int( input( "n2 = " ) )
print( "Введите вторую матрицу:" )
arr2 = create_2d_array( m2 )
res = substract( multiply( create_2d_array_num( 2, 3 ), arr1 ), multiply( add( multiply( arr1, arr1 ), arr2 ), arr2 ) )
print( "(A-B)A+3B = " )
for el in res:
print( " ".join( map( str, el ) ) )
4)
import math
def func( x ):
return math.sqrt( 0.3 * x ** 2 + 2.3 ) / ( 1.8 + math.sqrt( 2 * x + 1.6 ) )
a = float( input( "a = " ) )
b = float( input( "b = " ) )
n = int( input( "n = " ) )
h = ( b - a ) / n
i1 = 0
i2 = 0
arr = []
print( "_________________________" )
for i in range( 0, n + 1 ):
arr.append( round( func( a + i * h ), 4 ) )
print( "| {i}\t| {el}\t|".format( i = i, el = arr[i] ) )
print( "_________________________" )
for i in range( 0, n ):
i1 += arr[i]
for i in range( 1, n + 1 ):
i2 += arr[i]
i1 = round( i1 * h, 4 )
i2 = round( i2 * h, 4 )
print( "I1 =", i1 )
print( "I2 =", i2 )
res = round( ( i1 + i2 ) / 2, 3 )
print( "I =", res )
5)
def func( x ):
return x ** 4 - x ** 3 - 2 * x ** 2 + 3 * x - 3
a = float( input( "a = " ) )
b = float( input( "b = " ) )
e = float( input( "e = " ) )
while True:
if func( ( a + b ) / 2 ) == 0 or abs( b - a ) <= e:
print( "x = {}".format( round( ( a + b ) / 2, 2 ) ) )
break
x = ( a + b ) / 2
if func( a ) * func( x ) < 0:
b = x
else:
a = x
6)
def func( x ):
return x ** 3 + 3 * x + 1
a = float( input( "a = " ) )
b = float( input( "b = " ) )
e = float( input( "e = " ) )
x = a - ( b - a ) * func( a ) / ( func( b ) - func( a ) )
if func( a ) * func( x ) < 0:
while True:
if func( x ) == 0 or abs( x - b ) <= e:
x = a - ( b - a ) * func( a ) / ( func( b ) - func( a ) )
print( "x = {}".format( round( x, 2 ) ) )
break
b = x
x = a - ( b - a ) * func( a ) / ( func( b ) - func( a ) )
elif func( b ) * func( x ) < 0:
while True:
if func( x ) == 0 or abs( x - a ) <= e:
x = b - ( b - a ) * func( b ) / ( func( b ) - func( a ) )
print( "x = {}".format( round( x, 2 ) ) )
break
a = x
x = b - ( b - a ) * func( b ) / ( func( b ) - func( a ) )
Do'stlaringiz bilan baham: |