Assignment 3

Due on November 2 at 11:59pm electronically via email.

How to submit the assignment

Use a word-processor like Microsoft Word or LibreOffice (free), or \( \LaTeX \) (also free) to create a single PDF file with all of your answers. If you want to include code, do not put them in this file. This file should include your graphs, equations, tables, and explanations. The name of this file should have the following format: LASTNAME_STUDENTNUMBER_3.pdf. You can hand-write your answers, but you will have to scan your papers, or take a picture of them. In any case, send me one PDF file. I will not accept paper submissions.

If you want to include multiple code files (.m or .py files), put them all in one folder, zip the folder, and send me only one zip file. The name of this file should look like this: LASTNAME_STUDENTNUMBER_A3.zip

Attach both files to an email and send it to msamani[at]fields.utoronto.ca. Make sure the title of the email starts with MATH3090.

Question 1: Use the classical Runge-Kutta method, described at the bottom of page 190 and top of page 191 of the textbook, to solve the following initial-value differential equations:

  1. \( y' = 1 + y/t \; , \; 2 \le t \le 3 \; , \; y(2) = 1\)
  2. \( y' = e^{t-y} \; , \; 0 \le t \le 1 \; , \; y(0) = 1\)
Use \(h=0.5\) and \(h=0.01\). In each case, calculate the global error. The actual solutions are
  1. \( y(t) = \left( \frac{1 - 2 \log(2)}{2} \right) t + t \log(t) \)
  2. \( y(t) = \log(e^t + e - 1)\)
Plot the two numerical solutions on top of the exact solution.
Attach your code. Do not use any of MATLAB's odexxx or Python's scipy.integrate.ode functions. Write your own code.

Questions from the textbook:

6.3, 7.19, 11.2

For 6.3, I would like to see a plot of relative error versus \( n \), for a reasonable range of \( n \).

For 11.2.b, you can use the following code to produce the exact solution:

% MATLAB
syms u(x)
dsolve(diff(u,x,2) == exp(-x^2))
# Python
from sympy import *
from sympy.abc import x
u = Function('u')
dsolve(Derivative(u(x), (x,2)) - exp(-x**2))
They both produce the following function: $$ \DeclareMathOperator\erf{erf} u(x) = C_1 + C_2 x + e^{-x^2/2} + \frac{\sqrt{\pi}}{2} x \erf(x) $$ to which you can apply the boundary conditions in order to find \( C_1 \) and \( C_2 \).