187 lines
3.9 KiB
Plaintext
187 lines
3.9 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 5,
|
||
"id": "2a1f4fb4-1e20-4441-90f2-98ce7606e088",
|
||
"metadata": {
|
||
"slideshow": {
|
||
"slide_type": "skip"
|
||
},
|
||
"tags": [
|
||
"hide-input"
|
||
]
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"import math"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "c4e44c9e-0eea-48d3-b478-8723995efe97",
|
||
"metadata": {},
|
||
"source": [
|
||
"# Hilfe\n",
|
||
"\n",
|
||
"Hilfe kann man sich für Packages oder Funktionen anzeigen lassen:\n",
|
||
"\n",
|
||
"`help(math)`\n",
|
||
"\n",
|
||
"`help(math.sin)`"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 6,
|
||
"id": "18821bb6-e5a7-4367-ac55-60c468d78a02",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"Help on built-in function sin in module math:\n",
|
||
"\n",
|
||
"sin(x, /)\n",
|
||
" Return the sine of x (measured in radians).\n",
|
||
"\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"help(math.sin)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "bf381088-a36b-400d-8a8e-9491c85ee637",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"source": [
|
||
"Das **/** ist kein Parameter sondern eine Info für fortgeschrittene Programmierer ([Details](https://www.python.org/dev/peps/pep-0570/positional-only%20parameters)). Wir ignorieren dies.\n",
|
||
"\n",
|
||
"ℹ️ `<TAB>` zeigt verfügbare Funktionen an. Probiert:\n",
|
||
"\n",
|
||
"`math.<TAB>`\n",
|
||
"\n",
|
||
"`math.c<TAB>`"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "2d4ee0f4-7d02-4935-bfd9-9c04efb7de4d",
|
||
"metadata": {},
|
||
"source": [
|
||
"## Aufgabe\n",
|
||
"\n",
|
||
"❓ Berechne sin und cos von 0°, 90° und 180°!"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "d89f4342-623b-4b6e-be90-e6774c62a65f",
|
||
"metadata": {},
|
||
"source": [
|
||
"## Lösung\n",
|
||
"\n",
|
||
"War das Ergebnis richtig?\n",
|
||
"\n",
|
||
"Die Hilfe sagt, dass man den Parameter von `sin`/`cos` in Radians (Bogenmaß) angeben muss. Gegeben waren aber Grad. D.h. wir müssen dies erst umrechnen. Dazu gibt es auch eine Funktion `math.radians()`. Somit wäre die Lösung:"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 9,
|
||
"id": "0e612c09-f8b5-4dc2-80c7-49f03e510937",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"1.0"
|
||
]
|
||
},
|
||
"execution_count": 9,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"math.sin(math.radians(90))"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "89d942ed-7aac-48d7-ba5e-2d1c0e09a2d3",
|
||
"metadata": {},
|
||
"source": [
|
||
"ℹ️ Funktionen sind schachtelbar\n",
|
||
"\n",
|
||
"ℹ️ Ein Programm besteht aus ineinander geschachtelten Funktionsaufrufen."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 10,
|
||
"id": "3197696b-bf76-46b7-99db-67ad482516ca",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"1.2246467991473532e-16"
|
||
]
|
||
},
|
||
"execution_count": 10,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"math.sin(math.radians(180))"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "c5b2d7d1-d7e4-4372-933c-19063452d1dd",
|
||
"metadata": {},
|
||
"source": [
|
||
"Mmh, das sollte 0 sein.\n",
|
||
"\n",
|
||
"ℹ️ Beim Rechnen mit Kommazahlen ist die Genauigkeit begrenzt."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "0923f3a5-8e2e-4044-a316-598da598f3db",
|
||
"metadata": {},
|
||
"source": [
|
||
"❓ Was wäre, wenn es `math.radians()` nicht geben würde?"
|
||
]
|
||
}
|
||
],
|
||
"metadata": {
|
||
"kernelspec": {
|
||
"display_name": "Python 3 (ipykernel)",
|
||
"language": "python",
|
||
"name": "python3"
|
||
},
|
||
"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.9.7"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 5
|
||
}
|