0

Runge-Kutta is supposed to be used to obtain the numerical solution to a boundary layer problem. I'm trying to get the output to go to excel where it will show me the values for G1, G2 and G3 but it won't go to excel. Please help!

```
#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;
int main ()
{
double totalerror, allowederror;
double G1, G2, G3;
double firstguess;
double n;
double ystar1, ystar2, ystar3;
double h;
double fstar1, fstar2, fstar3;
double y1, y2, y3;
double secondguess, thirdguess;
double G1guess, G2guess;
const double pi = acos(-1.0);
totalerror=10;
ofstream results;
results.open ("output.xls");
/*
cout << "Please enter the allowed error." ;
cin >> allowederror;
cout << "Please enter the step size. ";
cin >> h;
cout << "Please enter the first guess for G3. ";
cin >> firstguess;
cout << "Please enter the second guess for G3. ";
cin >> secondguess;
*/
allowederror = .001;
h = .01;
firstguess = 1;
secondguess = .1;
while (totalerror > allowederror)
{
G1 = 0;
G2 = 0;
G3 = firstguess;
n = 0;
while (n < 10)
{
ystar1 = G1 + h*G2;
ystar2 = G2 + h*G3;
ystar3 = G3 + h*-G1*G3;
fstar1 = ystar2;
fstar2 = ystar3;
fstar3 = -ystar1*ystar3;
y1 = G1 + 0.5*h*(G2+fstar1); //new y values
y2 = G2 + 0.5*h*(G3+fstar2);
y3 = G3 + 0.5*h*(-G1*G3+fstar3);
G1 = y1;
G2 = y2;
G3 = y3;
n = n+h;
}
G1guess = G2;
G1 = 0;
G2 = 0;
G3 = secondguess;
n = 0;
while (n < 10)
{
ystar1 = G1 + h*G2;
ystar2 = G2 + h*G3;
ystar3 = G3 + h*-G2*G3;
fstar1 = ystar2;
fstar2 = ystar3;
fstar3 = -ystar1*ystar3;
y1 = G1 + 0.5*h*(G2+fstar1);
y2 = G2 + 0.5*h*(G3+fstar2);
y3 = G3 + 0.5*h*(-G1*G3+fstar3);
G1 = y1;
G2 = y2;
G3 = y3;
n = n+h;
}
G2guess = G2;
double m = (G2guess-G1guess)/(secondguess-firstguess);
double b = G1guess - m*firstguess;
thirdguess = (1-b)/m;
double firsterror = abs(1-G1guess);
double seconderror = abs(1-G2guess);
if (firsterror < seconderror)
{
firstguess = firstguess;
}
else
{
firstguess = secondguess;
}
secondguess = abs(thirdguess);
totalerror = abs(secondguess - firstguess);
}
G1 = 0;
G2 = 0;
G3 = thirdguess;
n = 0;
while (n < 2*pi)
{
ystar1 = G1 + h*G2;
ystar2 = G2 + h*G3;
ystar3 = G3 + h*-G1*G3;
fstar1 = ystar2;
fstar2 = ystar3;
fstar3 = -ystar1*ystar3;
y1 = G1 + 0.5*h*(G2+fstar1);
y2 = G2 + 0.5*h*(G3+fstar2);
y3 = G3 + 0.5*h*(-G1*G3+fstar3);
G1 = y1;
G2 = y2;
G3 = y3;
results << n << '\t' << G2 << endl;
n = n+h;
}
results.close();
return 0;
}
```