Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // minimos cuadrados
- // A'A x = A' b
- // si rang(A) = n, R no singular
- // Rx = Q'b, se resuelve por sust. regresiva
- function [Qu, R]= factorizacionQR(A)
- [m, n] = size(A)
- Qu = zeros(A)
- R = zeros(n,n)
- Qu(:, 1) = A(:, 1)
- R(1,1) = norm(A(:, 1), 2)
- Qu(:, 1) = Qu(:, 1) / R(1,1)
- for j = 2:n
- //Lleno la columna j de R
- for i = 1:j-1
- R(i,j) = A(:, j)' * Qu(:, i)
- end
- //Completo la columna j de Q.
- Qu(:, j)= A(:, j) - Qu(:, 1:j-1) * R(1:j-1, j)
- //Completo la posición de la diagonal de R
- R(j,j) = norm(Qu(:, j), 2)
- Qu(:, j) = Qu(:, j) / R(j,j)
- end
- endfunction
- function sol = f1(x)
- sol = 1 + x(1)**2 - x(2)**2 + %e**x(1) * cos(x(2))
- endfunction
- function sol = f2(x)
- sol = 2*x(1)*x(2) + %e**x(1) * sin(x(2))
- endfunction
- function vec = F(x)
- vec(1) = f1(x)
- vec(2) = f2(x)
- endfunction
- function sol = Newton(f, vecini)
- eps = 10**-5
- iter = 0
- vec = vecini - inv(numderivative(f, vecini)) * f(vecini)
- while iter < 20 & (f(vecini) ~= eps)
- iter = iter + 1
- vec = vecini - inv(numderivative(f, vecini)) * f(vecini)
- vecini = vec
- end
- sol = vec
- endfunction
- function sol = f6(x)
- sol = x + (1/2.5)*(x**2 - 5)
- endfunction
- function sol = ptofijo6(g, x)
- Eps = 10**-5
- Iter = 0
- while (Iter < 100) & (abs(g(x)-Eps) > 0)
- x = g(x)
- Iter = Iter + 1
- end
- sol = x
- endfunction
- function sol = secante(f, x0, x1)
- Eps = 10**-6
- x2 = 0
- while abs(x1 - x0) > Eps
- x2 = x1 - (x1-x0)/(f(x1)-f(x0)) * f(x1)
- x0 = x1
- x1 = x2
- end
- sol = x2
- endfunction
- function sol = biseccion(f, a, b)
- Eps = 10**-3
- mid = (a-b)/2 + a
- while (b-a)/2 > Eps
- mid = (b-a)/2 + a
- if(f(a)*f(mid) <= 0) b=mid
- else a=mid
- end
- end
- sol = mid
- endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement