44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
"""
|
|
Einleitendes Beispiel:
|
|
|
|
(Implizite) Graphische Darstellung f1(x1,x2) = 0 und f2(x1,x2) = 0
|
|
mit Hilfe eines Hoehenlinien-Plots (sog. Contour-Plots)
|
|
"""
|
|
|
|
|
|
# Definition der Funktionen f1, f2 : R^2 -> R
|
|
def f1(x1,x2):
|
|
return x1**2 + x2 - 11
|
|
|
|
def f2(x1,x2):
|
|
return x1 + x2**2 - 7
|
|
|
|
"""
|
|
(Implizite) Graphische Darstellung f1(x1,x2) = 0 und f2(x1,x2) = 0
|
|
mit Hilfe eines Hoehenlinien-Plots (sog. Contour-Plots), wobei
|
|
nur die "Nullline" dargestellt wird.
|
|
|
|
Dazu wird in folgenden Schritten vorgegangen:
|
|
"""
|
|
|
|
# 1. Erstellen eines 2d-Gitters in der x1,x2-Ebene mit Hifle von
|
|
# numpy.meshgrid (s. numpy-Doku)
|
|
|
|
import numpy as np
|
|
|
|
x1 = np.linspace(-6,6) # aequidistante Stuetzstellen in x1-Richtung
|
|
x2 = np.linspace(-5,12) # aequidistante Stuetzstellen in x2-Richtung
|
|
x1, x2 = np.meshgrid(x1,x2) # 2d-Gitter von Stuetzstellen
|
|
|
|
# 2. Berechnen der Funktionswerte an den Stuetzstellen
|
|
z1 = f1(x1,x2)
|
|
z2 = f2(x1,x2)
|
|
|
|
# 3. Erstellen des Countour-Plots (s. matplotlib-Doku)
|
|
import matplotlib.pyplot as plt
|
|
|
|
plt.contour(x1,x2,z1,levels=[0])
|
|
plt.contour(x1,x2,z2,levels=[0])
|
|
plt.xlabel('x1')
|
|
plt.ylabel('x2')
|
|
plt.show() |