The extrapolation method, which is based on the boundary conditions, introduces the latter value by the recursive relation, and then launches the latter value by the latter value by the recursive relation. Recursively until the solution to the problem is pushed forward from the initial state of the problem. Instance
Code
#include <iostream>#include <stdlib.h>using namespace STD;Const intMAXN = -;intN =4, d =2, M =3;floatA1 =2, an =5;voidInput () {cout<<"input data n,d,a1,an,m"<<endl;Cin>>N>>d>>a1>>an>>m;if(N > MAXN) {cout<<"Input Error"<<endl;return; }if(N > m) {cout<<"M is too large"<<endl;return; }if(M <0) {cout<<"M must be a positive data."<<endl;return; }}//Calculate the relationship between am and A1 s//a[i] = s[m][0]*a[2] + s[i][1]*d + s[i][2]*a1//a2 = (an-s[n-1][1] * d-s[n-1][2] * A1)/s[n-1][0]voidCalculate_s (float**s,float*List) {s[0][0] =0; s[0][1] =0; s[0][2] =1; s[1][0] =1; s[1][1] =0; s[1][2] =0; for(inti =2; i < N; i++) {s[i][0] = s[i-2][0] -2* s[i-1][0]; s[i][1] = s[i-2][1] -2* s[i-1][1] +2; s[i][2] = s[i-2][2] -2* s[i-1][2]; }List[0] = A1;List[1] = (an-s[n-1][1] * d-s[n-1][2] * A1)/s[n-1][0] ; for(intj =2; J < N; J + +) {List[j] =List[J-2] -2*List[J-1] +2* D; }}//Output The final resultvoidOutfloat**s,float*List){intI for(i =0; i < N; i++) {cout<<s[i][0]<<" "<<s[i][1]<<" "<<s[i][2]<<" "<<endl; }cout<<"Data ..."<<endl; for(i =0; i < N; i++) {cout<<List[i]<<" "; }cout<<endl;}intMain () {//input (); //s[i][0] = P s[i][1] means q s[i][2] = R float**s = (float**)malloc(sizeof(float*) * N); for(intII =0; II < N; ii++) S[ii] = (float*)malloc(sizeof(float) *3);float*List= (float*)malloc(sizeof(float) * N); Calculate_s (s),List); Out (S,List);cout<<"\nthe result of"<<m<<"Data is:";cout<<List[M-1]<<endl;return 0;}
Analysis and program design of practical algorithm--recursive method (Shun-push method) contains an example, code