ENG 213.1 · Computer Programming for Engineers
Our notes
1 min readWhy 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
| Area | Program idea | Sample result |
|---|---|---|
| Fluids | velocity of efflux v = √(2gh) for a tank, h = 5 m | 9.90 m/s |
| Fluids | Reynolds number and regime for a pipe | Re = 100,000, turbulent |
| Heat transfer | conduction through layered walls Q = ΔT / ΣR | see below |
| Thermodynamics | ideal gas: p = mRT/V for air, m = 1 kg, T = 300 K, V = 0.5 m³, R = 0.287 kJ/kg·K | 172.2 kPa |
| Electrical | series and parallel resistors, current in a circuit | 6 Ω 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
-
Bisection method
(opens en.wikipedia.org in a new tab)
Wikipedia, Bisection method, CC BY-SA 4.0 · licence
-
Newton's method
(opens en.wikipedia.org in a new tab)
Wikipedia, Newton's method, CC BY-SA 4.0 · licence
-
NPTEL: Numerical Methods (IIT Roorkee, whole course)
40 lectures: errors, linear systems, bisection, regula falsi, secant and Newton-Raphson, interpolation, numerical integration. Video lectures, many hours in all: watch on Wi-Fi where you can.
(opens nptel.ac.in in a new tab)
NPTEL, NPTEL: Numerical Methods (IIT Roorkee, whole course), CC BY-NC-SA 4.0 · licence
Watch
-
Best pick Numerical Analysis with Fortran: Using Bisection Code
3 min · ≈ 14 MB · about ₦8
(opens youtube.com in a new tab)
-
Fortran Program to Find Root of a Number | Lecture 4 | Fortran Programming Tutorial
6 min · ≈ 27 MB · about ₦15
(opens youtube.com in a new tab)
-
Fortran Program - Solve a Quadratic Equation
4 min · ≈ 18 MB · about ₦10
(opens youtube.com in a new tab)
-
Root of the equation using bisection method in fortran 90
22 min · ≈ 99 MB · about ₦56
(opens youtube.com in a new tab)
-
Integration Fortran
8 min · ≈ 36 MB · about ₦20
(opens youtube.com in a new tab)
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.