Numerical Methods In Engineering With Python 3 Solutions -
print(f"Temp after 60s (Euler): T_euler[-1]:.2f°C") print(f"Temp after 60s (RK4): T_rk4[-1]:.2f°C") Problem: Simply supported beam, uniformly distributed load ( w = 10 , \textkN/m ), length ( L = 5 , \textm ), ( EI = 20000 , \textkN·m^2 ). Find maximum deflection using numerical integration of the ODE:
print(f"Bisection root: root_bisect:.6f") print(f"Newton root: root_newton:.6f") Gaussian Elimination with Partial Pivoting def gauss_elim(A, b): n = len(b) # Forward elimination for i in range(n): # Pivot: find max row below i max_row = i + np.argmax(np.abs(A[i:, i])) if max_row != i: A[[i, max_row]] = A[[max_row, i]] b[[i, max_row]] = b[[max_row, i]] # Eliminate below for j in range(i+1, n): factor = A[j, i] / A[i, i] A[j, i:] -= factor * A[i, i:] b[j] -= factor * b[i] Numerical Methods In Engineering With Python 3 Solutions
root_bisect = bisection(deflection, 0, 1.5) root_newton = newton_raphson(deflection, d_deflection, 2.5) print(f"Temp after 60s (Euler): T_euler[-1]:
t_test = 2.0 velocity = central_diff(position, t_test) print(f"Velocity at t=2s (central diff): velocity:.2f m/s") distance = simpsons_rule(acceleration, 0, 5, 10) print(f"Distance (integrated): distance:.2f m") 5. Ordinary Differential Equations (ODEs) Euler, Runge–Kutta 4th Order (RK4) def euler(f, y0, t0, tf, h): t = np.arange(t0, tf + h, h) y = np.zeros(len(t)) y[0] = y0 for i in range(len(t)-1): y[i+1] = y[i] + h * f(t[i], y[i]) return t, y def rk4(f, y0, t0, tf, h): t = np.arange(t0, tf + h, h) y = np.zeros(len(t)) y[0] = y0 for i in range(len(t)-1): k1 = f(t[i], y[i]) k2 = f(t[i] + h/2, y[i] + h k1/2) k3 = f(t[i] + h/2, y[i] + h k2/2) k4 = f(t[i] + h, y[i] + h k3) y[i+1] = y[i] + h/6 * (k1 + 2 k2 + 2*k3 + k4) return t, y Example: cooling of an engine block (Newton's law of cooling) def cooling(t, T): T_env = 25 # ambient temp (°C) k = 0.05 # cooling constant return -k * (T - T_env) length ( L = 5
def d_deflection(x): return 3 x**2 - 12 x + 11
