Numericka integracija

\(\(\(\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \)\( (*\ MODULI\ *) \)\(
\)\(Trapez[n_, a_, b_, f_] := 
      Module[{i, h, 
          int}, 
		h = \((b - a)\)/
            n; \ 
		int = \((h/2)\) \((f[a] + f[b] + 
                  2  Sum[f[a + i\ h], {i, n - 1}])\) // 
            N
					 (*Print["n=", n, "   I=", 
            int]\ *) 
		\ \ \ \ \ \ \ \ \ \ \ \ \ \ ]


    Simpson[n_, a_, b_, f_] := 
      Module[{i, h, n1, int}, 
\ 
        h = N[\((b - a)\)/n]; \ \ \ \ \ n1 = 
          n/2; \ \ \ \ \ \ 
\ \ \ int = \((h/3)\) \((f[a] + f[b] + 
                4\ Sum[f[a + \((2  i - 1)\)\ h], {i, 
                      n1}]
					\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  + \ 
                2\ Sum[f[a + 2  i\ h], {i, n1 - 1}])\)
			 (*\ 
          Print["n=", n, "   I=", 
            int]\ *) 
	\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ]\)\)\)

?Integrate

\(\(\(
\)\(Integrate[Sin[x]/x, x]

    Integrate[Exp[\(-x^2\)], x]

    Integrate[1/\((x^3 - 1)\), x]\)\)\)

f[x_] := 4/(1 + x^2); a = 0; b = 1;
slf = 
      Plot[f[x], {x, a, b}, PlotLabel -> "x->f[x]",  
        DisplayFunction -> Identity];  
    slf2 = Plot[Abs[f''[x]], {x, a, b}, PlotLabel -> "x->|f''[x]|",  
        DisplayFunction -> Identity];
Show[GraphicsArray[{slf, slf2}],  
        DisplayFunction -> $DisplayFunction];
eps = 0.05;  M2 = 8;
n = Floor[(b - a) Sqrt[M2 (b - a)/(12  eps)]] + 1; 
    intZ = Trapez[n, a, b, f];
Print["n=", n, ",  I=", 
      N[Integrate[f[x], {x, a, b}]], ",   I^*", 
      intZ]
Print["x=", 
      xx = Table[a + i (b - a)/n, {i, 0, n}], ",   f[x]=", 
      f[xx]]

Aproksimacije broja Pi trapeznom formulom

a = 0;  b = 1;  M2 = 8;  eps0 = 5;
\(Do[
	\ \ \ \ \ \ eps = eps0/10. ^i; \ \ \ \ 
	\ \ \ \ \ \ n = 
        Floor[\((b - a)\) Sqrt[M2 \((b - a)\)/\((12  eps)\)]] + 
          1; 
\ \ \ \ \ \ \ intZ = \ 
        Trapez[n, a, b, f]; \ \ \ Print["eps=", eps, "   n=", 
        n, "   I*=", intZ, "   E=", 
        N[Abs[intZ - Pi], 5]], 
\ \ \ 	\ \ {i, 6}]\)

Aproksimacije broja Pi Simpsonovom formulom

f''''[x] // Simplify
Plot[Abs[f''''[x]], {x, 0, 1}];

a = 0;  b = 1;  M4 = 96;  eps0 =  .5;
\(Do[
	\ \ \ \ eps = eps0/10. ^i; \ 
      n = Floor[\((b - a)\) \((M4 \((b - a)\)/\((180  eps)\))\)^\((1/4)\)] + 
          1; 
	If[OddQ[n], n = n + 1, ]; \ \ \ 

      intZ = Simpson[n, a, b, f]; \ \ \ 
Print["eps=", 
        eps, "   n=", n, "   I^*=", intZ, "   E=", 
        Abs[intZ - Pi]\ ], 
	\ \ {i, 6}]\)

Z 7.4

f[x_] := Sin[x]^2; a = 0;  b = Pi/4;  M2 = 2; 
    M4 = 8; 
f[x_] := Cos[x]^2; a = 0;  b = Pi/4;  M2 = 2; 
    M4 = 8; 
f[x_] := Sin[x] - Log[x] + Exp[x]; a = 0.2;  b = 1;  M2 = 26; 
    M4 = 3752; 
f[x_] := Sqrt[1 + 2  x]; a = 0;  b = 1;  M2 = 1; 
    M4 = 15; 
f[x_] := x^2/Sqrt[1 - x^2]; a = 0;  b =  .5;  M2 = 5; 
    M4 = 120; 
f[x_] := Sin[x]/x; a = Pi/4;  b = Pi/2;  M2 =  .3; 
    M4 =  .2; 
f[x_] := (5 - x)/(9 - x^2); a = 0;  b = 2;  M2 =  .6; 
    M4 = 8; 
f[x_] := 4  Sqrt[1 -  .75  Sin[x]^2]; a = 0;  b = Pi/2;  M2 = 6; 
    M4 = 78; 
eps =  .00005;
f[x_] := Exp[-x^2/2]/Sqrt[2 Pi]; a = 0;  b = 5;  M2 =  .4; 
    M4 = 1.2; 
al = 45  Pi/180; f[x_] := 1/Sqrt[1 + Sin[al]^2  Sin[x]^2]; a = 0;  
    b = Pi/2;  M2 =  .5; 
    M4 = 4.25; 
  
s =  .5; f[x_] := Cos[Pi x^2/2]; a = 0;  b = s;  M2 = 3.5; 
    M4 = 29.6; 
\(	\ \ \ \ \ \ \(n = 
        Floor[\((b - a)\) Sqrt[M2 \((b - a)\)/\((12  eps)\)]] + 
          1;\)\)
f2 = 
        Plot[f''[x], {x, a, b}, 
          DisplayFunction -> Identity];
f4 = 
        Plot[f''''[x], {x, a, b}, 
          DisplayFunction -> Identity];
Show[GraphicsArray[{f2, f4}], 
        DisplayFunction -> $DisplayFunction];
Print["Trapezna formula"]
        Trapez[n, a, b, f]
n = 
      Floor[(b - a) (M4 (b - a)/(180  eps))^(1/4)] + 
        1
If[OddQ[n], n = n + 1];
Print["Simpsonova formula"]
  Simpson[n, a, b, f]

Clear[x];
FindMinimum[f''''[x], {x, b}]