Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Implementering av Identitets-Kvadratiske Funksjoner i Python | Funksjoner og Deres Egenskaper
Matematikk for Datavitenskap

bookImplementering av Identitets-Kvadratiske Funksjoner i Python

Identitetsfunksjon

Identitetsfunksjonen returnerer inngangsverdien uendret, i henhold til formen f(x)=xf(x) = x. I Python implementeres den slik:

# Identity Function
def identity_function(x):
    return x

Identitetsfunksjonen returnerer inngangsverdien uendret, i henhold til formen f(x)=xf(x)=x. For å visualisere den genereres x-verdier fra -10 til 10, linjen plottes, origo (0,0)(0,0) markeres, og akser samt rutenett med etiketter inkluderes for tydelighet.

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

Konstant funksjon

En konstant funksjon gir alltid samme utgangsverdi, uavhengig av inngangsverdien. Den følger f(x)=cf(x) = c.

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

En konstant funksjon gir alltid samme utgangsverdi, uavhengig av inngangsverdien, og følger formen f(x)=cf(x) = c. For å visualisere dette genererer vi x-verdier fra -10 til 10 og tegner en horisontal linje ved y=5y = 5. Plottet inkluderer akser, etiketter og et rutenett for tydelighet.

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

Lineær funksjon

En lineær funksjon følger formen f(x)=mx+bf(x) = mx + b, der mm representerer stigningstallet og bb skjæringspunktet med y-aksen.

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

En lineær funksjon følger formen f(x)=mx+bf(x) = mx + b, der mm er stigningstallet og bb er skjæringspunktet med y-aksen. Vi genererer x-verdier fra -20 til 20 og plotter funksjonen med begge akser, et rutenett og markerte skjæringspunkter.

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

Kvadratisk funksjon

En kvadratisk funksjon følger f(x)=ax2+bx+cf(x) = ax^2 + bx + c, og danner en parabolsk kurve. Viktige egenskaper inkluderer toppunktet og x-interseptene.

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

En kvadratisk funksjon følger f(x)=ax2+bx+cf(x) = ax^2 + bx + c, og danner en parabolsk kurve. Vi genererer x-verdier fra -2 til 6, plotter funksjonen, og markerer toppunktet og skjæringspunktene. Plottet inkluderer begge akser, et rutenett og etiketter.

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

Hvilken kode definerer korrekt en kvadratisk funksjon i Python som beregner (f(x) = x^2 - 4x - 2)?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 5

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Awesome!

Completion rate improved to 1.96

bookImplementering av Identitets-Kvadratiske Funksjoner i Python

Sveip for å vise menyen

Identitetsfunksjon

Identitetsfunksjonen returnerer inngangsverdien uendret, i henhold til formen f(x)=xf(x) = x. I Python implementeres den slik:

# Identity Function
def identity_function(x):
    return x

Identitetsfunksjonen returnerer inngangsverdien uendret, i henhold til formen f(x)=xf(x)=x. For å visualisere den genereres x-verdier fra -10 til 10, linjen plottes, origo (0,0)(0,0) markeres, og akser samt rutenett med etiketter inkluderes for tydelighet.

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

Konstant funksjon

En konstant funksjon gir alltid samme utgangsverdi, uavhengig av inngangsverdien. Den følger f(x)=cf(x) = c.

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

En konstant funksjon gir alltid samme utgangsverdi, uavhengig av inngangsverdien, og følger formen f(x)=cf(x) = c. For å visualisere dette genererer vi x-verdier fra -10 til 10 og tegner en horisontal linje ved y=5y = 5. Plottet inkluderer akser, etiketter og et rutenett for tydelighet.

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

Lineær funksjon

En lineær funksjon følger formen f(x)=mx+bf(x) = mx + b, der mm representerer stigningstallet og bb skjæringspunktet med y-aksen.

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

En lineær funksjon følger formen f(x)=mx+bf(x) = mx + b, der mm er stigningstallet og bb er skjæringspunktet med y-aksen. Vi genererer x-verdier fra -20 til 20 og plotter funksjonen med begge akser, et rutenett og markerte skjæringspunkter.

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

Kvadratisk funksjon

En kvadratisk funksjon følger f(x)=ax2+bx+cf(x) = ax^2 + bx + c, og danner en parabolsk kurve. Viktige egenskaper inkluderer toppunktet og x-interseptene.

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

En kvadratisk funksjon følger f(x)=ax2+bx+cf(x) = ax^2 + bx + c, og danner en parabolsk kurve. Vi genererer x-verdier fra -2 til 6, plotter funksjonen, og markerer toppunktet og skjæringspunktene. Plottet inkluderer begge akser, et rutenett og etiketter.

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

Hvilken kode definerer korrekt en kvadratisk funksjon i Python som beregner (f(x) = x^2 - 4x - 2)?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 5
some-alt