ME 2016 - Computing Techniques (Fall 2025)
Instructor: Karthik Menon
Homework 8
Due: October 30, 2025
Grading Rubric
Professionalism
Points
Report includes header/footer (name, date, course #, assignment #, page #)
2
Report includes problem description and discussion in complete sentences
2
Code includes header (name, date, description, input/output variable definitions)
2
Extraneous command window output is suppressed
2
Plots are well-formatted (axis labels, legend, appropriate line/marker styles)
4
Code runs without errors
4
TOTAL
16
Initial value problem
Points
Implementation is modular
10
Correct Euler solution curve
6
Correct Heun solution curve
12
Correct RK4 solution curve
12
Correct Euler error curve
6
Correct Heun error curve
12
Correct RK4 error curve
12
Discussion is complete and makes sense
14
TOTAL
84
Total Points: 100
1
ME 2016 (Fall 2025)
Homework 8
Due: October 30, 2025
Learning Objectives
• To write a modular code for solving first-order, linear ODE’s of the form, dy/dx = f (x, y),
such that it is easy to swap out different one-step methods.
• To compare accuracy of Euler, Heun, and classical 4th-order Runge-Kutta methods in
solving first- order, linear ODE’s of the form, dy/dx = f (x, y), given stepsize, h.
Reflection
Do you feel like you understand the Euler method (and other methods implemented in this
homework) now more than you did when implementing it in your first homework? Why or why
not? Is there context from everything else you have learned this semester that is relevant here?
Problem description
The goal of this homework is to solve the first-order, linear ordinary differential equation (ODE),
1
dy(x)
= f (x, y), where, f (x, y) = y − ex/2 sin 5x + 5ex/2 cos 5x,
dx
2
(1)
with initial condition y(0) = 0 and domain, 0 ≤ x ≤ 5. You should compare the analytical
solution of the initial value problem (IVP) in equation 1,
y(x) = ex/2 sin 5x
(2)
to the numerical solutions obtained using Euler, Heun, and the classical 4th-order Runge-Kutta
method considering stepsize, h = 0.25.
Your tasks
Using the provided script, Script IVP snippet.py, write a modular Python code that solves
the IVP in equation 1 and compares the analytical and numerical solutions. Look for comments
starting with TODO in the provided code snippet for parts of the code you need to complete.
Please do the following:
1. Implement a single step of Euler’s method, Heun’s method, and the classical 4th-order
Runge-Kutta method, in 3 separate functions. To be specific, you should write functions
called euler(), heun(), and rk4() that take as input xi and yi at the current step; the
output of a function dydx, that stores the function, f (x, y); and the stepsize, h. Each
of these function should output xi+1 and yi+1 after performing one step of the method,
i.e., after performing yi+1 = yi + ϕh and xi+1 = xi + h, where ϕ is the slope that is
approximated differently for each method.
2
ME 2016 (Fall 2025)
Homework 8
Due: October 30, 2025
2. Implement the main iterative loop for one-step methods in a separate function,
iterative IVP solver(). This function should take as input the initial value of your dependent variable, the initial and final values of your independent variable, and a function
that implements a one-step method mentioned above. Note that this function should be
general and work with any of the three one-step methods.
3. Plot the analytical solution in equation 2 and the approximate solutions of equation 1
from each method on a single plot.
4. Plot the true error, |ϵt |, at x = 2 as a function of the step size, h, for each method on a
single plot.
Your discussion
In your report, discuss the relative accuracy of the three numerical methods based on the two
plots output by your code. Which one is most accurate? Which one is least accurate? Does
this trend agree with the error estimates we discussed in class for each method? Does the error
change as expected when the stepsize, h, is reduced? Additionally, briefly discuss what makes
your code modular. For example, what changes to the code would you need to make if you
were implementing a 3rd-order Runge-Kutta method?
Deliverables
Please place all files described below (e.g., .pdf, .py) in a zipped folder and upload to Canvas
using the following naming convention: HW# Surname FirstName.zip.
This should include the following:
1. Professionally-formatted report: Please provide a brief description of the problem,
images of the plots output by your code, a screenshot of the command window output
from your code, and the discussions indicated above. Be sure to format your report professionally. Your plot(s) should include meaningful axis labels with units, a legible legend,
and curve formatting as specified above. Your report should include a header/footer with
your name, date, course number, assignment number, and page number.
2. Professionally-formatted source code: Include all scripts and functions that you
wrote, as well as all functions and data provided, to complete the assignment. Please be
sure that your code runs directly upon download of your zip file (which means you should
include the scripts/data provided, if any). Be sure to format your code professionally.
At the top of each script, include your name, the date, and a description of the file - for
functions also define all input and output variables. Use comments liberally.
3