(** Zadacha 1 **)
(** Variant 18 **)
Print["Zadacha 1"]
X = {0, 21.1, 37.8, 54.4, 71.1, 87.8, 100};
Y = {1.79, 1.13, 0.696, 0.519, 0.338, 0.321, 0.296};
n = Length[X];
plotList = ListPlot[Table[{X[[i]], Y[[i]]}, {i, 1, n}], PlotRange -> {0, 2}, PlotMarkers ->■];
Error[k_, u_, w_]  := u * X[[k]] + w - 1/Y[[k]]
Func[u_, w_] := (∑_(i=1)^n)Error[i, u, w]^2
solution = Solve[
{
D[Func[u, w], u] ==0,
D[Func[u, w], w] ==0
}, {u, w}]
a = 1/u /. solution[[1]];
b = w*a /. solution[[1]];
f[x_] = a / (x+b)
plotFunc=Plot[f[x], {x, 0, 100}];
Show[plotList, plotFunc]

(** Zadacha 2 **)
Print["Zadacha 2"]
Clear[X]
Clear[Y]
X = {1, 1.25, 1.4};
Y = {5, 0, 1};
T = 0.5;
len = Length[X];
plotPoints = ListPlot[Table[{X[[i]], Y[[i]]}, {i,1, len}],PlotRange -> {{0.5, 2}, {-1, 6}},PlotMarkers ->■];
(** Da smenim intervala v 2pi **)
T = 4*Pi*(X - 1);
trigPoly[t_] := a0 + a1*Cos[t] + b1*Sin[t]
equations = Table[trigPoly[T[[i]]] == Y[[i]], {i, 1, len}];
coefficients = Solve[
equations, {a0, a1, b1}];
f[x_] = trigPoly[4*Pi*(x-1)] /. coefficients[[1]]
plotFunc = Plot[f[x], {x, 0.5, 2}];
Show[plotPoints, plotFunc]

(** Zadacha 3 **)
ClearAll[n, f]
Print["Zadacha 3, formula na pravougulnici"]
start = 0;
end = Pi/2;
f[x_] = 8+4Cos[x];
(** Define epsilon **)
Print["Epsilon="]
epsilon = 0.000001
(** End epsilon **)
digits = RealDigits[epsilon][[2]];
(** 2-ra Proizodna : -4Cos[x], nai-golqma stoinost po modul v x=0 -> 1 **)
n = (
result = 0;
While[result^2 < (end-start)^3 / (24*epsilon), result++];
result
);
h = (end - start) / n;
nodes = Table[start+ i*h, {i, 0, n}];
Print["Real value:"]
N[Integrate[f[x], {x, 0, Pi/2}], -digits + 3]
Print["Approximation:"]
Qrect = (
result = 0;
Do[result += f[(nodes[[i]]+nodes[[i+1]] )/ 2], {i,1, n}];
result *= h;
N[result, -digits + 3]
)