Beispiel #1
0
def calculate_integral(function_number, nodes_number):
    result, currentWeight, currentNode = 0, 0, 0
    for i in range(1, nodes_number + 1):
        currentWeight = np.pi / nodes_number
        currentNode = -np.cos(((2 * i - 1) * np.pi) / (2 * nodes_number))
        result += currentWeight * get_function_value(currentNode,
                                                     function_number)
    return result
def calculate_integral(function_number, nodes_number, polynomial_degree):
    result, currentWeight, currentNode = 0.0, None, None
    for i in range(1, nodes_number + 1):
        currentWeight = np.pi / nodes_number
        currentNode = -np.cos(((2 * i - 1) * np.pi) / (2 * nodes_number))
        result += currentWeight * get_function_value(currentNode, function_number) * \
                  czebyszew_aproximation(polynomial_degree, currentNode, function_number)
    return result
Beispiel #3
0
def data_load():
    print("""
Wybierz numer funkcji ktorej chcesz uzyc w programie:
    1. FUNKCJA LINIOWA: x - 3
    2. FUNKCJA: |x|
    3. FUNKCJA WIELOMIANOWA:  2 * x^3 + 1 * x^2 - 3 * x + 7
    4. FUNKCJA TRYGONOMETRYCZNA:  4 * cos(x) + 6 * sin(x)
    5. FUNKCJA ZŁOŻONA:  |sin(x + 2) - 1.6|""")
    function_number = int(input("""
Wybór: """))
    while function_number not in [1, 2, 3, 4, 5]:
        valid_number = False
        while not valid_number:
            function_number = int(input("""
                Wybierz jeszcze raz numer funkcji: """))
            if function_number in [1, 2, 3, 4, 5]:
                valid_number = True

    left_border = float(input("""
Podaj lewa granice przedziału interpolacji: """))
    right_border = float(input("""Podaj prawa granice przedziału interpolacji: """))

    nodes_number = int(input("""
Podaj liczbę węzłów interpolacji: """))
    while nodes_number < 1:
        print("Podaj liczbę węzłów interpolacji większą od 1!")
        nodes_number = int(input("""
Podaj liczbę węzłów interpolacji: """))

    function_arguments = list(np.linspace(left_border, right_border, 1000))

    function_values = []
    for x in function_arguments:
        function_values.append(get_function_value(x, function_number))

    interpolation_arguments = np.linspace(left_border, right_border, nodes_number)
    interpolation_values = list(get_function_value(interpolation_arguments, function_number))
    interpolation_arguments = list(interpolation_arguments)

    polynomial_values = calculations(function_arguments, interpolation_arguments, interpolation_values)

    presentation(function_arguments, function_values, polynomial_values, function_number, interpolation_arguments,
                 interpolation_values)
Beispiel #4
0
def calculations(function_number, left_border, right_border, polynomial_degree,
                 nodes_number):
    segment = 100
    epsilon = 0.0
    current_x = 0
    current_y = 0
    approximated_arguments = []
    approximated_values = []

    for i in range(0, segment):
        current_x = left_border + 1.0 * i / segment * (right_border -
                                                       left_border)
        current_y = calculate_aproximation(current_x, function_number,
                                           nodes_number, polynomial_degree)
        approximated_arguments.append(current_x)
        approximated_values.append(current_y)
        epsilon = epsilon + abs(
            get_function_value(current_x, function_number) - current_y)
    epsilon /= 100

    return [epsilon, approximated_arguments, approximated_values]
def calculate_function_and_weight_product(argument, function_number):
    return get_function_value(
        argument, function_number) * (1 / sqrt(1 - argument * argument))
Beispiel #6
0
def data_load():

    # Numer funkcji
    print("""
Wybierz numer funkcji ktorej chcesz uzyc w programie:
    1. FUNKCJA LINIOWA: x - 3
    2. FUNKCJA: |x|
    3. FUNKCJA WIELOMIANOWA:  2 * x^3 + 1 * x^2 - 3 * x + 7
    4. FUNKCJA TRYGONOMETRYCZNA:  4 * cos(x) + 6 * sin(x)
    5. FUNKCJA ZŁOŻONA:  |sin(x + 2) - 1.6|""")
    function_number = int(input("""
Wybór: """))
    while function_number not in [1, 2, 3, 4, 5]:
        valid_number = False
        while not valid_number:
            function_number = int(
                input("""
Wybierz jeszcze raz numer funkcji: """))
            if function_number in [1, 2, 3, 4, 5]:
                valid_number = True

    # Przedział aproksymacji
    left_border = float(
        input("""
Podaj lewa granice przedziału aproksymacji: """))
    right_border = float(
        input("""Podaj prawa granice przedziału aproksymacji: """))

    # Stopień wielomianu aproksymujacego
    polynomial_degree = int(
        input("""
Podaj stopien wielomianu aproksymacji: """))
    while polynomial_degree < 1:
        print("Podaj stopień wielomianu większy od 0!")
        polynomial_degree = int(
            input("""
Podaj stopien wielomianu aproksymacji: """))

    # Liczba wezlow dla metody calkowania Gaussa-Czebyszewa
    nodes_number = int(
        input("""
Podaj liczbe wezlow dla metody calkowania (Gauss-Czebyszew): """))
    while nodes_number < 0:
        print("Podaj liczbe wezlow wieksza od 0!")
        nodes_number = int(
            input("""
Podaj liczbe wezlow dla metody calkowania (Gauss-Czebyszew): """))

    function_arguments = list(np.linspace(left_border, right_border, 1000))

    function_values = []
    for x in function_arguments:
        function_values.append(get_function_value(x, function_number))

    calculated_values = calculations(function_number, left_border,
                                     right_border, polynomial_degree,
                                     nodes_number)

    print()
    print("------------------------------------------------")
    print("Blad aproksymacji wynosi:", calculated_values[0])
    print("------------------------------------------------")
    print()

    generate_graph(function_arguments, function_values, function_number,
                   calculated_values[1], calculated_values[2])