(*Pergunta 1*)(* Temos a função iteradora*)

g[x_] := 1/2 Cos[x] +  1

g'[x]

Sendo (Subscript[x, 0])  = 1,  deacordo com a alínea anterior,  
    temos  | z - (Subscript[x, 0]) | ≤1/2.  Logo ,  
    para qualquer n,  
    verifica - se   | z - (Subscript[x, n]) | ≤1/2 (L^n),  
    onde L = (max_(x ∈  ℝ))|g' (x)| = 1/2.  Logo,  
    para que se verifique   | 
      z - (Subscript[x, n]) | ≤ϵ,  devemos ter ((((1/2)))^(n + 1))≤∈,  donde n + 
          1 > (Subscript[Log, 1/2])∈, ou seja,  
    n > (Subscript[Log, 1/2]) ∈ -1.

(* Para aproximar o valor de z,  
          devemos resolver a equação 1 +  
              1/2 cos (z) = z .  Logo *)

f[x_] = 1 +  1/2 Cos[x] - x

f'[x]

x1 = 1 - f[1]/f'[1]

N[%]

x2 = x1 - f[x1]/f'[x1]

N[%]

(* Temos as funções *)

F1[x1_, x2_, x3_] := x1^2 - x2^2 + x3^3 + 3

F2[x1_, x2_, x3_] := 4 x1  + x2^3 + x3 - 2

F3[x1_, x2_, x3_] := x1* x3 + 5 x2  - 3

Jac = {{D[F1[x1, x2, x3], {x1, 1}], D[F1[x1, x2, x3], {x2, 1}], 
          D[F1[x1, x2, x3], {x3, 1}]}, {D[F2[x1, x2, x3], {x1, 1}], 
          D[F2[x1, x2, x3], {x2, 1}], 
          D[F2[x1, x2, x3], {x3, 1}]}, {D[F3[x1, x2, x3], {x1, 1}], 
          D[F3[x1, x2, x3], {x2, 1}], D[F3[x1, x2, x3], {x3, 1}]}}

A = 
      MatrixForm[Jac] /. {x1 -> 1, x2 -> 0, 
          x3 -> -1}

h = {-F1[1, 0, -1], -F2[1, 0, -1], -F3[1, 
            0, -1]}

A' = MatrixForm[{{4, 0, 1}, {-1, 5, 1}, {2, 0, 3}}]

h' = {-1, 4, -3}

v0 = (-1, -1, -1)

v1 = {0, 0, 0}

v1[[1]] = (-1 - (-1))/4

v1[[2]] = (4 - (-1) - 0)/5

v1[[3]] = (-3 - 0)/3

v2 = {0, 0, 0}

v2[[1]] = 0

v2[[2]] = 1

v2[[3]] = -1

AA = {{4, 0, 1}, {-1, 5, 1}, {2, 0, 3}}

v1 = LinearSolve[AA, h']

x0 = {1, 0, -1}

x1 = x0 + v1

A' = MatrixForm[{{2, 0, 3}, {-1, 5, 1}, {4, 0, 1}}]

L = MatrixForm[{{1, 0, 0}, {-1/2, 1, 0}, {2, 0, 1}}]

U = MatrixForm[{{2, 0, 3}, {0, 5, 5/2}, {0, 0, -5}}]

f01 = (3 - 1)/0.25

f12 = (7 - 3)/0.25

f012 = (f12 - f01)/0.5

P2[x_] := 
      1 + f01*(x - 0.5) + f012*(x - 0.5)*(x - 0.75)

P2[0.7]

xi = {0, 0.25, 0.5, 0.75, 1}

fi = {7, 4, 1, 3, 7}

ϕ1[x_] := (x - 0.5)^2

ϕ01 = (∑_(i = 1)^5) ϕ1[xi[[i]]]

ϕ11 = (∑_(i = 1)^5) ϕ1[xi[[i]]]^2

ϕ00 = 5.

Mat = {{ϕ00, ϕ01}, {ϕ01, ϕ11}}

b1 = (∑_(i = 1)^5) fi[[i]]

b2 = (∑_(i = 1)^5) fi[[i]]*ϕ1[xi[[i]]]

b = {b1, b2}

Sol = LinearSolve[Mat, b]

Minimo = (∑_(i = 1)^5)(fi[[i]] - Sol[[1]] - 
              Sol[[2]]*ϕ1[xi[[i]]])^2

A = Table[0, {i, 1, 3}, {j, 1, 3}]

A[[1]] = {1, 1, 1}

A[[2]] = {0.25, 0.5, 0.75}

A[[3]] = {0.25^2, 0.5^2, 0.75^2}

MatrixForm[A]

b1 = 1

b2 = (1 - 0)/2

b3 = (1 - 0)/3

b = {b1, b2, b3}

Pesos = LinearSolve[A, b]

Exacto = Integrate[x^3, {x, 0, 1}]

Aprox = 
      Pesos[[1]]*(1/4)^3 + Pesos[[2]]*(1/2)^3 + 
        Pesos[[3]]*(3/4)^3

(*Como 1/4 = 0.25,  
      a fórmula tem grau 3.  Verifiquemos se tem grau 4*)

Exacto = Integrate[x^4, {x, 0, 1}]

Aprox = 
      Pesos[[1]]*(1/4)^4 + Pesos[[2]]*(1/2)^4 + 
        Pesos[[3]]*(3/4)^4

Pesos[[1]]*fi[[2]]/(1 + xi[[2]]) + 
      Pesos[[2]]*fi[[3]]/(1 + xi[[3]]) + 
      Pesos[[3]]*fi[[4]]/(1 + xi[[4]])

f1[x_, y1_, y2_] := y2

f2[x_, y1_, y2_] := Cos[x]*y1 + y2

y10 = 1; y20 = 1

y11 = y10 + h*f1[0, y10, y20]

y21 = y20 + h*f2[0, y10, y20]