Files
haydenproject/AERO3220_HW4_block_diagram.md

188 lines
4.7 KiB
Markdown

# AERO3220 HW4 Program Flow Block Diagram
```mermaid
flowchart TD
A([Start Script]) --> B[Clear Workspace: clear, close all, clc]
B --> C[Set Parameters: k1, k2, m1, m2]
C --> D[Set Time Grid: t0, tf, dt, tspan]
D --> E[Set Initial State Vector x0 with 4 states]
E --> F[Define Input Force Functions: F1, F2, F3]
F --> G[Case 1: b=100, F=F1]
G --> H[Run ode45 with eom_two_mass]
H --> I[Case 2: b=100, F=F2]
I --> J[Run ode45 with eom_two_mass]
J --> K[Case 3: b=0, F=F2]
K --> L[Run ode45 with eom_two_mass]
L --> M[Case 4: b=100, F=F3]
M --> N[Run ode45 with eom_two_mass]
N --> O[Case 5: b=0, F=F3]
O --> P[Run ode45 with eom_two_mass]
P --> Q[Build Legend Strings]
Q --> R[Plot Figure 1: z1 vs time for 5 cases]
R --> S[Plot Figure 2: z2 vs time for 5 cases]
S --> T[Plot Figure 3: z1dot vs time for 5 cases]
T --> U[Plot Figure 4: z2dot vs time for 5 cases]
U --> V[Plot Figure 5: z1 and z2 together by case]
V --> W[Local Function eom_two_mass]
W --> X[Unpack States: z1, z1dot, z2, z2dot]
X --> Y[Evaluate Input u = Ffun of t]
Y --> Z[Compute Accelerations: z1ddot and z2ddot]
Z --> AA[Return State Derivative Vector dx with 4 elements]
AA --> AB([End])
```
## ODE Model Used in Each Case
\[
\ddot{z}_1 = -\frac{k_1}{m_1}z_1 + \frac{k_1}{m_1}z_2
\]
\[
\ddot{z}_2 = \frac{k_1}{m_2}z_1 - \frac{k_1+k_2}{m_2}z_2 - \frac{b}{m_2}\dot{z}_2 + \frac{1}{m_2}u(t)
\]
where \(u(t)\) is one of the three forcing functions depending on the case.
## System Equations Block Diagram
This is a dynamics block diagram of the coupled equations, not a program flowchart.
```mermaid
flowchart LR
U[Input force u] --> E2[Compute z2ddot from z1 z2 z2dot u and parameters]
E1[Compute z1ddot from z1 z2 and parameters] --> I1v[Integrate to z1dot]
I1v --> Z1D[State z1dot]
Z1D --> I1x[Integrate to z1]
I1x --> Z1[State z1]
E2 --> I2v[Integrate to z2dot]
I2v --> Z2D[State z2dot]
Z2D --> I2x[Integrate to z2]
I2x --> Z2[State z2]
Z1 --> E1
Z2 --> E1
Z1 --> E2
Z2 --> E2
Z2D --> E2
```
## Transfer Function Block Diagram Form
This version shows the same coupled dynamics using gain blocks and integrator transfer functions.
```mermaid
flowchart LR
Z1[State z1] --> G11[Gain -k1/m1]
G11 --> S1[Sum z1ddot]
Z2[State z2] --> G12[Gain +k1/m1]
G12 --> S1
S1 --> I11[Transfer block 1/s]
I11 --> Z1D[State z1dot]
Z1D --> I12[Transfer block 1/s]
I12 --> Z1
U[Input force u] --> G2U[Gain 1/m2]
G2U --> S2[Sum z2ddot]
Z1 --> G21[Gain k1/m2]
G21 --> S2
Z2 --> G22["Gain -(k1 + k2)/m2"]
G22 --> S2
Z2D[State z2dot] --> G23[Gain -b/m2]
G23 --> S2
S2 --> I21[Transfer block 1/s]
I21 --> Z2D
Z2D --> I22[Transfer block 1/s]
I22 --> Z2
```
Equivalent transfer relation notes:
\[
Z_1 = \frac{1}{s^2}\left(-\frac{k_1}{m_1} Z_1 + \frac{k_1}{m_1} Z_2\right)
\]
\[
Z_2 = \frac{1}{s^2}\left(\frac{k_1}{m_2} Z_1 - \frac{k_1+k_2}{m_2} Z_2 - \frac{b}{m_2} s Z_2 + \frac{1}{m_2} U\right)
\]
### Coupled State Space Form
Let
\[
x = \begin{bmatrix} z_1 \\ \dot{z}_1 \\ z_2 \\ \dot{z}_2 \end{bmatrix}
\]
then
\[
\dot{x} = A x + B u
\]
with
\[
A = \begin{bmatrix}
0 & 1 & 0 & 0 \\
-\frac{k_1}{m_1} & 0 & \frac{k_1}{m_1} & 0 \\
0 & 0 & 0 & 1 \\
\frac{k_1}{m_2} & 0 & -\frac{k_1+k_2}{m_2} & -\frac{b}{m_2}
\end{bmatrix},
\qquad
B = \begin{bmatrix}
0 \\
0 \\
0 \\
\frac{1}{m_2}
\end{bmatrix}
\]
## Assignment-Style Block Diagram (Recommended For Submission)
```mermaid
flowchart TD
A([Start]) --> B[Define constants and masses: k1, k2, m1, m2]
B --> C[Define simulation time: t0, tf, dt, tspan]
C --> D[Set initial state vector x0 with 4 states]
D --> E[Define force inputs F1 constant, F2 sine slow, F3 sine fast]
E --> F[Create case table with case b and force]
F --> G{i <= Number of Cases?}
G -- Yes --> H[Load case i values: b_i, F_i]
H --> I[Call ode45 with eom_two_mass and current case]
I --> J[Store outputs: t_i and x_i]
J --> K[i = i + 1]
K --> G
G -- No --> L[Generate legend labels]
L --> M[Plot z1 vs time for all cases]
M --> N[Plot z2 vs time for all cases]
N --> O[Plot z1dot vs time for all cases]
O --> P[Plot z2dot vs time for all cases]
P --> Q[Plot combined z1 and z2 by case]
Q --> R([End])
```
### Solver Subsystem (Inside `eom_two_mass`)
```mermaid
flowchart LR
A1[Inputs: t, x, m1, m2, k1, k2, b, Ffun] --> A2[Unpack states: z1, z1dot, z2, z2dot]
A2 --> A3[Compute input force u from Ffun and t]
A3 --> A4[Compute z1ddot from mass 1 equation]
A4 --> A5[Compute z2ddot from mass 2 equation]
A5 --> A6[Assemble derivative vector dx with 4 elements]
A6 --> A7[Return dx to ode45]
```