ZHAWNotes/Notes/Semester 4/HM2 - Höhere Mathematik 2/Week 1/Miguel_S1_Aufg1.py

85 lines
1.9 KiB
Python

# %%
from numpy import pi, sin
import matplotlib.pyplot as plt
from IPython import get_ipython
def draw3D(x, y, z, title, xlabel, ylabel, zlabel):
fig = plt.figure()
surface = fig.add_subplot(projection="3d")
plot = surface.plot_surface(x, y, z, cmap="rainbow")
fig.colorbar(plot, shrink=0.5, aspect=5)
fig = plt.figure()
wireframe = fig.add_subplot(projection="3d")
wireframe.plot_wireframe(x, y, z)
for axes in [surface, wireframe]:
axes.set_title(title)
axes.set_xlabel(xlabel)
axes.set_ylabel(ylabel)
axes.set_zlabel(zlabel)
plt.show()
def drawContour(x, y, z, title, xlabel, ylabel):
fig = plt.figure()
axes = fig.add_subplot()
plot = axes.contour(x, y, z, cmap="rainbow")
fig.colorbar(plot, shrink=0.5, aspect=5)
axes.set_title(title)
axes.set_xlabel(xlabel)
axes.set_ylabel(ylabel)
plt.show()
def drawPlots(x, y, z, title, xlabel, ylabel, zlabel):
draw3D(x, y, z, title, xlabel, ylabel, zlabel)
drawContour(x, y, z, title, xlabel, ylabel)
# %%
g = 9.81
def W(v, a):
return ((v ** 2) * sin(a * 2)) / g
import numpy as np
[v, a] = np.meshgrid(np.linspace(0, 100), np.linspace(0, pi / 2))
z = W(v, a)
get_ipython().run_cell("%matplotlib widget")
drawPlots(v, a, z, "Wurfdistanz", "v_0", "alpha", "W")
# %%
R = 3.81
def calcP(V, T):
return (R * T) / V
def calcV(p, T):
return (R * T) / p
def calcT(p, V):
return (p * V) / R
# %%
[V, T] = np.meshgrid(np.linspace(0, 0.2), np.linspace(0, 10 ** 4))
p = calcP(V, T)
drawPlots(V, T, p, "Druck", "V", "T", "p")
# %%
[p, T] = np.meshgrid(np.linspace(10 ** 4, 10 ** 5), np.linspace(0, 10 ** 4))
V = calcV(p, T)
drawPlots(p, T, V, "Volumen", "p", "T", "V")
# %%
[p, V] = np.meshgrid(np.linspace(10 ** 4, 10 ** 6), np.linspace(0, 10))
T = calcT(p, V)
drawPlots(p, V, T, "Temperatur in K°", "p", "V", "T")
# %%