Files
Komplexe-Zahlen/Komplexe_Zahlen.ipynb
2026-02-17 07:29:38 +01:00

74 lines
1.5 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"id": "initial_id",
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2026-02-17T06:10:37.823863Z",
"start_time": "2026-02-17T06:10:37.590164Z"
}
},
"source": [
"def abs(c):\n",
" return (c.real**2 + c.imag**2)**0.5\n",
"\n",
"def add(c1, c2):\n",
" return complex(c1.real + c2.real, c1.imag + c2.imag)\n",
"\n",
"def sub(c1, c2):\n",
" # (a+bi) - (c+di) = (a-c) + (b-d)i\n",
" return complex(c1.real - c2.real, c1.imag - c2.imag)\n",
"\n",
"def mul(c1, c2):\n",
" # (a+bi)(c+di) = (ac-bd) + (ad+bc)i\n",
" return complex(c1.real * c2.real - c1.imag * c2.imag, c1.real * c2.imag + c1.imag * c2.real)\n",
"\n",
"\n",
"\n",
"print(mul(1+2j, 2+1j))"
],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5j\n"
]
}
],
"execution_count": 1
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": "",
"id": "9169fa196cc5ca5d"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}