Mathematical Discussion
The Adams-Bashforth 2-step method is an explicit numerical method used to approximate the solution of a first-order initial value problem:
\[ \frac{dy}{dx}=f(x,y), \quad y(x_0)=y_0 \]
Since it is a two-step method, it needs two previous values before computing the next value. The first value is usually obtained from the given initial condition, while the second value can be estimated using Euler's method or another one-step method.
\[ y_{n+1}=y_n+\frac{h}{2}\left(3f_n-f_{n-1}\right) \]
where \(h\) is the step size, \(f_n=f(x_n,y_n)\), and \(f_{n-1}=f(x_{n-1},y_{n-1})\).
Worked Example 1
Problem: Use Adams-Bashforth 2-step method to solve \(y'=x+y\), \(y(0)=1\), with \(h=0.1\). Find values up to \(x=0.3\).
Step 1: Given \(x_0=0\), \(y_0=1\), \(h=0.1\).
\[ f_0=f(0,1)=0+1=1 \]
Step 2: Use Euler's method to get \(y_1\):
\[ y_1=y_0+hf_0=1+0.1(1)=1.1 \]
\[ x_1=0.1, \quad f_1=f(0.1,1.1)=0.1+1.1=1.2 \]
Step 3: Compute \(y_2\):
\[ y_2=y_1+\frac{h}{2}(3f_1-f_0) \]
\[ y_2=1.1+\frac{0.1}{2}[3(1.2)-1] \]
\[ y_2=1.1+0.05(2.6)=1.2300 \]
Step 4: Compute \(f_2\):
\[ f_2=f(0.2,1.23)=0.2+1.23=1.43 \]
Step 5: Compute \(y_3\):
\[ y_3=1.23+\frac{0.1}{2}[3(1.43)-1.2] \]
\[ y_3=1.23+0.05(3.09)=1.3845 \]
Final Answer: \(y(0.3)\approx 1.3845\).
Worked Example 2
Problem: Use Adams-Bashforth 2-step method to solve \(y'=x-y\), \(y(0)=2\), with \(h=0.2\). Find values up to \(x=0.6\).
Step 1: Given \(x_0=0\), \(y_0=2\), \(h=0.2\).
\[ f_0=f(0,2)=0-2=-2 \]
Step 2: Use Euler's method to get \(y_1\):
\[ y_1=y_0+hf_0=2+0.2(-2)=1.6 \]
\[ x_1=0.2, \quad f_1=f(0.2,1.6)=0.2-1.6=-1.4 \]
Step 3: Compute \(y_2\):
\[ y_2=1.6+\frac{0.2}{2}[3(-1.4)-(-2)] \]
\[ y_2=1.6+0.1(-2.2)=1.38 \]
Step 4: Compute \(f_2\):
\[ f_2=f(0.4,1.38)=0.4-1.38=-0.98 \]
Step 5: Compute \(y_3\):
\[ y_3=1.38+\frac{0.2}{2}[3(-0.98)-(-1.4)] \]
\[ y_3=1.38+0.1(-1.54)=1.226 \]
Final Answer: \(y(0.6)\approx 1.226\).
Interactive Calculator
Safe Input Parsing
The calculator does not use Python's eval(). Instead, it uses SymPy's sympify() with a limited list of allowed variables and functions. Only x, y, and common math functions such as sin, cos, exp, log, and sqrt are accepted.