Monday, May 4, 2026

Taylor Series(Math) in Robot Legs and Prosthetic Design

 


One of the most common real-world uses of Taylor series is in robotics and prosthetic leg control.A robot leg or a prosthetic knee behaves like a pendulum. The equation that describes its motion is nonlinear because it contains the term sin(θ), where θ is the angle of the leg. Solving or controlling nonlinear equations in real time is computationally expensive and difficult.Engineers apply Taylor series linearization around the operating point (usually θ ≈ 0):

                                                            sin(θ)θ  (First-order Taylor approximation)







This small change turns the complex nonlinear system into a linear system. Linear systems are much easier to analyze and control.Why This Matters in Practice
  • Simpler Controller Design: Engineers can use well-established linear control methods such as PID, LQR, or pole placement.
  • Real-time Performance: The simplified model runs faster on embedded microcontrollers inside prosthetic legs.
  • Stability Analysis: Linear models make it easier to guarantee the leg won’t become unstable while walking.
Real devices that use this idea:
  • Advanced prosthetic knees (e.g., Össur, Ottobock)
  • Humanoid robots and quadruped robots (like Boston Dynamics’ Spot)
  • Exoskeletons for rehabilitation
For small angles (typically under 15–20°), the approximation is very accurate. For larger movements, engineers either use higher-order Taylor terms or switch to nonlinear control techniques.
Taylor Series in Computational Fluid Dynamics (CFD)Taylor series also plays a fundamental role in Computational Fluid Dynamics — the science of simulating how air, water, and other fluids move.Most CFD methods (Finite Difference, Finite Volume) rely on Taylor series to estimate derivatives. For example, to calculate how fast velocity changes at a point, engineers expand the function using Taylor series and then truncate higher-order terms to create simple numerical approximations.This technique allows computers to solve the complex Navier-Stokes equations on a mesh of millions of small cells. Without Taylor-based discretization, accurate fluid simulation would be nearly impossible on current hardware.Applications include:
  • Aerodynamic design of cars, aircraft, and drones
  • Simulation of blood flow in medical devices
  • Weather prediction and turbomachinery (turbines, pumps)


Python Code by Grok

import numpy as np
import matplotlib.pyplot as plt

# Parameters
g = 9.81      # gravity
L = 0.8       # leg length (meters)
dt = 0.01     # time step
t_max = 10
t = np.arange(0, t_max, dt)

# Target angle (20 degrees)
target_deg = 20
target = np.deg2rad(target_deg)

# PD Controller gains
Kp = 25
Kd = 8

def simulate_pendulum(use_linear=False):
    theta = np.zeros_like(t)
    omega = np.zeros_like(t)
    
    for i in range(1, len(t)):
        if use_linear:
            torque = Kp * (target - theta[i-1]) - Kd * omega[i-1]
            alpha = torque - (g/L) * theta[i-1]   # Linear: sinθ ≈ θ
        else:
            torque = Kp * (target - theta[i-1]) - Kd * omega[i-1]
            alpha = torque - (g/L) * np.sin(theta[i-1])  # Real nonlinear
        
        omega[i] = omega[i-1] + alpha * dt
        theta[i] = theta[i-1] + omega[i] * dt
    
    return np.rad2deg(theta)

# Run both simulations
theta_nonlinear = simulate_pendulum(use_linear=False)
theta_linear    = simulate_pendulum(use_linear=True)

# Plot results
plt.figure(figsize=(12, 7))

plt.plot(t, theta_nonlinear, 'b-', linewidth=2, label='Real Robot Leg (Nonlinear)')
plt.plot(t, theta_linear, 'r--', linewidth=2, label='Linearized Model (Taylor sinθ≈θ)')
plt.axhline(y=target_deg, color='green', linestyle='--', label=f'Target = {target_deg}°')

plt.title('PD Controller on Robot Leg\nWith and Without Taylor Linearization', fontsize=14)
plt.xlabel('Time (seconds)')
plt.ylabel('Leg Angle (degrees)')
plt.legend()
plt.grid(True)
plt.ylim(0, 45)

plt.show()

# Performance comparison
final_error_non = abs(theta_nonlinear[-1] - target_deg)
final_error_lin = abs(theta_linear[-1] - target_deg)

print(f"Final Error - Real Model     : {final_error_non:.2f} degrees")
print(f"Final Error - Linear Model   : {final_error_lin:.2f} degrees")

Saturday, May 2, 2026

Ashby Plot Analysis: Young's Modulus vs Density – A Guide to Smart Material Selection


                                                                Figure 1


    An Ashby plot is one of the most powerful visualization tools in materials engineering. By plotting Young’s Modulus (stiffness) against Density (mass per volume) on logarithmic scales, we can quickly compare how different materials perform when both rigidity and weight matter.In the plot above, we compare five specific alloys:
  • Magnesium Alloy AZ91E-T6
  • Semi-red Brass C84200
  • Tin Bronze C91100
  • Copper Alloy C19200
  • JIS SUH35 (a heat-resistant stainless steel)
Key Insights:
  • Density significantly affects the specific stiffness (E/ρ) of a material. Materials that sit higher and more to the left on the chart offer better stiffness per unit weight.
  • Magnesium Alloy AZ91E-T6 typically shows the lowest density among the group. This makes it attractive for applications where weight saving is critical (e.g., automotive, aerospace, or portable electronics), even if its absolute stiffness is lower than steels or copper alloys.
  • Copper-based alloys (Semi-red Brass, Tin Bronze, and Copper Alloy C19200) generally have higher density but also respectable Young’s Modulus. They are preferred when high corrosion resistance, thermal conductivity, or wear resistance is needed alongside moderate stiffness.
  • JIS SUH35 (a stainless steel variant) likely sits in the higher stiffness and higher density region, making it suitable for high-temperature or high-strength applications where weight is less critical.
Engineering Takeaway:When designing a component, engineers rarely look for the “strongest” or “stiffest” material in absolute terms. Instead, they optimize for performance indices such as E/ρ (for tension-loaded lightweight stiff structures) or E^{1/3}/ρ (for bending stiffness with minimum weight).
  • If your design is weight-sensitive → favor materials toward the top-left (like magnesium alloys).
  • If your design requires high absolute stiffness and can tolerate higher weight → copper alloys or steels become more competitive.
  • Trade-offs always exist: lower density materials often come with lower absolute strength, higher cost, or processing challenges.
This Ashby plot helps visualize these trade-offs at a glance, enabling faster and more informed material selection during the early design stage.

    An Ashby plot is one of the most powerful visualization tools in materials engineering. By plotting Young’s Modulus (stiffness) against Density (mass per volume) on logarithmic scales, we can quickly compare how different materials perform when both rigidity and weight matter.

In the plot above, we compare five specific alloys:
  • Magnesium Alloy AZ91E-T6
  • Semi-red Brass C84200
  • Tin Bronze C91100
  • Copper Alloy C19200
  • JIS SUH35 (a heat-resistant stainless steel)
Key Insights:
  • Density significantly affects the specific stiffness (E/ρ) of a material. Materials that sit higher and more to the left on the chart offer better stiffness per unit weight.
  • Magnesium Alloy AZ91E-T6 typically shows the lowest density among the group. This makes it attractive for applications where weight saving is critical (e.g., automotive, aerospace, or portable electronics), even if its absolute stiffness is lower than steels or copper alloys.
  • Copper-based alloys (Semi-red Brass, Tin Bronze, and Copper Alloy C19200) generally have higher density but also respectable Young’s Modulus. They are preferred when high corrosion resistance, thermal conductivity, or wear resistance is needed alongside moderate stiffness.
  • JIS SUH35 (a stainless steel variant) likely sits in the higher stiffness and higher density region, making it suitable for high-temperature or high-strength applications where weight is less critical.
Engineering Takeaway:When designing a component, engineers rarely look for the “strongest” or “stiffest” material in absolute terms. Instead, they optimize for performance indices such as E/ρ (for tension-loaded lightweight stiff structures) or E^{1/3}/ρ (for bending stiffness with minimum weight).
  • If your design is weight-sensitive → favor materials toward the top-left (like magnesium alloys).
  • If your design requires high absolute stiffness and can tolerate higher weight → copper alloys or steels become more competitive.
  • Trade-offs always exist: lower density materials often come with lower absolute strength, higher cost, or processing challenges.
This Ashby plot helps visualize these trade-offs at a glance, enabling faster and more informed material selection during the early design stage.


Python Code
import pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport os
# ================== Kaggle Setup ==================os.environ['KAGGLE_USERNAME'] = "XXXXXXXXXX"os.environ['KAGGLE_KEY'] = "KGAT_xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
import kaggle
# Download dataset (run once)print("Downloading dataset...")kaggle.api.dataset_download_files('purushottamnawale/materials',                                   path='./materials_data',                                   unzip=True)
# Load the datadata_dir = './materials_data'csv_files = [f for f in os.listdir(data_dir) if f.endswith('.csv')]csv_path = os.path.join(data_dir, csv_files[0])
df = pd.read_csv(csv_path)
# ================== Fix Column Names ==================df = df.rename(columns={    "Material": "Material",    "E": "E",                       # Young's Modulus    "Young's Modulus": "E",    "Ro": "Density",                # Density column in this dataset    "Density": "Density"})
# Convert to numericdf['E'] = pd.to_numeric(df['E'], errors='coerce')df['Density'] = pd.to_numeric(df['Density'], errors='coerce')
# Clean datadf_clean = df.dropna(subset=['E', 'Density']).copy()
# Convert MPa to GPa if neededif df_clean['E'].max() > 1000:    df_clean['E'] = df_clean['E'] / 1000
# ================== Select Exactly 5 Materials ==================# Change these 5 material names as you likefive_materials = [    'Magnesium Alloy AZ91E-T6',    'Semi-red Brass C84200',    'Tin Bronze C91100',    'Copper Alloy C19200',    'JIS SUH35']
# Filter the 5 materialsselected = df_clean[df_clean['Material'].isin(five_materials)].copy()
print("\nMaterials being plotted:")print(selected[['Material', 'Density', 'E']])
# ================== Plot Ashby Chart for 5 Materials ==================plt.figure(figsize=(12, 9))
# Scatter plotplt.scatter(selected['Density'], selected['E'],             s=180, alpha=0.9, edgecolors='black', linewidth=1.5, color='royalblue')
# Add labels for each pointfor i, row in selected.iterrows():    plt.annotate(row['Material'],                  xy=(row['Density'], row['E']),                 xytext=(15, 10),                 textcoords='offset points',                 fontsize=11,                 fontweight='bold')
# Log scales (standard for Ashby plots)plt.xscale('log')plt.yscale('log')
# Labels and Titleplt.xlabel('Density (kg/m³)', fontsize=13, fontweight='bold')plt.ylabel("Young's Modulus E (GPa)", fontsize=13, fontweight='bold')plt.title("Ashby Plot: Young's Modulus vs Density\n(5 Selected Materials)",           fontsize=16, fontweight='bold', pad=20)
plt.grid(True, which="both", ls="--", alpha=0.7)
plt.tight_layout()plt.show()