Files
haydenproject/AERO3220_HW4_block_diagram.md
2026-04-04 17:47:19 -05:00

2.8 KiB

AERO3220 HW4 Program Flow Block Diagram

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: x0 = (z1, z1dot, z2, z2dot)^T]
    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 (5 cases)]
    R --> S[Plot Figure 2: z2 vs time (5 cases)]
    S --> T[Plot Figure 3: z1dot vs time (5 cases)]
    T --> U[Plot Figure 4: z2dot vs time (5 cases)]
    U --> V[Plot Figure 5: z1 and z2 together by case]

    V --> W[Local Function: eom_two_mass(t,x,...)]
    W --> X[Unpack States: z1, z1dot, z2, z2dot]
    X --> Y[Evaluate Input: u = Ffun(t)]
    Y --> Z[Compute Accelerations: z1ddot and z2ddot]
    Z --> AA[Return State Derivative: dx = (z1dot, z1ddot, z2dot, z2ddot)^T]
    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.

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 = (z1, z1dot, z2, z2dot)^T]
    D --> E[Define force inputs: F1=100, F2=100sin(0.25t), F3=100sin(0.50t)]

    E --> F[Create case table: (Case, b, 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)

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 = Ffun(t)]
    A3 --> A4[Compute z1ddot from mass 1 equation]
    A4 --> A5[Compute z2ddot from mass 2 equation]
    A5 --> A6[Assemble derivative: dx = (z1dot, z1ddot, z2dot, z2ddot)^T]
    A6 --> A7[Return dx to ode45]