--- /dev/null
+
+A = zeros(length(t), 5);
+
+for i=1:length(t)
+ A(i, :) = [1 cos(2*pi*t(i,1)/0.3840) sin(2*pi*t(i,1)/0.3840) cos(4*pi*t(i,1)/0.3840) sin(2*pi*t(i,1)/0.3840)];
+
+
+
+end
\ No newline at end of file
+++ /dev/null
-function [L,U,P] = lufact(A)
-%%
-% Computes the LU factorization of the matrix A. The factorization is done
-% in-place and then the L and U matrices are extracted at the end for
-% output. The factorization is PA = LU
-%
-% INPUT:
-% A - n by n square, non-singular matrix
-%
-% OUTPUT:
-% L - lower triangular matrix with ones along the main diagonal
-% U - upper triangular matrix
-% P - permutation matrix for pivoting
-%%
-% get the size of the system
- n = length(A);
-%%
-% initialize the pivoting matrix
- P = eye(n);
-%%
-% Vectorized in-place LU factorization (with row pivoting) that keeps
-% track of the total permutations by scrambleing the matrix P
- for j = 1:n-1
-
- [v i] = max(abs(A(:, j)));
- A([k i],:) = A([i k],:);
- P([k i],:) = P([i k],:);
-%%
-% Find the index of the largest pivot element in the current column
-
-
-%%
-% Swap the rows within the in-place array as well as the permutation matrix P
-
-
-
-%%
-% Perform the in-place elimination and save the new column of L
- i = j+1:n; % indices for the "active" matrix portion
- A(i,j) = A(i,j)/A(j,j);
- A(i,i) = A(i,i) - A(i,j)*A(j,i);
- %A, return
- end
-%%
-% Extract L and U from the in-place form
- U = triu(A);
- L = eye(n) + tril(A,-1);
-end
--- /dev/null
+function [xVals,iter] = newtonRaphson(f,x0,tol)
+%%
+% Implementation of the Newton-Raphson method to approximate
+% the root of a nonlinear function f(x)
+%
+% INPUT:
+% f - function f(x) OBS! passed as an anonyomous function
+% fprime - first derivative of the function f(x) OBS! passed as an anonyomous function
+% x0 - initial guess of the root location
+% tol - error tolerance to stop the iteration
+%
+% OUTPUT:
+% xVals - sequence of approximate values for the root of the function f(x)
+% iter - number of iterations it took to achieve user set tolerance
+%%
+% initialize a vector to store the sequence of guesses
+ xVals = zeros(16,1);
+%%
+% save the initial guess
+ xVals(1) = x0;
+%%
+% perform Newton-Raphson for a fixed number of iterations
+ for k = 1:15
+%%
+% update to the next value
+ fk = f(xVals(k));
+ xVals(k+1) = xVals(k) - ((fk)^2) / (f(xVals(k) + fk) - fk);
+%%
+% check the stopping condition
+ stopCond = abs(f(xVals(k+1)));
+ if stopCond < tol
+ xVals = xVals(1:k+1);
+ iter = k+1;
+ break;
+ end
+ end
+end
\ No newline at end of file