|
Hi,
can you help me writing the following programm in C++, please?
The problem is quite simple:
1) the programm asks user to enter numbers N1 , N2 (integers)
2) then it defines constants h1 = pi/(N1 - 1), h2 = pi/(N2 - 1)
3) then it iniciates square matrix "A", where number of rows is equal to number of columns = (N1 - 2)(N2 - 2):
D A B 0 0 0 0 0 0 . . . 0
A D A B 0 0 0 0 0 . . . 0
B A D A B 0 0 0 0 . . . 0
0 B A D A B 0 0 0 . . . 0
0 0 B A D A B 0 0 . . . 0
.
.
. ETC,
where
D = -2(1/h_{1}^2 + 1/h_{2}^2) + 12
A = 1/h_{1}^2
B = 1/h_{2}^2
4) solves A X = B (want to get X), where
X denotes the vector:
X = [u(1,1), u(2,1), ... ,u(N1-1,1),u(1,2),u(2,2), ... , u(N1 - 1,2), ... , u(1,N2-1), u(2,N2-1), ... , u(N1-1,N2-1)]
by the way: u(i,j) is function approximated at (i,j)-th cell of its domain, i.e. u(i,j) := u(ih1,jh2) :-)
B denotes the vector:
B = [f(1,1), f(2,1), ... ,f(N1-1,1),f(1,2),f(2,2), ... , f(N1 - 1,2), ... , f(1,N2-1), f(2,N2-1), ... , f(N1-1,N2-1)],
where f(i,j) := 12 - sin(2ih1)sin(3ih2)
5) writes the solution (vector X) in a file "output.dat"
|
|
|
|
|