<< Statistics`ContinuousDistributions`
<< Graphics`Graphics`
<< Graphics`MultipleListPlot`

Generiranje podataka - eksponencijalna funkcija

f[t_] :=  .5 Exp[ .2 t]
m = 100;   h =  .1;
slf = 
        Plot[f[t], {t, 0, 10}, 
          DisplayFunction -> Identity];
t = Table[h i, {i, 1, m}];
y = 
        Table[f[t[[i]]] + Random[NormalDistribution[0,  .5]] , {i, 1, 
            m}];
pod = 
        Table[ {t[[i]], y[[i]]}, {i, 1, 
            m}];
TableForm[Transpose[pod]]
slpod = 
        ListPlot[pod, PlotStyle -> AbsolutePointSize[3], 
          DisplayFunction -> Identity];
Show[slf,  slpod, 
        DisplayFunction -> $DisplayFunction];

Stopa rasta

G[c_] := 
      Apply[Plus, t Exp[2  c t]] 
          Apply[Plus, y Exp[c t]]/Apply[Plus, Exp[2  c t]] - 
        Apply[Plus, t y Exp[c t]]
Plot[G[c], {c, 0,  .4}];
Plot[G'[c], {c, 0,  .4}];

Primjeri

f[x_] := 
      x^3 + 4  x^2 - 10;  a = 1; b = 
      2; eps =  .0005;n_max = 
      20;

f[x_] := x^3 - 7  x^2 + 14  x - 6;   a = 1;  b = 2;  eps =  .0005; 
    n_max = 20;

f[x_] := Exp[x] - x^2 + 3  x - 2;  a = 0;  b = 1;

f[x_] := 2 + Cos[Exp[2] - 2] - Exp[x];  a =  .5;  b = 1.5;

f[x_] := Exp[x] + 2^(-x) + 2  Cos[x] - 6;  a = 1;  
    b = 2;

f[x_] := 2 x Cos[2  x] - (x - 2)^2;  a = 2;  b = 4;

Metoda bisekcije

f[x_] := x^3 - 6  x + 2;
a = 0;  b = 1.5;  eps =  .01; k = 0;

\(If[f[a] f[b] < 0, 
\ \ \ \ \ \ \ xL = a; \ xD = b; \ 
      xP = \((xL + xD)\)/2; gr = \((xD - xL)\)/2; 

      Print["k=", k, "  xL=", xL, "  xD=", xD, "  xP=", \ 
        xP, "  gr=", gr]; 
		While[gr > eps, 
        k = k + 1; 
		\ \ \ \ \ \ \ \ \ \ \ \ \ \ If[f[xL] f[xP] < 0, 
          xD = 	xP, 
          xL = xP]; 
			\ \ \ \ \ \ \ \ \ \ \ \ xP = \((xL + xD)\)/
            2; 
		\ \ \ \ \ \ \ \ \ \ \ \ \ \ gr = \((xD - xL)\)/
            2; 
		\ \ \ \ \ \ \ \ \ \ \ \ \ \ Print["k=", 
          k, "  xL=", xL, "   xD=", xD, "  xP=", \ 
          xP, "  gr=", 
          gr]], 
	\ \ Print["Interval nije dobro odredjen"]
\ \ \ \ \ ]\)

Modul Bisekcija

\(Bisekcija[f_, a_, b_, eps_, It_, P_] := 
      Module[{k = 0, xL, xD, xP, gr}, 
If[
          f[a] f[b] < 0, 
\ \ \ \ xL = a; \ xD = b; \ xP = \((xL + xD)\)/2; 
          gr = \((xD - xL)\)/2; 
\ \ \ If[P == 1, 
            Print["k=", k, "  xL=", xL, "  xD=", 
              xD, "  xP=", \ xP, "  gr=", gr]\ ]; 
		While[
            gr > eps, 
            k = k + 1; 
		\ \ \ \ \ \ \ \ \ \ \ \ \ \ If[f[xL] f[xP] < 0, 
              xD = 	xP, 
              xL = xP]; 
			\ \ \ \ \ \ \ \ \ \ \ \ xP = \((xL + xD)\)/
                2; 
		\ \ \ \ \ \ \ \ \ \ \ \ \ \ gr = \((xD - xL)\)/
                2; 
		\ \ \ \ \ \ \ \ \ \ \ \ \ If[P == 1, \ 
              Print["k=", k, "  xL=", xL, "   xD=", 
                xD, "  xP=", \ xP, "  gr=", 
                gr]]], 
	\ \ Print["Interval nije dobro odredjen"]
\ \ \ \ \ ]; \ {k, 
          xP}
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ]\)

Koristenje

Bisekcija[f, a, b,  .0000005, 10, 0]