\(Parcijalne\ diferencijalne\ jednadbe\)

\(\( (*\ Gauss - Seidelova\ metoda\ *) 

    GS[a_, b_, n_, it_] := 
      Module[{i, k, xs, xn}, \ xs = Table[0, {i, n}]; xn = xs; 

        Do[
\ \ \ \ \ \ \ \ 
          Do[
\ \ \ \ \ \ \ \ \ \ \ \ 
            xn[\([i]\)] = 
              \((b[\([i]\)] - Sum[a[\([i, j]\)] xn[\([j]\)], {j, i - 1}] - 
                    Sum[a[\([i, j]\)] xs[\([j]\)], {j, i + 1, n}])\)/
                a[\([i, i]\)], 
				\ \ \ \ \ \ {i, n}]; 

           (*\ \ \ \ \ \ \ \ \ \ Print["It_", k, " = ", N[xn]]; *) \ 
          xs = xn, 
	\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {k, it}]; \ 
        x = xn // N; 

        \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ]\)\)

Plot3D[
      6.65  y (y - 6) (x^2 - 16)/144, {x, -4, 4}, {y, 0, 6}, 
      Shading -> False, PlotPoints -> 20, Ticks -> None];

Plot3D[
      6.65  y (y - 6) (x^2 - 16)/144, {x, -4, 4}, {y, 0, 6}, 
      Shading -> False, PlotPoints -> 8];

\(x0 = 2; \ y0 = 1; 
r[x_, y_] := Sqrt[\((x - x0)\)^2 + \((y - y0)\)^2]; 
    
sl1 = Plot3D[1/r[x, y], {x, \(-2\), 5}, {y, \(-2\), 5}, 
        DisplayFunction -> Identity]; 

    sl2 = Plot3D[Log[r[x, y]], {x, \(-2\), 5}, {y, \(-2\), 5}, 
        DisplayFunction -> Identity]; 

    sl3 = Plot3D[Log[1/r[x, y]], {x, \(-2\), 5}, {y, \(-2\), 5}, 
        DisplayFunction -> Identity]; 

    Show[GraphicsArray[{sl1, sl2, sl3}], \ 
      DisplayFunction -> $DisplayFunction]\)

Metoda konačnih diferencija

\(
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  (*\ Definiranje\ simetrične\ vrpčaste\ matrice\ *) 

    n = 5; m = 1; 
a = Table[0, {i, n}, {j, n}]; \ b = Table[1, {i, n}]; 
\ 
    Do[a[\([i, i]\)] = 2, \ {i, n}]; \ 

    Do[\ a[\([i + 1, i]\)] = 1; a[\([i, i + 1]\)] = 1, \ {i, n - 1}]\)\(MatrixForm[a]\ 


    \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  (*\ Gauss - Seidelova\ metoda\ *) \)\(it = 50; 
tt = Timing[GS[a, b, n, it]]; 

    Print["Rjeenje = ", \ N[x, 3]]


    \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 
     (*\ Kontrola\ *) \)Print["Greska = ", Max[Abs[a.x - b]] // N,  
      "        Vrijeme = ", tt[[1]]]

Primjer 9.2

\(n = 20; m = 5; 
a = Table[0, {i, n}, {j, n}]; \ 
    b = Table[\(-2\), {i, n}]; 
\ Do[a[\([i, i]\)] = \(-4\), \ {i, n}]; \ 

    Do[\ If[i < 5, a[\([i, i + 1]\)] = 1, \ 
        If[Mod[i, 5] == 0, a[\([i, i + 1]\)] = 0, a[\([i, i + 1]\)] = 1]], 
      \ {i, n - 1}]\)Do[a[[i + 1, i]] = a[[i, i + 1]], {i, n - 1}]Do[ a[[i + 5, i]] = 1; 
      If[i < 6, a[[i, i + 5]] = 2, a[[i, i + 5]] = 1],  {i, n - 5}]
      \(MatrixForm[a]\ 

\ \ \ \ \ \ \ \ \ \ \ \ \ 
     (*\ Gauss - Seidelova\ metoda\ *) \)\(it = 50; 
tt = Timing[GS[a, b, n, it]]; \ 

    Print["Rjeenje = ", \ N[x, 3]]


    \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 
     (*\ Kontrola\ *) \)Print["Greska = ", Max[Abs[a.x - b]] // N,  
      "        Vrijeme = ", tt[[1]]]

x

\(\(

\ 
    u = Table[{\ 0, x[\([\(-j\) + 21]\)], x[\([\(-j\) + 16]\)], 
          x[\([\(-j\) + 11]\)], x[\([\(-j\) + 6]\)], x[\([\(-j\) + 11]\)], 
          x[\([\(-j\) + 16]\)], x[\([\(-j\) + 21]\)], 0}, {j, 5}]; \ 

    TableForm[u]
		\)\)

\(\(
ListPlot3D[u]\)\)

\(
\)

\( (*\ 
      Cholesky\ faktorizacija\ vrpcaste\ matrice\ A = L\ Transpose[L]\ *) 
	
    Do[
	If[a[\([k, m + 1]\)] > 0, \ 
			
        L[\([k, m + 1]\)] = Sqrt[a[\([k, m + 1]\)]\ ]\ ; 
			
        p = Min[k + m, n]; 
			
        Do[\ 
				\ 
          L[\([i, k - i + m + 1]\)] = \ 
            a[\([i, k - i + m + 1]\)]/L[\([k, m + \ 1]\)]; 
					
          Do[\ 
				
            a[\([i, j - i + m + 1]\)] = \ \ \ 
              a[\([i, j - i + m + 1]\)] - 
                L[\([i, k - i + m + 1]\)]\ \ L[\([j, k - j + m + 1]\)]

            				\ , {j, k + 1, i}]
			, {i, k + 1, p}], \ ]

      	\ , {k, n}\ ]\)MatrixForm[L] MatrixForm[a]