![]() |
![]() |
This lesson concerns a simple one-dimensional two-point boundary value problem. The whole program can be found in Example 1 in the examples directory. We will examine it here below line by line.
#include "OFELI.h" |
using namespace OFELI; |
int main(int argc, char *argv[]) { |
double L=1; int N=10; |
banner(); |
if (argc > 1) N = atoi(argv[1]); |
Mesh ms(L,N); |
int NbN = N+1; ms.setVerbose(10); cout << ms; |
TrMatrix<double> A(NbN); Vect<double> b(ms); |
b.set("16*pi*pi*sin(4*pi*x)"); |
double h = L/double(N); b *= h; |
for (int i=2; i<NbN; i++) { A(i,i ) = 2./h; A(i,i+1) = -1./h; A(i,i-1) = -1./h; } |
A(1,1) = 1.; A(1,2) = 0.; b(1) = 0; A(NbN,NbN) = 1.; A(NbN-1,NbN) = 0.; b(NbN) = 0; |
A.Solve(b); |
cout << "\nSolution :\n"<< b; Vect<double> sol(ms); sol.set("sin(4*pi*x)"); cout << "Error = " << (b-sol).getNormMax() << endl; |
return 0; } |
M E S H D A T A =================== Space Dimension : 1 Number of nodes : 11 Number of elements : 10 Number of sides : 0 Solution : 1 0.00000000e+00 2 1.08674760e+00 3 6.71646957e-01 4 -6.71646957e-01 5 -1.08674760e+00 6 -1.62832710e-15 7 1.08674760e+00 8 6.71646957e-01 9 -6.71646957e-01 10 -1.08674760e+00 11 0.00000000e+00 Error = 1.35691088e-01
![]() |
![]() |