• 2-topshiriq.
  • Guruh talabasi Sobirov Ixlosbek Algoritmni loyihalash 3-amaliy topshiriq




    Download 15,83 Kb.
    Sana15.05.2024
    Hajmi15,83 Kb.
    #234233
    Bog'liq
    Sobirov Ixlosbek Algoritm loyihalash 3-amaliy topshiriq 1


    310-22-guruh talabasi Sobirov Ixlosbek
    Algoritmni loyihalash 3-amaliy topshiriq


    1. topshiriq.Chiziqli dasturlash masalasi yechimi asosida xulosa va iqtisodiy tavsiyalar ishlab chiqish. Matematik model asosida iqtisodiy masala tuzishga namunalar.

    Ushbu mavzular Python dasturlash tilida yozilgan.
    import numpy as np
    import matplotlib.pyplot as plt
    x = np.array([1, 2, 3, 4, 5])
    y = np.array([2, 3, 5, 4, 6])
    coefficients = np.polyfit(x, y, 1) # 1- darajali (lineyka) model
    model = np.poly1d(coefficients)
    plt.scatter(x, y, color='blue', label='Ma`lumotlar') # Ma'lumotlarni tasvir qilish
    plt.plot(x, model(x), color='red', label='Model') # Modelni tasvir qilish
    plt.xlabel('X o`lchami')
    plt.ylabel('Y o`lchami')
    plt.title('Masala Yechish')
    plt.legend()
    plt.show()
    mse = np.mean((model(x) - y) ** 2) # O`xshashlik yig`indisi (MSE) ni hisoblash
    print("Mean Squared Error:", mse)

    2-topshiriq. Jadval funksiya Fur`e qatoriga yoyish. Fur`e koeffisientlarini hisoblash. Qator hadlari sonini tanlash. Taqribiy integrallash formulasini tanlash, aniqligini baholash. Fur`e qatori asosida raqamli signallar yetakchi garmonikalarini aniqlash.
    import numpy as np
    import scipy.integrate as spi

    def furier_series(func, interval, n_terms):
    coefficients = []
    for n in range(n_terms):
    f_cos = lambda x: func(x) * np.cos(2 * np.pi * n * x / interval)
    f_sin = lambda x: func(x) * np.sin(2 * np.pi * n * x / interval)
    a_n = 2 * spi.quad(f_cos, 0, interval)[0] / interval
    b_n = 2 * spi.quad(f_sin, 0, interval)[0] / interval
    coefficients.append((a_n, b_n))
    return coefficients

    def find_series_length(coefficients, threshold=1e-10):
    series_length = len(coefficients)
    for i, (a_n, b_n) in enumerate(coefficients[::-1]):
    if np.abs(a_n) < threshold and np.abs(b_n) < threshold:
    series_length -= 1
    else:
    break
    return series_length

    def evaluate_integration_accuracy(func, interval, n_terms):
    def find_harmonics(furier_coefficients, threshold=1e-10):
    harmonics = []
    for i, (a_n, b_n) in enumerate(furier_coefficients):
    if np.abs(a_n) > threshold or np.abs(b_n) > threshold:
    harmonics.append((i, a_n, b_n))
    return harmonics
    def test_function(x):
    return np.sin(x) + np.sin(2 * x) + np.cos(3 * x)

    n_terms = 10
    coefficients = furier_series(test_function, 2 * np.pi, n_terms)
    series_length = find_series_length(coefficients)
    print("Qator Hadlari Soni:", series_length)
    evaluate_integration_accuracy(test_function, 2 * np.pi, n_terms)
    harmonics = find_harmonics(coefficients)
    print("Yetakchi Garmonikalar:")
    for i, a_n, b_n in harmonics:
    print(f"Garmonika {i + 1}: a_n = {a_n}, b_n = {b_n}")


    1. topshiriq. Axborotlar oqimini segmentlarga ajratish. dinamik dasturlash. chiziqli model. jarayon matematik modelini tuzishda eng kichik kvadratlar usulidan foydalanish.


    import numpy as np
    def segmentize(data, n_segments):
    segment_length = len(data) // n_segments
    segments = [data[i * segment_length : (i + 1) * segment_length] for i in range(n_segments)]
    return segments
    def linear_least_squares(x, y):
    n = len(x)
    sum_x = np.sum(x)
    sum_y = np.sum(y)
    sum_xy = np.sum(x * y)
    sum_x_squared = np.sum(x**2)
    slope = (n * sum_xy - sum_x * sum_y) / (n * sum_x_squared - sum_x**2)
    intercept = (sum_y - slope * sum_x) / n

    return slope, intercept
    def least_squares_method(data):
    n = len(data)
    x = np.arange(n)
    y = np.array(data)
    slope, intercept = linear_least_squares(x, y)
    model = slope * x + intercept
    residuals = y - model
    RSS = np.sum(residuals**2)
    return slope, intercept, model, RSS
    data = [10, 15, 20, 30, 40, 45, 50, 55, 60]
    segments = segmentize(data, 3)
    for i, segment in enumerate(segments):
    slope, intercept, model, RSS = least_squares_method(segment)
    print(f"Segment {i + 1}: Slope={slope}, Intercept={intercept}, RSS={RSS}")
    Download 15,83 Kb.




    Download 15,83 Kb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Guruh talabasi Sobirov Ixlosbek Algoritmni loyihalash 3-amaliy topshiriq

    Download 15,83 Kb.