# 辅导Python程序设计、辅导program编程

- 首页 >> Algorithm 算法
Assignment_2
October 14, 2021
1 Lab Assignment 2
1.1 Presentation and coding style (3 marks)
In this assignment, some marks are allocated to your coding style and presentation. Try to make
good quality, right size, good range and proper labels.
In this task we try to use several method from Lab 2 to solve the initial value problem
y
′ = 3y − 4t, y(0) = 1, (1)
Set the step size to h = 0.05 and numerically solve this ODE from t = 0 to 0.5 using the following
methods:
• Forward Euler
• Adams–Bashforth order 3 (we did not code this method in the computer lab, but you can
find the formula on this wikipedia page). For this method, you need to build the very first
two steps using other methods. For the first step, use the Euler scheme. For the second step,
Plot the three different approximations, and display the values in a table.
[ ]: # Import packages
import math
import numpy as np
import matplotlib.pyplot as plt
[ ]: # defining the function in the RHS of the ODE given in the question
[ ]: from pandas import DataFrame
# plot the results
1
[ ]: # printing the solution in a table