Skip to content

Instantly share code, notes, and snippets.

@alexg228
Created November 19, 2010 07:12
Show Gist options
  • Save alexg228/706218 to your computer and use it in GitHub Desktop.
Save alexg228/706218 to your computer and use it in GitHub Desktop.
way simpalar
#include <fstream>
#include <math.h>
using namespace std;
int main(void) {
ofstream fp5;
fp5.open ("Laplace101.txt");
double V[11];
double diff(1.0);
double oldv;
int j = 0;
int i;
V[1]=0;
V[2]=7;
V[3]=25;
V[4]=32;
V[5]=39;
V[6]=42;
V[7]=55;
V[8]=70;
V[9]=82;
V[10]=93;
V[11]=100;
while (diff >= .001)
{
oldv = V[9];
for (i=2; i<=10; i++)
{
V[i]=.5*(V[i+1]+V[i-1]);
}
diff = fabs(V[9]-oldv)/oldv;
j++;
}
for(int k=1; k<=11; k++) {
fp5 << k << " " << V[k] << endl;
}
fp5.close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment