"## 1.1 Plotting task: representation of geometric shapes\n",
"\n",
"### Aim\n",
"The aim of this task is to plot various geometric shapes using Python and Matplotlib\n",
"\n",
"#### Requirements\n",
"\n",
"- Use `matplotlib.pyplot` to plot the functions. Each function group should have a different color.\n",
"- **Plot settings**:\n",
" - Add a grid to make orientation easier.\n",
" - Add a title “Students face”\n",
" - Add a legend that identifies the individual function groups."
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "cba143bf",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"# Funktionsgruppe 1\n",
"t = np.linspace(0, 2*np.pi, 100)\n",
"x_1 = 5 * np.cos(t)\n",
"y_1 = 5 * np.sin(t)\n",
"\n",
"# Funktionsgruppe 2\n",
"x_2 = 2 * np.cos(t) - 2\n",
"y_2 = 2 * np.sin(t) + 2\n",
"\n",
"# Funktionsgruppe 3\n",
"x_3 = 2 * np.cos(t) + 2\n",
"y_3 = 2 * np.sin(t) + 2\n",
"\n",
"# Funktionsgruppe 4\n",
"t2 = np.linspace(0, np.pi, 100)\n",
"x_4 = 3 * np.cos(t2)\n",
"y_4 = 3 * np.sin(t2 + np.pi ) - 0.5"
]
},
{
"cell_type": "markdown",
"id": "68f742ed",
"metadata": {},
"source": [
"## 1.2 Plotting data and style it\n",
"\n",
"### 1. Generate Data with NumPy:\n",
"- Given is a Function that generates a sinus with random noise\n",
" $$\n",
" y = \\sin(t) + \\text{random noise}\n",
" $$\n",
"\n",
"### 2. Create the Plot:\n",
"- Plot the time series as a solid line.\n",
"- Highlight the actual measurement points with circles.\n",
"\n",
"### 3. Plot Styling:\n",
"- Add axis titles for time (`x-axis`) and measurement values (`y-axis`).\n",
"- Add a plot title.\n",
"- Differentiate the markers by using a distinct color and a large size."
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "bf165039",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# 1. Generate data\n",
"t = np.linspace(0, 10, 11) # Timevalues\n",
"y = np.sin(t) + np.random.normal(0, 0.1, len(t)) # Sinus values with noise\n",
"\n",
"# 2. Generateplot\n"
]
},
{
"cell_type": "markdown",
"id": "ff1d99ae",
"metadata": {},
"source": [
"## 1.2 Plot task: Damped oscillation of a resonant circuit\n",
"\n",
"#### Aim\n",
"The aim of this task is to graphically represent the natural oscillation of a damped oscillating circuit. The oscillation is described by a mathematical function that represents the change in amplitude over time as a function of time.\n",
"\n",
"#### Function to be plotted\n",
"\n",
"The oscillation is described by the following function:\n",
"$$\n",
"a(t) = a_0 e^{-t/\\tau} \\cos(2\\pi f_n t + \\phi)\n",
"$$\n",
"given are:\n",
"- $a_0 = 5$ the amplitude\n",
"- $\\tau = 0.2$ s the time constant of the attenuation\n",
"- $f_n = 10$ Hz the frequency of the resonant circuit\n",
"- $\\phi = -\\pi/2$ the phase shift\n",
"## Task definition\n",
"\n",
"\n",
"\n",
"1 **Visualize the function**:\n",
"\n",
" - Create a plot of the function \\( a(t) \\) over a period of 0 to 1 second.\n",
" - Make sure that the x-axis shows the time in seconds and the y-axis shows the amplitude.\n",
" \n",
"2 **Adjust the plot settings**:\n",
"\n",
" - Label the x-axis and y-axis appropriately.\n",
" - Add an appropriate legend to clearly identify the data being plotted.\n",
" - Add a grid to improve the readability of the plot.\n"
## 1.1 Plotting task: representation of geometric shapes
### Aim
The aim of this task is to plot various geometric shapes using Python and Matplotlib
#### Requirements
- Use `matplotlib.pyplot` to plot the functions. Each function group should have a different color.
-**Plot settings**:
- Add a grid to make orientation easier.
- Add a title “Students face”
- Add a legend that identifies the individual function groups.
%% Cell type:code id:cba143bf tags:
``` python
importnumpyasnp
# Funktionsgruppe 1
t=np.linspace(0,2*np.pi,100)
x_1=5*np.cos(t)
y_1=5*np.sin(t)
# Funktionsgruppe 2
x_2=2*np.cos(t)-2
y_2=2*np.sin(t)+2
# Funktionsgruppe 3
x_3=2*np.cos(t)+2
y_3=2*np.sin(t)+2
# Funktionsgruppe 4
t2=np.linspace(0,np.pi,100)
x_4=3*np.cos(t2)
y_4=3*np.sin(t2+np.pi)-0.5
```
%% Cell type:markdown id:68f742ed tags:
## 1.2 Plotting data and style it
### 1. Generate Data with NumPy:
- Given is a Function that generates a sinus with random noise
$$
y = \sin(t) + \text{random noise}
$$
### 2. Create the Plot:
- Plot the time series as a solid line.
- Highlight the actual measurement points with circles.
### 3. Plot Styling:
- Add axis titles for time (`x-axis`) and measurement values (`y-axis`).
- Add a plot title.
- Differentiate the markers by using a distinct color and a large size.
%% Cell type:code id:bf165039 tags:
``` python
importnumpyasnp
importmatplotlib.pyplotasplt
# 1. Generate data
t=np.linspace(0,10,11)# Timevalues
y=np.sin(t)+np.random.normal(0,0.1,len(t))# Sinus values with noise
# 2. Generateplot
```
%% Cell type:markdown id:ff1d99ae tags:
## 1.2 Plot task: Damped oscillation of a resonant circuit
#### Aim
The aim of this task is to graphically represent the natural oscillation of a damped oscillating circuit. The oscillation is described by a mathematical function that represents the change in amplitude over time as a function of time.
#### Function to be plotted
The oscillation is described by the following function:
$$
a(t) = a_0 e^{-t/\tau} \cos(2\pi f_n t + \phi)
$$
given are:
- $a_0 = 5$ the amplitude
- $\tau = 0.2$ s the time constant of the attenuation
- $f_n = 10$ Hz the frequency of the resonant circuit
- $\phi = -\pi/2$ the phase shift
## Task definition
1 **Visualize the function**:
- Create a plot of the function \( a(t) \) over a period of 0 to 1 second.
- Make sure that the x-axis shows the time in seconds and the y-axis shows the amplitude.
2 **Adjust the plot settings**:
- Label the x-axis and y-axis appropriately.
- Add an appropriate legend to clearly identify the data being plotted.
- Add a grid to improve the readability of the plot.