UNIHIVE

Study Hub UNIPORT ENG 213.1

ENG 213.1 · Computer Programming for Engineers

Solving engineering problems: root finding, integration and applications

Short programs for fluid, thermodynamic, heat transfer and electrical problems, with bisection, Newton's method and the trapezium rule.

Our notes

1 min read

Why numerical methods

Many engineering equations have no neat formula for the answer: the friction factor in pipe flow, a beam's natural frequency, the work in a process with measured pressures. A computer finds a numerical answer to any required accuracy.

Bisection method (root finding)

If f(a) and f(b) have opposite signs, a root lies between them. Halve the interval, keep the half with the sign change, repeat.
program bisect
  implicit none
  real :: a, b, m
  integer :: k
  a = 1.0
  b = 2.0
  do k = 1, 30
    m = (a + b) / 2.0
    if (f(a) * f(m) <= 0.0) then
      b = m
    else
      a = m
    end if
  end do
  print *, 'Root =', m
contains
  real function f(x)
    real, intent(in) :: x
    f = x**3 - x - 2.0
  end function f
end program bisect
Output: Root = 1.52138 (to about 6 figures). Check: 1.52138³ − 1.52138 − 2 ≈ 0.

Newton's method

x_new = x − f(x)/f′(x). Much faster near the root, but needs f′ and a good starting value. For f(x) = x³ − x − 2, f′(x) = 3x² − 1, starting at x = 1.5:

  • x₁ = 1.5 − (3.375 − 1.5 − 2)/(6.75 − 1) = 1.5 − (−0.125/5.75) = 1.52174
  • x₂ = 1.52138, already correct to 5 decimals.

Trapezium rule (integration)

∫ f dx ≈ h [f₀/2 + f₁ + ... + f_(n−1) + fₙ/2], with h = (b − a)/n.
Thermodynamics example: isothermal expansion of a gas with pV = 10 kJ (p in kPa, V in m³) from 0.1 to 0.2 m³. Work W = ∫p dV.

  • Exact: W = 10 ln 2 = 6.931 kJ.
  • Trapezium rule with n = 10: 6.9377 kJ (error 0.1%).

Applications in the lab

AreaProgram ideaSample result
Fluidsvelocity of efflux v = √(2gh) for a tank, h = 5 m9.90 m/s
FluidsReynolds number and regime for a pipeRe = 100,000, turbulent
Heat transferconduction through layered walls Q = ΔT / ΣRsee below
Thermodynamicsideal gas: p = mRT/V for air, m = 1 kg, T = 300 K, V = 0.5 m³, R = 0.287 kJ/kg·K172.2 kPa
Electricalseries and parallel resistors, current in a circuit6 Ω and 3 Ω: 9 Ω and 2 Ω

Worked example: layered wall

Brick (L = 0.2 m, k = 0.8 W/m·K) plus insulation (L = 0.05 m, k = 0.04), area 10 m², ΔT = 20 K.

  • R_brick = 0.2 / (0.8 × 10) = 0.025 K/W; R_ins = 0.05 / (0.04 × 10) = 0.125 K/W.
  • Q = 20 / 0.15 = 133.3 W (compared with 800 W for brick alone).

Exams usually ask

  • Write a program to find a root by bisection or Newton's method.
  • Write a program to integrate tabulated data by the trapezium rule.
  • Write a program for a given fluid, heat or electrical calculation.

Common mistake

Running Newton's method with no limit on iterations or from a bad starting point where f′(x) ≈ 0. Add a maximum number of passes and check convergence.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

Read

Watch

We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.

All ENG 213.1 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.