# L-32 MCS 471 Fri 4 Nov 2022 : adamsbashforth3.jl # Applies the method of undetermined coefficient to construct # a 3-point Adams-Bashforth method using SymPy. using SymPy # declare the parameter h, the weights, and a free variable h, c1, c2, c3, z = Sym("h, c1, c2, c3, z") # if xn is 0, then xnminus1 must be -h, xnminus2 must be -2*h (xn, xnminus1, xnminus2) = (0, -h, -2*h) # we can now define the rule symbolically rule(f) = c1*f(xn) + c2*f(xnminus1) + c3*f(xnminus2) # the basis functions are b1(x) = Sym("1") b2(x) = x b3(x) = x^2 # the right hand sides of the equations rhs1 = SymPy.integrate(b1(z), (z, xn, xn+h)) rhs2 = SymPy.integrate(b2(z), (z, xn, xn+h)) rhs3 = SymPy.integrate(b3(z), (z, xn, xn+h)) # the rule must integrate the basis functions correctly eq1 = rule(b1) - rhs1 eq2 = rule(b2) - rhs2 eq3 = rule(b3) - rhs3 println("The equations :") println(eq1) println(eq2) println(eq3) sol = SymPy.solve([eq1,eq2,eq3],[c1, c2, c3]) println("The solution :", sol)