Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Реалізація Тотожних і Квадратичних Функцій у Python | Функції та Їх Властивості
Математика для науки про дані

bookРеалізація Тотожних і Квадратичних Функцій у Python

Функція тотожності

Функція тотожності повертає вхідне значення без змін, має вигляд f(x)=xf(x) = x. У Python її можна реалізувати так:

# Identity Function
def identity_function(x):
    return x

Функція тотожності повертає вхідне значення без змін, має вигляд f(x)=xf(x)=x. Для її візуалізації генеруються x-значення від -10 до 10, будується пряма, позначається початок координат (0,0)(0,0), а також додаються підписані осі та сітка для наочності.

12345678910111213141516171819202122232425
import numpy as np import matplotlib.pyplot as plt # Identity Function def identity_function(x): return x x = np.linspace(-10, 10, 100) y = identity_function(x) plt.plot(x, y, label="f(x) = x", color='blue', linewidth=2) plt.scatter(0, 0, color='red', zorder=5) # Mark the origin # Add axes plt.axhline(0, color='black', linewidth=1) plt.axvline(0, color='black', linewidth=1) # Add labels plt.xlabel("x") plt.ylabel("f(x)") # Add grid plt.grid(True, linestyle='--', alpha=0.6) plt.legend() plt.title("Identity Function: f(x) = x") plt.show()
copy

Константна функція

Константна функція завжди повертає одне й те саме значення незалежно від вхідного аргументу. Вона має вигляд f(x)=cf(x) = c.

# Constant Function
def constant_function(x, c):
    return np.full_like(x, c)

Константна функція завжди повертає одне й те саме значення незалежно від вхідного аргументу, має вигляд f(x)=cf(x) = c. Для візуалізації генеруємо x-значення від -10 до 10 та будуємо горизонтальну лінію при y=5y = 5. Графік містить осі, підписи та сітку для наочності.

123456789101112131415161718
import numpy as np import matplotlib.pyplot as plt def constant_function(x, c): return np.full_like(x, c) x = np.linspace(-10, 10, 100) y = constant_function(x, c=5) plt.plot(x, y, label="f(x) = 5", color='blue', linewidth=2) plt.axhline(0, color='black', linewidth=1) plt.axvline(0, color='black', linewidth=1) plt.xlabel("x") plt.ylabel("f(x)") plt.grid(True, linestyle='--', alpha=0.6) plt.legend() plt.title("Constant Function: f(x) = 5") plt.show()
copy

Лінійна функція

Лінійна функція має вигляд f(x)=mx+bf(x) = mx + b, де mm — це кутовий коефіцієнт, а bb — ордината початку.

# Linear Function
def linear_function(x, m, b):
    return m * x + b

Лінійна функція має вигляд f(x)=mx+bf(x) = mx + b, де mm — це кутовий коефіцієнт, а bb — ордината початку. Генеруємо значення x від -20 до 20 та будуємо графік функції з обома осями, сіткою та позначеними точками перетину з осями.

1234567891011121314151617181920
import numpy as np import matplotlib.pyplot as plt def linear_function(x, m, b): return m * x + b x = np.linspace(-20, 20, 400) y = linear_function(x, m=2, b=-5) plt.plot(x, y, color='blue', linewidth=2, label="f(x) = 2x - 5") plt.scatter(0, -5, color='red', label="Y-Intercept") plt.scatter(2.5, 0, color='green', label="X-Intercept") plt.axhline(0, color='black', linewidth=1) plt.axvline(0, color='black', linewidth=1) plt.xlabel("x") plt.ylabel("f(x)") plt.grid(True, linestyle='--', alpha=0.6) plt.legend() plt.title("Linear Function: f(x) = 2x - 5") plt.show()
copy

Квадратична функція

Квадратична функція має вигляд f(x)=ax2+bx+cf(x) = ax^2 + bx + c, утворюючи параболічну криву. Основні характеристики включають вершину та x-перетини.

# Quadratic Function
def quadratic_function(x):
    return x**2 - 4*x - 2

Квадратична функція має вигляд f(x)=ax2+bx+cf(x) = ax^2 + bx + c, утворюючи параболічну криву. Генеруємо x-значення від -2 до 6, будуємо графік функції та позначаємо вершину й точки перетину з осями. На графіку присутні обидві осі, сітка та підписи.

12345678910111213141516171819202122232425
import numpy as np import matplotlib.pyplot as plt def quadratic_function(x): return x**2 - 4*x - 2 x = np.linspace(-2, 6, 200) y = quadratic_function(x) plt.plot(x, y, color='blue', linewidth=2, label="f(x) = x² - 4x - 2") plt.scatter(2, quadratic_function(2), color='red', label="Vertex (2, -6)") plt.scatter(0, quadratic_function(0), color='green', label="Y-Intercept (0, -2)") # X-intercepts from quadratic formula x1, x2 = (4 + np.sqrt(24)) / 2, (4 - np.sqrt(24)) / 2 plt.scatter([x1, x2], [0, 0], color='orange', label="X-Intercepts") plt.axhline(0, color='black', linewidth=1) plt.axvline(0, color='black', linewidth=1) plt.xlabel("x") plt.ylabel("f(x)") plt.grid(True, linestyle='--', alpha=0.6) plt.legend() plt.title("Quadratic Function: f(x) = x² - 4x - 2") plt.show()
copy
question mark

Який код правильно визначає квадратичну функцію в Python, що обчислює (f(x) = x^2 - 4x - 2)?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 5

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Suggested prompts:

Can you explain how to interpret the graphs for each function?

What are the key differences between the identity, constant, linear, and quadratic functions?

Can you help me modify one of these functions for a different example?

Awesome!

Completion rate improved to 1.96

bookРеалізація Тотожних і Квадратичних Функцій у Python

Свайпніть щоб показати меню

Функція тотожності

Функція тотожності повертає вхідне значення без змін, має вигляд f(x)=xf(x) = x. У Python її можна реалізувати так:

# Identity Function
def identity_function(x):
    return x

Функція тотожності повертає вхідне значення без змін, має вигляд f(x)=xf(x)=x. Для її візуалізації генеруються x-значення від -10 до 10, будується пряма, позначається початок координат (0,0)(0,0), а також додаються підписані осі та сітка для наочності.

12345678910111213141516171819202122232425
import numpy as np import matplotlib.pyplot as plt # Identity Function def identity_function(x): return x x = np.linspace(-10, 10, 100) y = identity_function(x) plt.plot(x, y, label="f(x) = x", color='blue', linewidth=2) plt.scatter(0, 0, color='red', zorder=5) # Mark the origin # Add axes plt.axhline(0, color='black', linewidth=1) plt.axvline(0, color='black', linewidth=1) # Add labels plt.xlabel("x") plt.ylabel("f(x)") # Add grid plt.grid(True, linestyle='--', alpha=0.6) plt.legend() plt.title("Identity Function: f(x) = x") plt.show()
copy

Константна функція

Константна функція завжди повертає одне й те саме значення незалежно від вхідного аргументу. Вона має вигляд f(x)=cf(x) = c.

# Constant Function
def constant_function(x, c):
    return np.full_like(x, c)

Константна функція завжди повертає одне й те саме значення незалежно від вхідного аргументу, має вигляд f(x)=cf(x) = c. Для візуалізації генеруємо x-значення від -10 до 10 та будуємо горизонтальну лінію при y=5y = 5. Графік містить осі, підписи та сітку для наочності.

123456789101112131415161718
import numpy as np import matplotlib.pyplot as plt def constant_function(x, c): return np.full_like(x, c) x = np.linspace(-10, 10, 100) y = constant_function(x, c=5) plt.plot(x, y, label="f(x) = 5", color='blue', linewidth=2) plt.axhline(0, color='black', linewidth=1) plt.axvline(0, color='black', linewidth=1) plt.xlabel("x") plt.ylabel("f(x)") plt.grid(True, linestyle='--', alpha=0.6) plt.legend() plt.title("Constant Function: f(x) = 5") plt.show()
copy

Лінійна функція

Лінійна функція має вигляд f(x)=mx+bf(x) = mx + b, де mm — це кутовий коефіцієнт, а bb — ордината початку.

# Linear Function
def linear_function(x, m, b):
    return m * x + b

Лінійна функція має вигляд f(x)=mx+bf(x) = mx + b, де mm — це кутовий коефіцієнт, а bb — ордината початку. Генеруємо значення x від -20 до 20 та будуємо графік функції з обома осями, сіткою та позначеними точками перетину з осями.

1234567891011121314151617181920
import numpy as np import matplotlib.pyplot as plt def linear_function(x, m, b): return m * x + b x = np.linspace(-20, 20, 400) y = linear_function(x, m=2, b=-5) plt.plot(x, y, color='blue', linewidth=2, label="f(x) = 2x - 5") plt.scatter(0, -5, color='red', label="Y-Intercept") plt.scatter(2.5, 0, color='green', label="X-Intercept") plt.axhline(0, color='black', linewidth=1) plt.axvline(0, color='black', linewidth=1) plt.xlabel("x") plt.ylabel("f(x)") plt.grid(True, linestyle='--', alpha=0.6) plt.legend() plt.title("Linear Function: f(x) = 2x - 5") plt.show()
copy

Квадратична функція

Квадратична функція має вигляд f(x)=ax2+bx+cf(x) = ax^2 + bx + c, утворюючи параболічну криву. Основні характеристики включають вершину та x-перетини.

# Quadratic Function
def quadratic_function(x):
    return x**2 - 4*x - 2

Квадратична функція має вигляд f(x)=ax2+bx+cf(x) = ax^2 + bx + c, утворюючи параболічну криву. Генеруємо x-значення від -2 до 6, будуємо графік функції та позначаємо вершину й точки перетину з осями. На графіку присутні обидві осі, сітка та підписи.

12345678910111213141516171819202122232425
import numpy as np import matplotlib.pyplot as plt def quadratic_function(x): return x**2 - 4*x - 2 x = np.linspace(-2, 6, 200) y = quadratic_function(x) plt.plot(x, y, color='blue', linewidth=2, label="f(x) = x² - 4x - 2") plt.scatter(2, quadratic_function(2), color='red', label="Vertex (2, -6)") plt.scatter(0, quadratic_function(0), color='green', label="Y-Intercept (0, -2)") # X-intercepts from quadratic formula x1, x2 = (4 + np.sqrt(24)) / 2, (4 - np.sqrt(24)) / 2 plt.scatter([x1, x2], [0, 0], color='orange', label="X-Intercepts") plt.axhline(0, color='black', linewidth=1) plt.axvline(0, color='black', linewidth=1) plt.xlabel("x") plt.ylabel("f(x)") plt.grid(True, linestyle='--', alpha=0.6) plt.legend() plt.title("Quadratic Function: f(x) = x² - 4x - 2") plt.show()
copy
question mark

Який код правильно визначає квадратичну функцію в Python, що обчислює (f(x) = x^2 - 4x - 2)?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 5
some-alt