ULOHA 2 :

-Δu = sin y ( x^2 - 2 )
u(x,0) = 4x
u(0,y) = 0
u(x,π) = 4x
u(π,y) = π^2 sin y + 4π
u(x,y) = x^2 sin y + 4x

f[x_, y_] := Sin[y]*(x^2 - 2);
p[x_] := 4*x;
r[y_] := 0;
q[x_] := 4*x;
s[y_] := π^2*Sin[y] + 4*π;
pres[x_, y_] := x^2*Sin[y] + 4*x;
a = π;
n = 4;
h = a/(n + 1);
A = IdentityMatrix[n*n];
PS = Table[0, {i, 1, n*n}];

Do[
Do[{
k = 
            i*n + j; 
PS[[k]] = 
            N[h^2*f[(i + 1)*h, j*h]]; 
A[[k, k]] = 
            4; 
If[(i == 0), 
            PS[[k]] = PS[[k]] + r[j*h], 
            A[[k, k - 
                    n]] = -1]; 
If[(i == (n - 1)), PS[[k]] = PS[[k]] + s[j*h], 
            A[[k, k + n]] = -1]; 
If[(j == 
                1), PS[[k]] = PS[[k]] + p[(i + 1)*h], 
            A[[k, k - 1]] = -1]; 
If[(j == 
                n), PS[[k]] = PS[[k]] + q[(i + 1)*h], 
            A[[k, k + 
                    1]] = -1];
}, 
{j, 1, n}], {i, 0, 
        n - 1}]

Print[MatrixForm[A]];
Print[PS];

Ries = LinearSolve[A, PS]

pre = Table[0, {i, 1, n*n}];
Do[
        Do[{k = i*n + j, pre[[k]] = N[pres[(i + 1)*h, j*h]]}, {j, 1, 
            n}, {i, 0, n - 1}]];

Print[pre];

vysledky = 
        Table[{i, pre[[i]], Ries[[i]], 
            Abs[(pre[[i]] - Ries[[i]])]}, 
{i, 
            1, n*n}];
Print["cislo uzlu    Pres ries    Num ries    chyba"]
PaddedForm[TableForm[vysledky], {5, 3}]

<< Graphics`Graphics3D`

plopr = Plot3D[pres[x, y], {x, 0, 4}, {y, 0, 4}]

aprox = {Table[Ries[[i]], {i, 1, n}], 
        Table[Ries[[n + i]], {i, 1, n}], 
        Table[Ries[[2*n + 1]], {i, 1, n}]}

graprox = BarChart3D[aprox]

aprpl = ListPlot3D[aprox]