\(Rješavanje\ nelinearnih\ jednadžbi\)

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; sgn = Sign[f[xP]]; 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; 
        sgn = Sign[
            f[xP]]; 
		\ \ \ \ \ \ \ \ \ \ \ \ \ \ gr = \((xD - xL)\)/
            2; 
		\ \ \ \ \ \ \ \ \ \ \ \ \ \ Print["k=", 
          k, "  xL=", xL, "   xD=", xD, "  xP=", \ 
          xP, "  gr=", 
          gr]], 
	\ \ Print["Interval nije dobro odredjen"]
\ \ \ \ \ ]\)

\(f[x_] := x\ Cos[x] - Log[x]; \ a = 0.1; b = 20; 

    slf = Plot[f[x], {x, a, b}, DisplayFunction -> Identity]; 

    sld = Plot[\(f'\)[x], {x, a, b}, DisplayFunction -> Identity]; 

    Show[GraphicsArray[{slf, sld}]]; 
FindRoot[x^3 - x - 4, {x, 2}]\)

Metoda jednostavnih iteracija

f[x_] := Exp[x] - x - 5/4
Plot[f[x], {x, 0, 1}];

fi[x_] := Exp[x] - 5/4
fi[x_] := Log[x + 5/4] 
x0 = 1. ;

Sukcesivne iteracije

x1 = fi[x0]
x0 = x1

Program: Metoda jednostavnih iteracija

n = 0;  x0 = 1. ; gr = Abs[x0 - fi[x0]];   q =  .8;  eps =  .005;  
    m1 =  .1;
  
  
  
While[n = n + 1;  x1 = fi[x0]; gr1 = Abs[x1 - x0] q/(1 - q); 
      Print["n=", n, "  x", n, "=", x1, "  f(x", n, ")=", 
        f[x1],  "  gr1=", gr1 , "   gr2=", 
        gr q^n/(1 - q),  "  gr3=", 
        Abs[f[x1]]/m1]; 
gr1 > eps, x0 = x1]

Newtonova metoda

f[x_]  :=  Exp[-x]  +  x^2  -  2;
slf = 
            Plot[f[x], {x,  .5, 2}, DisplayFunction -> Identity];
slf1 = 
            Plot[f'[x], {x,  .5, 2}, DisplayFunction -> Identity];
slf2 = 
            Plot[f''[x], {x,  .5, 2}, 
              DisplayFunction -> Identity];
Show[GraphicsArray[{slf, slf1, slf2}], 
            DisplayFunction -> $DisplayFunction];

Program: Newtonova metoda

n = 0;  x0 = 2. ; gr = Abs[x0 - fi[x0]];    eps =  .000005;  
    m1 = Abs[f'[2]]; 
    M2 = Abs[f''[ .5]];
  
  
While[n = n + 1;  x1 = x0 - f[x0]/f'[x0]; 
      gr = (M2/(2  m1)) (x1 - x0)^2; 
      Print["n=", n, "  x", n, "=", x1, "  f(x", n, ")=", 
        f[x1],  "  gr=", gr , "   gr1=", 
        Abs[f[x1]]/m1]; 
gr > eps, x0 = x1]

f(x)=arctg x

f[x_]  :=  ArcTan[x];
slf = 
            Plot[f[x], {x, -2, 2}, DisplayFunction -> Identity];
slf1 = 
            Plot[f'[x], {x, -2, 2}, 
              DisplayFunction -> Identity];
slf2 = 
            Plot[f''[x], {x, -2, 2}, 
              DisplayFunction -> Identity];
Show[GraphicsArray[{slf, slf1, slf2}], 
            DisplayFunction -> $DisplayFunction];