Documente Academic
Documente Profesional
Documente Cultură
Let’s begin with a first order predictor integral where the limits of
integration are between xi-1 and xi or xi-1 and xi-1 + h and where we want to
calculate the value of the integral at xi+1. The general equation for such a
first order indefinite integral can be written as:
We want to find an equation that uses the current data point and the previous
point and finds the integral between xi and xi+1.
JAxi + JB + KAxi-1 + KB
JA xi + JB + KA xi – KAh + KB
Bh = JB + KB or
J+K=h
K = –h/2
Therefore:
The next step is to develop the first order corrector equation. Here we begin
with the area bounded by the dependent values yi-1, yi and the independent
values xi-1 and xi and calculate the value of the integral at yi.
JAxi + JB + KA(xi – h) + KB
Bh = JB + KB
1
Jack W. Crenshaw, MATH Toolkit for REAL-TIME Programming, CMP Books, 2000
J+K=h
Dividing by h yields
xi – h/2 = xi – K or
Therefore:
J = h/2 and K = h/2
Let’s continue and develop the equations for a second order integral
predictor.
+ L(Axi-22 + Bxi-2 + C)
1
Jack W. Crenshaw, MATH Toolkit for REAL-TIME Programming, CMP Books, 2000
Multiplying out terms on the left and right hand sides we have
+ LAxi-22 + LBxi-2 + LC
Now we separate out the A, B, and C terms since they are orthogonal to each
other and like terms on the left side must equal like terms on the right side.
Let’s start with the C terms since this is the simplest of the three equations.
JC + KC + LC = Ch or
J+K+L=h
xh + h2/2 = Jx + Kx – Kh + Lx – 2Lh
xh + h2/2 = xh – Kh – 2Lh
h/2 = – K – 2L
Finally we have
K + 2L = – h/2
x2h + xh2 + h3/3 = Jx2 + Kx2 – 2Kxh + Kh2 + Lx2 – 4Lxh + 4Lh2
Since J + K + L = h we have
xh + h2/3 = Kh + 4Lh + xh
K + 4L = h/3
J + K + 1L = h/1
K + 2L = – h/2
K + 4L = h/3
J + K + 1L = h/1
K + 2L = h/2
K + 4L = h/3
Using these coefficients we can write the second order corrector equation
J + K + 1L + 1M + 1N = h/1
K + 2L + 3M + 4N = – h/2
K + 4L + 9M + 16N = h/3
K + 8L + 27M + 64N = – h/4
K + 16L + 81M + 256N = h/5
J + K + 1L + 1M + 1N = h/1
K + 2L + 3M + 4N = h/2
K + 4L + 9M + 16N = h/3
K + 8L + 27M + 64N = h/4
K + 16L + 81M + 256N = h/5
The terms on the left hand side are identical and form a nice geometric
progression. The terms on the right hand side are also identical except for
the differences in sign. Solving these matrices will give us the equations for
a fourth order predictor and corrector.
The attached C++ program can solve for either the predictor or corrector
equations by generating the matrix and solving for the unknowns.
#include <math.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <fstream.h>
#define ORDER 5
#define N ORDER
#define TRUE 1
#define FALSE 0
__int64 test;
class fraction {
private:
long int numerator, denominator;
public:
fraction(long int numerator = 1, long int denominator = 1);
fraction reduction(fraction);
void setfraction(long int, long int);
fraction fabs(fraction);
void fpow(long int, long int);
void oprint();
void sprint();
};
void fraction::oprint() {
printf("%7ld", numerator);
}
void fraction::sprint() {
printf("%6ld/%ld", numerator, denominator);
}
//-------------------------------------------------------------------------//
// Euclid's Algorithm for fraction reduction
//-------------------------------------------------------------------------//
fraction fraction::reduction(fraction f) {
fraction save, temp;
save = f;
while(f.denominator != 0) {
temp.numerator = f.numerator;
f.numerator = f.denominator;
f.denominator = temp.numerator % f.denominator;
}
temp.numerator = save.numerator / f.numerator;
temp.denominator = save.denominator / f.numerator;
// for negative fractions set numerator negative
if(temp.denominator < 0) {
//-------------------------------------------------------------------------//
// Write the original matrix to the terminal
//-------------------------------------------------------------------------//
printf("\n");
for(j=0; j<n; j++) {
for(k=0; k<n+1; k++)
a[k][j].sprint(); // oprint
printf("\n");
}
printf("\n");
}
//-------------------------------------------------------------------------//
// Write the solution to the terminal
//-------------------------------------------------------------------------//
printf("\n");
for(j=0; j<n; j++) {
for(k=0; k<n+1; k++)
a[k][j].sprint();
printf(" | ");
x[j].sprint();
printf("\n");
}
printf("\n");
}
//-------------------------------------------------------------------------//
// Solve system of equations using Gaussian Elimination
//-------------------------------------------------------------------------//
return(TRUE);
}
double main(void) {
long int row, col;
fraction a[N+1][N]; //a[col][row]
fraction b[N];
WriteOriginal(N, a);
if(!GaussSolve(N, a, b)) {
printf ("The Matrix is Singular");
return -1;
}
WriteSolution(N, a, b);
return 0;
}