Orar semigroup #2

Orar semigroup #2

[CN] 20 octombrie - Lab 2

//Prob 1 : primul grafic f(x) - cu rosu; Ln - cu verde; graficul al doilea - eroarea

X =.; X[i_, n_] := -1 + 2 i/n;
l[i_, n_, x_] :=
  Product[If[i == j, 1, (x - X[j, n])/(X[i, n] - X[j, n])], {j, 0,
    n}];
L[f_, n_, x_] := Sum[f[X[i, n]]*l[i, n, x], {i, 0, n}];
n = 15; f[x_] := Sin[Pi * x];
Plot[Evaluate[{f[x], L[f, n, x]}], {x, -1, 1},
 PlotStyle -> {RGBColor[1, 0, 0], RGBColor[0, 1, 0]}]
Plot[Evaluate[Abs[f[x] - L[f, n, x]]], {x, -1, 1}, PlotRange -> All]

//Prob 2 : primul grafic f(x) - cu rosu; Ln - cu verde; graficul al doilea - eroarea
X =.; X[i_, n_] := -1 + 2 i/n;
l[i_, n_, x_] :=
  Product[If[i == j, 1, (x - X[j, n])/(X[i, n] - X[j, n])], {j, 0,
    n}];
L[f_, n_, x_] := Sum[f[X[i, n]]*l[i, n, x], {i, 0, n}];
n = 15; f[x_] := 1/(1 + 25*x^2);
Plot[Evaluate[{f[x], L[f, n, x]}], {x, -1, 1},
 PlotStyle -> {RGBColor[1, 0, 0], RGBColor[0, 1, 0]}]
Plot[Evaluate[Abs[f[x] - L[f, n, x]]], {x, -1, 1}, PlotRange -> All]

//Prob 3 : primul grafic f(x) - cu rosu; Ln - cu verde; graficul al doilea - eroarea
X =.; X[i_, n_] := Cos[(2 i + 1)*Pi/(2 n + 2)];
l[i_, n_, x_] :=
  Product[If[i == j, 1, (x - X[j, n])/(X[i, n] - X[j, n])], {j, 0,
    n}];
L[f_, n_, x_] := Sum[f[X[i, n]]*l[i, n, x], {i, 0, n}];
n = 15; f[x_] := 1/(1 + 25*x^2);
Plot[Evaluate[{f[x], L[f, n, x]}], {x, -1, 1},
 PlotStyle -> {RGBColor[1, 0, 0], RGBColor[0, 1, 0]}]
Plot[Evaluate[Abs[f[x] - L[f, n, x]]], {x, -1, 1}, PlotRange -> All]

//Prob 4.2 : primul grafic f(x) - cu rosu; Ln - cu verde; graficul al doilea - eroarea
X =.; X[i_, n_] := -1 + 2 i/n;
l[i_, n_, x_] :=
  Product[If[i == j, 1, (x - X[j, n])/(X[i, n] - X[j, n])], {j, 0,
    n}];
L[f_, n_, x_] := Sum[f[X[i, n]]*l[i, n, x], {i, 0, n}];
n = 20; f[x_] := Abs[x];
Plot[Evaluate[{f[x], L[f, n, x]}], {x, -1, 1},
 PlotStyle -> {RGBColor[1, 0, 0], RGBColor[0, 1, 0]},
 PlotRange -> All]
Plot[Evaluate[Abs[f[x] - L[f, n, x]]], {x, -1, 1}, PlotRange -> All]

//Prob 4.3 : primul grafic f(x) - cu rosu; Ln - cu verde; graficul al doilea - eroarea
X =.; X[i_, n_] := Cos[(2 i + 1)*Pi/(2 n + 2)];
l[i_, n_, x_] :=
  Product[If[i == j, 1, (x - X[j, n])/(X[i, n] - X[j, n])], {j, 0,
    n}];
L[f_, n_, x_] := Sum[f[X[i, n]]*l[i, n, x], {i, 0, n}];
n = 20; f[x_] := Abs[x];
Plot[Evaluate[{f[x], L[f, n, x]}], {x, -1, 1},
 PlotStyle -> {RGBColor[1, 0, 0], RGBColor[0, 1, 0]}]
Plot[Evaluate[Abs[f[x] - L[f, n, x]]], {x, -1, 1}, PlotRange -> All]

//Prob 5 : primul grafic f(x) - cu rosu; Ln - cu verde; graficul al doilea - eroarea
X =.; X[i_, n_] := -1 + 2 i/n;
l[i_, n_, x_] :=
  Product[If[i == j, 1, (x - X[j, n])/(X[i, n] - X[j, n])], {j, 0,
    n}];
L[f_, n_, x_] := Sum[f[X[i, n]]*l[i, n, x], {i, 0, n}];
n = 3; f[x_] := x^3 + 2 x^2 - 17 x + 23;
Plot[Evaluate[{f[x], L[f, n, x]}], {x, -1, 1},
 PlotStyle -> {RGBColor[1, 0, 0], RGBColor[0, 1, 0]},
 PlotRange -> All]
Plot[Evaluate[Abs[f[x] - L[f, n, x]]], {x, -1, 1}, PlotRange -> All]
Simplify[L[f, n, x]]

X =.; X[i_, n_] := -1 + 2 i/n;
l[i_, n_, x_] :=
  Product[If[i == j, 1, (x - X[j, n])/(X[i, n] - X[j, n])], {j, 0,
    n}];
L[f_, n_, x_] := Sum[f[X[i, n]]*l[i, n, x], {i, 0, n}];
n = 3; f[x_] := x^3 + 3 x^2 - 2 x + 20;
Plot[Evaluate[{f[x], L[f, n, x]}], {x, -1, 1},
 PlotStyle -> {RGBColor[1, 0, 0], RGBColor[0, 1, 0]},
 PlotRange -> All]
Plot[Evaluate[Abs[f[x] - L[f, n, x]]], {x, -1, 1}, PlotRange -> All]
Simplify[L[f, n, x]]

X =.; X[i_, n_] := Cos[(2 i + 1)*Pi/(2 n + 2)];
l[i_, n_, x_] :=
  Product[If[i == j, 1, (x - X[j, n])/(X[i, n] - X[j, n])], {j, 0,
    n}];
L[f_, n_, x_] := Sum[f[X[i, n]]*l[i, n, x], {i, 0, n}];
n = 3; f[x_] := x^3 + 3 x^2 - 2 x + 20;
Plot[Evaluate[{f[x], L[f, n, x]}], {x, -1, 1},
 PlotStyle -> {RGBColor[1, 0, 0], RGBColor[0, 1, 0]}]
Plot[Evaluate[Abs[f[x] - L[f, n, x]]], {x, -1, 1}, PlotRange -> All]
Simplify[L[f, n, x]]

X = {1, 2, 3, 4, 5, 6}; f[x_] := x^5; n = Length[X] - 1;
t = Table[0., {i, 1, n + 1}, {j, 1, n + 1}];
For[i = 1, i <= n + 1, i++, t[[i, 1]] = f[X[[i]]];]; MatrixForm[t];
For[j = 2, j <= n + 1, j++,
 For[i = 1, i <= n + 2 - j, i++,
  t[[i, j]] = (t[[i + 1, j - 1]] - t[[i, j - 1]])/(X[[j + i - 1]] -
       X[[i]]);]]
MatrixForm[t]

X = {-1, -1/2, 0, 1/2, 1} ; f[x_] := Sin[Pi*x]; n = Length[X] - 1;
t = Table[0., {i, 1, n + 1}, {j, 1, n + 1}];
For[i = 1, i <= n + 1, i++, t[[i, 1]] = f[X[[i]]];]; MatrixForm[t];
For[j = 2, j <= n + 1, j++,
 For[i = 1, i <= n + 2 - j, i++,
  t[[i, j]] = (t[[i + 1, j - 1]] - t[[i, j - 1]])/(X[[j + i - 1]] -
       X[[i]]);]]
MatrixForm[t]

Newt[f_, x_, n_] :=
  f[X[[1]]] +
   Sum[Product[(x - X[[j]]), {j, 1, i}]*t[[1, i + 1]], {i, 1, n}];
Simplify[Newt[f, x, n]]

X =.; X[i_, n_] := -1 + 2 i/n;
l[i_, n_, x_] :=
  Product[If[i == j, 1, (x - X[j, n])/(X[i, n] - X[j, n])], {j, 0,
    n}];

L[f_, n_, x_] := Sum[f[X[i, n]]*l[i, n, x], {i, 0, n}];
n = 4; f[x_] := Sin[Pi*x];
Simplify[L[f, n, x]]

luni, 20 octombrie 2014 by DlMuresan
Categories: | Leave a comment

Leave a Reply