Skip to content

Instantly share code, notes, and snippets.

Created October 2, 2010 19:39
Show Gist options
  • Save anonymous/607923 to your computer and use it in GitHub Desktop.
Save anonymous/607923 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
using namespace std;
int main() {
const int x_max=20 ,y_max=20;
const float y_max_v=1.0, mu=1.0;
int pass_count=0;
float V[x_max][y_max];
for (int i=0; i<=y_max-1; i++) {
V[0][i]=0.0;
V[x_max-1][i]=1.0;
}
for (int i=0; i<=x_max-1;i++){
V[i][0]=(y_max_v/(y_max-1))*i;
V[i][y_max-1]=(y_max_v/(y_max-1))*i;
}
for(int i=1;i<=x_max-2;i++) {
for(int j=1;j<=y_max-2;j++) {V[i][j]=mu;}
}
while(1<2){
for(int i=1;i<=x_max-2;i++) {
for(int j=1;j<=y_max-2;j++) {
if(((V[i+1][j]+V[i-1][j]+V[i][j+1]+V[i][j-1])/4.0)-V[i][j]<=0.000005) {
V[i][j]=(V[i+1][j]+V[i-1][j]+V[i][j+1]+V[i][j-1])/4.0;
pass_count=pass_count+1;
}
else {cout<<"The solution is "<<V[i][j];}
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment