function [MHesian,Aequation,bequation,AMatrix,bVector,F,XGuess]=DataEntry; [x,y] = InputData; % Data Entry MHesian = Hesian_Matrix(x,y); % Creates Hesian Matrix Aequation = Aequation_Matrix(x,y); % Creates A Equation Matrix bequation = bequation_Vector(y); % Creates b Equation Vector bVector = b_Vector(y); % Creates b Vector AMatrix = A_Matrix(x,y); % Creates A Matrix F = FVector(x,y); % Creates F Vector XGuess = XGuessVector(x,y); % Guess Vector function [XTable,Yvector]=InputData clc; prompt = {'Enter Excel file name :','Enter X Worksheet:',... 'Enter X Worksheet:'}; dlg_title = 'file and number worksheet'; num_lines = 1; def = {'Sample.xls','X','Y'}; options.Resize='on'; options.WindowStyle='modal'; options.Interpreter='tex'; str = inputdlg(prompt,dlg_title,num_lines,def,options); XTable = xlsread(str{1}, str{2}); Yvector = xlsread(str{1}, str{3}); n = length(Yvector); [m,l]=size(XTable); flag = n>l; if flag for i=l+1:n XTable(:,i) = zeros(1,m); end end end % end of InputData function Hesian = Hesian_Matrix(X,Y) [M L] = size(X); N = length(Y); OnePartition = eye(N); ZeroPartition = zeros(N*(2+M)-N); Hesian = blkdiag(2.*OnePartition,ZeroPartition); eps =0.0000005; Perturbation = eps*eye(size(Hesian)); Hesian = Hesian + Perturbation; end % end of Hesian_Matrix function AEquation = Aequation_Matrix(X,Y) [M,L] = size(X); N = length(Y); epsilon = eye(N); Alpha = epsilon; XBlock = BlkDiagVectorOfMatrix(X,N); AEquation = [epsilon Alpha XBlock]; end % end of Aequation_Matrix function bEquation = bequation_Vector(Y) N = 1; bEquation = BlkVertical(Y,N); end % end of bequation_Vector function bVector = b_Vector(Y) N = length(Y); b = BlkVertical(Y,N); bVector = reduction(b,N); function bVec = reduction(bv,N) i = 1:N+1:N^2; bv(i) = []; bVec = bv; bVec = -bVec; end % end of reduction end % end of b_Vector function AMatrix = A_Matrix(X,Y) [M,L] = size(X); N = length(Y); temp = cell(1,N); temp{1} = epsilons(N); temp{2} = Alphas(N); temp{3} = Xs(X,N,M); Matrix = cell2mat(temp); AMatrix = reduction(Matrix,N); function A_Matrix = reduction(Mat,N) L = N^2; i = 1:N+1:L; Mat(i,:) = []; A_Matrix = Mat; A_Matrix = -A_Matrix; end % end of reduction end % end of A_Matrix function eps = epsilons(N) Ctemp = cell(1,N); epsilon = eye(N); for i=1:N Ctemp{i,1} = epsilon; end eps = cell2mat(Ctemp); end % end of epsilons function AlphaMatrix = Alphas(N) temp = diag(eye(N)); AlphaMatrix = BlkDiag(temp,N); end % end of Alphas function XBlock = Xs(X,N,M) if N~=2 temp = [X(:,1)';X(:,2)']; for i=3:N temp = [temp; X(:,i)']; end else temp = [X(:,1)';X(:,2)']; end XBlock = BlkDiag(temp,N); end % end of Xs function FVec = FVector(X,Y) [M,L] = size(X); N = length(Y); FVec = zeros(N*(2+M),1); end % end of FVector function X0 = XGuessVector(X,Y) [M,L] = size(X); N = length(Y); index = find(Y); pad = zeros(N*(2+M),1); pad(index) = Y(index); X0 = pad; end % end of XGuessVector function Block = BlkDiag(X,N) switch N case 1 Block = X; otherwise Ctemp = cell(1,N); for i=1:N Ctemp{i}= X; end if N~=2 temp = blkdiag(Ctemp{1},Ctemp{2}); for i=3:N temp = blkdiag(temp,Ctemp{i}); end else temp = blkdiag(Ctemp{1},Ctemp{2}); end Block = temp; end % end of switch end % end of BlkDiag function Block = BlkDiagVectorOfMatrix(X,N) X = X'; temp = blkdiag(X(1,:),X(2,:)); for i=3:N temp = blkdiag(temp,X(i,:)); end Block = temp; end % end of BlkDiagVectorOfMatrix function Block = BlkVectorMatrix(X,N) X = X'; temp = blkdiag(X(1,:),X(2,:)); for i=3:N temp = blkdiag(temp,X(i,:)); end Block = temp; end % end of BlkVectorMatrix function Block = BlkVertical(X,N) temp = cell(N,1); for i=1:N temp{i} = X; end Block = cell2mat(temp); end % end of BlkVertical end % end of DataEntry