View on GitHub

computational-mathematics

Contains basic implementations of a number of standard procedures in scientific computing and computational mathematics.

Routine Name: adams34

Author: Christopher Johnson

Language: C++. Tested with g++ compiler.

Declared in: “ivpSolver.hpp”

Description/Purpose: Solves initial value problem with third order predictor corrector method. Initial values generated by rk4, prediction by fourth order Adams-Bashforth, and correction by third order Adams-Moulton.

Input: Function F(R^2->R), initial value y0, endpoints a < b, and step size h.

Output: Returns struct TimeAndValues containing endpoints, mesh, and function values at mesh points.

Usage/Example: Tested in Exponential Test and Logistic Test. See associated documentation for example code.

Implementation/Code: The following is the code for adams34(f,y0,a,b,h)

timesAndValues adams34 (std::function<double(double,double)> F, double y0, double a, double b, double h)
{
	timesAndValues r;
	r.a = a;
	r.b = b;
	double y = y0;
	double t=a;
	for (int i=0;i<4;++i)
	{
		r.time.push_back(t);
		r.value.push_back(y);
		y = rk4(F,y,t,h);
		t+=h;
	}

	double u0 = r.value[0];
	double u1 = r.value[1];
	double u2 = r.value[2];
	double u3 = r.value[3];
	double t0 = r.time[0];
	double t1 = r.time[1];
	double t2 = r.time[2];
	double t3 = r.time[3];

	for (t; t<=b; t+=h)
	{
		r.time.push_back(t);
		r.value.push_back(y);
		double u4 = u3 + h/24 * (-9*F(u0,t0) + 37*F(u1,t1) - 59*F(u2,t2) + 55*F(u3,t3));
		y = u3 + h/24*(F(u1,t1) - 5*F(u2,t2) + 19*F(u3,t3) + 9*F(u4,t));
		u0 = u1; u1=u2; u2=u3; u3=u4;
		t0 = t1; t1=t2; t2=t3; t3=t;
	}
	return r;
}

Last Modified: April/2018