calculus and analysis – Weird result when calculating the deviation of 2 functions (2 examples)

In the final step of this program it takes a huge amount of time to complete
and the result I get is a bit weird. I was waiting for some number in scientific notation format.

``````f(x_) := 1/(1 + x^2) + Log(x + 1);
xM = 10;
xm = 0; (* Domeniul de definitie, extins in afara lui (-1,1)*)

g1 = Print(Plot(f(x), {x, xm, xM}, PlotStyle -> Blue));
Na = 40;
For(
k = 0, k <= Na, k++,
c(k) = 2/Na !(
*UnderoverscriptBox(((Sum)), (j = 1), (Na))(f(((Cos(
*FractionBox((((2  j - 1))
*FractionBox(((Pi)), (2))), (Na)))))
*FractionBox((xM - xm), (2)) +
*FractionBox((xM + xm), (2))) ((Cos(
*FractionBox((k ((2  j - 1))
*FractionBox(((Pi)), (2))), (Na)))))))
);
(*Se calculeaza coeficienti de interpolare Chebyshev pentru f(x) -
CDT *)
p(x_) := !(
*UnderoverscriptBox(((Sum)), (n = 1), (Na))(c(n) Cos(
n ArcCos(2
*FractionBox((x - xm), (xM - xm)) - 1)))) + 1/2 c(0);
(*Aici incepe derivarea numerica*)
b(Na + 1) = 0;
b(Na) = 0;
For(k = Na, k > 0, k--,
b(k - 1) = b(k + 1) + 2 k c(k);
);
dp(x_) := 2/(xM - xm)*(!(
*UnderoverscriptBox(((Sum)), (n = 1), (Na))(b(n) Cos(
n *ArcCos(2
*FractionBox((x - xm), (xM - xm)) - 1)))) + 1/2 b(0));
df(x_) := !(
*SubscriptBox(((PartialD)), (x))(f(
x))); (*Derivata analitica pentru comparatie *)
g3 =
Plot(df(x), {x, xm, xM}, PlotStyle -> Red, PlotRange -> All);
g4 = Plot(dp(x), {x, xm, xM}, PlotStyle -> Green, PlotRange -> All);
Print(Show(g3, g4));

Nm = 500; (*Nr de puncte in care se calculeaza abaterea*)
lst = {};
For(i = 1, i < Nm, i++,
r(i) = xm + i (xM - xm)/Nm;

AppendTo(lst, Abs(df(r(i)) - dp(r(i))));
);
Print(Max(Sort(lst)));
``````

The block that is giving me issues is:

``````Nm=500; (*Nr de puncte in care se calculeaza abaterea*)
lst={};
For(i=1, i<Nm, i++,
r(i)=xm+i (xM-xm)/Nm;

AppendTo(lst, Abs(df(r(i))-dp(r(i))));
);
Print(Max(Sort(lst)))
``````