Off[General::"spell"];
Off[General::"spell1"];

Steepest Descent metode "SteepestDescent" med tilhørende Options

Options[SteepestDescent] = {MaxIterations ->  30000, 
        Epsilon ->  10^(-6), 
        SecantPrecision ->  10^(-12)}

\(\(SteepestDescent[f_, x0_, {var_, t1_, t2_}, opts___] := 
        Module[
{k, tk, gk, absgk, max, 
            xkvec}, 
ϵ = \(Epsilon /. 
                Flatten[{opts}]\) /. 
              Options[SteepestDescent]; 
xk = 
            x0; 
k = 
            0; 
xkvec = {xk}; 
gkvec = {}; 
max = \(MaxIterations /. Flatten[{opts}]\) /. 
              Options[SteepestDescent]; 

While[
              k < max, \(k++\); 

gk = 
                SetPrecision[Grad[f, xk], 
                  90]; 

tk = \((t /. 
                    secantFindRoot[\(-gk . Grad[f, xk - t\ gk]\), {var, t1, 
                        t2}, Precision -> \ 10^\ \((\(-90\))\), 
                      MaxIterations -> \ 500, 
                      WorkingPrecision -> \ 
                        80])\); 

xk = 
                xk - tk\ gk; 
absgk = 
                Norm[gk]; 

If[
                Mod[k, 500] == 
                  0, 
\(Print["k: ", 
                    PaddedForm[k, 
                      Length[IntegerDigits[max]]], "	 x1: ", \ 
                    pretty[xk[\([1]\)] // N], "	 x2: ", \ 
                    pretty[xk[\([2]\)] // 
                        N], \*""\t ||(g^k)||: "", 
                    pretty[absgk // 
                        N]];\)
]; 

xkvec = 
                Append[xkvec, xk]; 

If[
                absgk ≤ \ ϵ, 
Print["Desired Epsilon reached"]; 
Break[]
];
]
Print["k: ", 
              PaddedForm[k, Length[IntegerDigits[max]]], "	 x1: ", \ 
              pretty[xk[\([1]\)] // N], "	 x2: ", \ 
              pretty[xk[\([2]\)] // N], \*""\t ||(g^k)||: "", 
              pretty[absgk // N]]; 
xkvec = 
            Append[xkvec, xk]
];\)\)