typst/schule/mathe/tests/test.ipynb

237 lines
11 KiB
Text
Raw Permalink Normal View History

2024-11-18 12:13:17 +01:00
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sympy"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAgMAAAGFCAYAAABg2vAPAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAKuUlEQVR4nO3dT4iV9R7H8e+55sqTgX8ClWAkqVChhS4UEVyICobWwqiFQS4UUWgTCjo0R/yDmxbiQhCTwZ0xrhTdhJOEYojRKmylIjjgH1RKQxw8d3FpwquXnJzT8fZ5veBsfueZ5/n+zmJ4n/MMZxrtdrtdAECsf3V7AACgu8QAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBM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fvpFjrl69WocOHarvv/++pkyZUs1ms5rNZn333XfPPGe73a7h4eEnHu12+5nro7Fp06a6f//+U+/2n2cPf9eMQAe1gY45fPhwu6raEyZMaH/44Yft4eHhFzrf4OBgu6qe63H58uXnOmdvb2+7qtr79+8fkz2M9Yw3b95sV1W7r6/vufYDjF53PpOEEG+99VZV/eceeH9/f40bN+6Fzjdv3ry6cOHCE2sbNmyo6dOnV19f3xPr06dP/9Pz7dixo3bt2lW7d++uzZs3P/OY0e5hrGcEOk8MQIf8+OOP9d5779WiRYvq7Nmzdfjw4dq0adMLnfPVV1+t+fPnP7U2efLkp9b/zI4dO6rValWr1apt27Y985i/soexnBH4e/ibAeiAn3/+uZYvX14LFy6swcHBWr16dbVarbp37163R6uqqp07d1ar1are3t6n3q3/7mXfAzB2xACMsStXrtTSpUvr7bffrmPHjtX48eNr7969defOndqzZ0+3x6svv/yyvvjii1qxYkWtXLmyzp8//8Sj6uXYw6lTp2pgYKCOHz9eVVU//fRTDQwM1MDAgP/dAGPMlw7BGBoaGqrFixfXa6+9VoODgzVx4sSR59avX19HjhypS5cuVU9Pz5hdc7Rf6LNkyZI6c+bM/3z++vXrY76H0c5YVdXT01NXr1595nOXL18e09cQ0okBAAjnNgEAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABBODABAODEAAOHEAACEEwMAEE4MAEA4MQAA4cQAAIQTAwAQTgwAQDgxAADhxAAAhBMDABDu3/AkdJMFQJALAAAAAElFTkSuQmCC",
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"from sympy import symbols, latex\n",
"\n",
"x = symbols('x')\n",
"expr = x**2 + 2*x + 1\n",
"\n",
"# LaTeX-String erstellen\n",
"latex_code = latex(expr)\n",
"\n",
"# Plot erstellen\n",
"plt.text(0.5, 0.5, f\"${latex_code}$\", fontsize=12, ha='center')\n",
"plt.axis('off')\n",
"plt.show()\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"x^{2} + 2 x + 1\n"
]
}
],
"source": [
"from sympy import symbols, latex\n",
"\n",
"x = symbols('x')\n",
"expr = x**2 + 2*x + 1\n",
"\n",
"# LaTeX-String erzeugen\n",
"latex_code = latex(expr)\n",
"print(latex_code)\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3 x^{2} + 2\n",
"\\frac{x^{4}}{4} + x^{2} + x\n"
]
}
],
"source": [
"from sympy import diff, integrate, symbols, latex\n",
"\n",
"x = symbols('x')\n",
"f = x**3 + 2*x + 1\n",
"\n",
"# Ableitung\n",
"derivative = diff(f)\n",
"print(latex(derivative)) # Ausgabe: 3 x^{2} + 2\n",
"\n",
"# Integral\n",
"integral = integrate(f)\n",
"print(latex(integral)) # Ausgabe: \\frac{x^{4}}{4} + x^{2} + x\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"3 x^{2} + 2\n",
"\\frac{x^{4}}{4} + x^{2} + x\n",
"$$"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-2\n",
"2\n"
]
}
],
"source": [
"from sympy import solve\n",
"\n",
"eq = x**2 - 4\n",
"solution = solve(eq)\n",
"\n",
"# Lösungen anzeigen\n",
"for sol in solution:\n",
" print(latex(sol)) # Ausgabe: -2 und 2\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAEsAAAAUCAYAAADFlsDIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAABJ0AAASdAHeZh94AAACB0lEQVR4nO3YvWsVQRTG4SeawlJQsLAQOwvjfyBEAoIIgko6NVoLIWAhCHJyBMFGxUoLIWksrSSijSbYCYKgiApCsFBR0UII4lcs7r26Jjfxfmw2V/BtZnZmmN/Zd2dnd07f/Py8/2pNa1Y7gH9J/Y1KZg7ibqHvWURsqzqg1VZmbsS7YltE9FEwq6AZTON9yUFswH7sxQA24wseYQITEfGjTGaH3DlkvX4UWxodzcyajojxsoPGMC7jtdoKfolNOICr2JOZwxFR9ibaFjci5jDOr7dtWbNWSs+xD1PFJ5mZp3AfB9Vu4HqvciszKyLuLNH+JjOv4CwGlWxWmdxe+Rp+rZffepm76mZlZj+O1C9v9TJ31c3COWzHzYi43cvclveszJxV+DK0oGsRcegvc47iBJ7icBtzd6VOue1s8C/wuY3xr5brzMzjuIQnGIqID23M3bG64bZsVkQMdRBbU2XmGC7isVrAb8uaeyW5le9ZmXlSLeCH2FWhUV1zq/wplZmncQYPsLuVVyAzJzGCYxExWRW3mSozKzNH1AL+jnsYzcyFw2abGNJY/R39g3XBXaQqV9bWerkWY0uMmcHkgrYBfMJUxdxFqvK4M65+QG1VmbkeO3A+Ij5WxV1KzcyKzAy9kc/aqXYkuVAVsFk+q6GiWbN+53EoOZ/ViSLiBtZVjC3ms/7QTx5045MkGXPbAAAAAElFTkSuQmCC",
"text/latex": [
"$\\displaystyle \\left[ -2, \\ 2\\right]$"
],
"text/plain": [
"[-2, 2]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from sympy import symbols, solve, init_printing\n",
"from IPython.display import display\n",
"\n",
"# SymPy-Darstellung aktivieren\n",
"init_printing()\n",
"\n",
"x = symbols('x')\n",
"eq = x**2 - 4\n",
"\n",
"# Gleichung lösen und anzeigen\n",
"solutions = solve(eq)\n",
"display(solutions)\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ableitung von f(x) = exp(0.5*x):\n",
"0.5*exp(0.5*x)\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAEwAAAAUCAYAAAAnStuxAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90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1968MGVGNHd6mIyBbpPZyRmT9jHCYq4Q7nVPv/UnXibWzf0qEp5zalWHWnw8RKTpM2qhedv8M23dCPqn83HVZH0Nq6x1otvuXF7YrD9mnQRlTjMctYO6+fsvuNpsM+qsYhPfDWVaSnHNcp6oozkCVJdwOlGOzbz73/djRzWF0lRmRmu6FdE3viV6Uz7g92r8bZ1Vgfs/X7ue8/giWOiYjPlGvFFjirxZdKRNzT7MEyc3BmDsvMVbswZ27X7Jwb9EG4pXq9r5L7q9JubJuZh3enZGbuVbUdKxztpD8ar+KmzDwAHyqVaT/lKF7S4n9OuS9uqTS8NY7ERZk5HZ/jJwzGIVhDKdvN69F4PImpmfms4sCVsKlyX1w1Ipb1BeIfQZejV0XZzrhbcdQ4xdCbsHtEfNvhvtPxiOLIY5WvCvviZaX5PDQiFjbk1hfmqUr7MUa5722DZ5W77b8CA/7/4to3/Kc/IK4I/AXg3nrQh3yL0AAAAABJRU5ErkJggg==",
"text/latex": [
"$\\displaystyle 0.5 e^{0.5 x}$"
],
"text/plain": [
" 0.5⋅x\n",
"0.5⋅ℯ "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from sympy import symbols, diff, exp, init_printing\n",
"from IPython.display import display\n",
"init_printing()\n",
"\n",
"# Symbol für die Variable x definieren\n",
"x = symbols('x')\n",
"\n",
"# Funktion definieren: f(x) = e^(0.5x)\n",
"f = exp(0.5 * x)\n",
"\n",
"# Ableitung berechnen\n",
"f_derivative = diff(f, x)\n",
"\n",
"# Ergebnis anzeigen\n",
"print(f\"Ableitung von f(x) = {f}:\")\n",
"print(f_derivative)\n",
"display(f_derivative)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python (Nix)",
"language": "python",
"name": "nix-python"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}