witam , znów pojawiam się z problemem... niestety nie rozumiem jak można zadeklarować w cpp warunki brzegowe Dirichleta w rozwiązaniu równania Poissona.
Jest kod, wzięty ze strony AGH, jednak zamiast tamtejszych warunków brzegowych , chciałabym inne, czy mógby ktoś mi pomóc zrozumieć jak je zadeklarować?
include <math.h>
using namespace std;
const double b = 1;
const int n = 11;
const double pi=3.141592;
/*
double g0(double t) { return t*t; }
double g1(double t) { return 1.0; }
double g2(double t) { return t*t; }
double g3(double t) { return 0; }
double f(double x, double y) { return 2; }
double u_exact(double x, double y) { return x*x; }
*/
/*
double g0(double x) { return x*x; }
double g1(double y) { return cos(y); }
double g2(double x) { return x*x*cos(1.0); }
double g3(double y) { return 0.0; }
double f(double x, double y) { return (2-x*x)*cos(4*y); }
double u_exact(double x, double y) { return x*x*cos(y); }
*/
double g0(double x) { return x*x; }
double g1(double y) { return cos(4*y); }
double g2(double x) { return x*x*cos(4.0); }
double g3(double y) { return 0.0; }
double f(double x, double y) { return 2*(1-8*x*x)*cos(4*y); }
double u_exact(double x, double y) { return x*x*cos(4*y); }
/*
double g0(double x) { return 0.0; }
double g1(double y) { return 0.0; }
double g2(double x) { return 0.0; }
double g3(double y) { return 0.0; }
double f(double x, double y) { return -2*pi*pi*sin(pi*x)*sin(pi*y); }
double u_exact(double x, double y) { return sin(pi*x)*sin(pi*y); }
*/
void PoissonOnSquare(double (*g[4])(double), double u[n+2][n+2], int numIter) {
int i, j, k;
double h;
h = b/(n+1);
for (i=0; i <=n+1; i++) {
u[i][0] = (*g[0])(i*h);
u[n+1][i] = (*g[1])(i*h);
u[i][n+1] = (*g[2])(i*h);
u[0][i] = (*g[3])(i*h);
}
for (i=1; i <= n; i++)
for (j=1; j <= n; j++) u[i][j] = 0.0;
for (k=1; k <= numIter; k++)
for (i=1; i <= n; i++)
for (j=1; j <= n; j++)
u[i][j] = 0.25*(u[i-1][j]+u[i+1][j]+u[i][j-1]+u[i][j+1]-h*h*f(i*h,j*h));
}
int main() {
double (*g[4])(double), u[n+2][n+2];
int i, j;
g[0] = &g0; g[1] = &g1; g[2] = &g2; g[3] = &g3;
PoissonOnSquare(g, u, 500);
for (i=1; i <= n; i=i+4) {
for (j=1; j <= n; j=j+4) { cout.precision(4); cout.width(10); cout << right << u[i][j]; }
cout << "\n";
}
cout << "\n *** Rozwiązanie dokładne ***\n";
for (i=1; i <= n; i=i+4) {
for (j=1; j <= n; j=j+4) { cout.precision(4); cout.width(10); cout << right << u_exact(i*b/(n+1), j*b/(n+1))<< " "; }
cout << "\n";
}
system("pause");
}
a moje warunki brzegowe to : dla x=1 a=1,b=0,c=1 a dla x=1 mamy a=1, b=0, c=y(1-y)