(* ::Package:: *)

(************************************************************************)
(* This file was generated automatically by the Mathematica front end.  *)
(* It contains Initialization cells from a Notebook file, which         *)
(* typically will have the same name as this file except ending in      *)
(* ".nb" instead of ".m".                                               *)
(*                                                                      *)
(* This file is intended to be loaded into the Mathematica kernel using *)
(* the package loading commands Get or Needs.  Doing so is equivalent   *)
(* to using the Evaluate Initialization Cells menu command in the front *)
(* end.                                                                 *)
(*                                                                      *)
(* DO NOT EDIT THIS FILE.  This entire file is regenerated              *)
(* automatically each time the parent Notebook file is saved in the     *)
(* Mathematica front end.  Any changes you make to this file will be    *)
(* overwritten.                                                         *)
(************************************************************************)



n=125;
{a,b}={0.0,1.0};
h=(b-a)/n;
\[ScriptCapitalA]= SparseArray[{
Band[{1,1}]->2.0,
Band[{2,1}]->-1.0,
Band[{1,2}]->-1.0
},
{n-1,n-1}
];
f[x_]= 3 Sin[x] + 3 Cos[x]- 4 Cos[2 x]-Sin[6 x];
\[ScriptF]=Table[f[x],{x,a+h,b-h,h}];
\[ScriptU]= LinearSolve[\[ScriptCapitalA],h^2 \[ScriptF]];


SetAttributes[SORUpDate1DRedBlack, HoldFirst]
SORUpDate1DRedBlack[u_,\[ScriptF]_,h_,\[Omega]_]:=Module[
{i,n=Length[\[ScriptF]]},
u[[1]]=(1-\[Omega])u[[1]]+\[Omega]/2 (h^2 \[ScriptF][[1]]+u[[2]]);
u[[n]]=(1-\[Omega])u[[n]]+\[Omega]/2 (h^2 \[ScriptF][[n]]+u[[n-1]]);
Do[
u[[i]]=(1-\[Omega])u[[i]]+\[Omega]/2 (h^2 \[ScriptF][[i]]+u[[i-1]]+u[[i+1]]),
{i,3, n-1,2}];
Do[
u[[i]]=(1-\[Omega])u[[i]]+\[Omega]/2 (h^2 \[ScriptF][[i]]+u[[i-1]]+u[[i+1]]),
{i,2,n-1,2}];
]



