%demo for newton approach to system
% of two linear equations.
close all
clear all
clc
%function fsys.m returns the two equations
%  as a vector.
%function jacsys.m returns the jacoby of
%the two equations as a 2x2 matrix
%the vector X contains the two variables x1 and x2.
x1 = zeros(2,1);
x0=x1;
f1 = zeros (2,1);
jac1 = zeros(2,2);
x1(1) = input('enter x   ');
x1(2) = input ('enter y    ');
%x1 = [.8; 1.2];
%x1 = [-0.75; -1];
tol=1.0E-12;
disp ([x1(1) x1(2)])
format long e
while any(abs(x1-x0)> tol)
    f1 = fsys(x1);
    jac1=jacsys(x1);
    jinv=inv(jac1);
    s1 = -jinv*f1;
    x0=x1;
    x1 = x0+s1;
   disp ([x1(1) x1(2)])
end
    
