0

Hello everyone, I am a Mathematics major and my mentor asked me to put together a program that evaluates explicit stencil methods along the difference mesh. Basically I need to use a recursive method to get my value, as I know base values and boundaries, but the C++ experience I have is minimal, and I need to use iterated loops. I am having trouble, and if anyone can help I would appreciate it.

This is the wiki page for Explicit stencil: (Note I am not using standard central difference)

http://en.wikipedia.org/wiki/Finite_difference_method

Here is my code thus far:

```
/*****************************************************************************
This program will take in a lower level node on the finite-difference mesh and
output a node that is on the level above it. This program also takes in a value
for lambda for future use. This program takes in a value for the stepsize along
the x axis.
******************************************************************************/
#include <iostream>
#include <cmath>
using namespace std;
//long double forwardAdjustedCentral(long double, long double);
int main()
{
long double uN, n, x, t, lambda, tau, h, H, Hminus, uNminus, uNplus, tMplus;
cout << "Enter a negative value for lambda: ";
cin >> lambda;
cout << "Enter a value for a stepsize tau on the t axis: ";
cin >> tau;
cout << "Enter a value for a stepsize h on the x axis: ";
cin >> H;
cout << "Enter a node on the finite difference mesh (x,t): ";
cin >> x;
cin.ignore(1);
cin >> t;
Hminus = H;
//long double array oldu [3];
for (n = 0; n <= t; ++n)
{
if (x == 1 || x == 0)
{
uN = 0;
uNplus = 0;
uNminus = 0;
}
if (t == 0)
{
uN = sin(x);
uNplus = sin(x);
uNminus = sin(x);
}
tMplus = (((2*lambda*tau)/((H*Hminus*(H+Hminus))))*(H*uNminus-H*uN+Hminus*uNplus))+uN;
for(
}
cout << uN << endl << uNplus << endl << uNminus << endl;
cout << tMplus << endl;
return 0;
}
/*long double forwareAdjustedCentral(long double x, long double t);
{
Mplus = (((2*lambda*tau)/((H*Hminus*(H+Hminus))))*(H*Nminus-H*N+Hminus*Nplus))+N
return Mplus;
}*/
```

Thanks so much everyone!