master > master: src - für notebook wk10

This commit is contained in:
RD 2022-12-15 07:05:50 +01:00
parent 0384334ce0
commit 847e7744ff
5 changed files with 69 additions and 5 deletions

View File

@ -6,6 +6,7 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from src.maths.diagrams.sets import *;
from src.maths.diagrams.signal import *;
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# EXPORTS
@ -14,4 +15,5 @@ from src.maths.diagrams.sets import *;
__all__ = [
'Function',
'Functions',
'display_signal',
];

View File

@ -0,0 +1,48 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# IMPORTS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from __future__ import annotations;
from src.thirdparty.code import *;
from src.thirdparty.types import *;
from src.thirdparty.maths import *;
from src.thirdparty.plots import *;
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# EXPORTS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__all__ = [
'display_signal',
];
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# CONSTANTS / VARIABLES
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def display_signal(
u: np.ndarray,
title: str,
max_labels = 10,
):
n = len(u);
if n <= max_labels:
x_axis = list(range(n));
else:
skip = int(n/max_labels);
x_axis = [ k*skip for k in range(max_labels) ];
fig, axs = mplot.subplots(1, 1, constrained_layout=True);
mplot.title(title);
mplot.xlabel('»Zeit« [=Indizes]');
mplot.ylabel('Werte [=Einträge]');
axs.stem(linspace(0,n-1,n), np.real(u), label='reeller Teil', linefmt='red');
axs.stem(linspace(0,n-1,n) + 0.05, np.imag(u), label='imaginärer Teil', linefmt='lime');
mplot.legend();
axs.set_xticks(x_axis, labels=[ str(index) for index in x_axis]);
mplot.show();
return;

View File

@ -6,10 +6,17 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from fractions import Fraction;
from numpy import cos;
from numpy import exp;
from numpy import linalg;
from numpy import linspace;
from numpy import pi;
from numpy import sin;
from numpy import sqrt;
from typing import TypeVar;
import math;
import numpy as np;
import random;
from typing import TypeVar;
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# MODIFICATIONS
@ -39,8 +46,15 @@ def sample(
__all__ = [
'Fraction',
'cos',
'exp',
'linalg',
'linspace',
'math',
'np',
'pi',
'random',
'sample',
'sin',
'sqrt',
];

View File

@ -19,11 +19,11 @@ from qiskit.visualization import array_to_latex;
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__all__ = [
'Latex',
'array_to_latex',
'display',
'display_latex',
'display_markdown',
'display_png',
'display',
'Latex',
'widgets',
];

View File

@ -38,8 +38,8 @@ from typing import Generic;
from typing import Optional;
from typing import Type;
from typing import TypeVar;
from typing_extensions import Concatenate;
from typing_extensions import ParamSpec;
from typing import Concatenate;
from typing import ParamSpec;
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# EXPORTS