%WRM     generates a plot of the actual and approximate solution to
%
%             f'(x) + f(x) = 0,   f(0) = 1
%
%        on [0,xmax].  The approximate solution is g(x) where
%
%             g(x) = 1 + a(1) x + a(2) x^2 + ... a(N) x^N.
%
%        One of four possible methods are used (Least squares, Galerkin,
%        Collocation, or Method of Moments) and the user is queried 
%        about which to use, what xmax to use and the degree of the 
%        approximation.
%

%        Ellen McGrattan, 8-28-96


clc
home
disp('       THE APPROXIMATION OF f(x), where f''(x)+f(x)=0, f(0)=1')
disp('       ------------------------------------------------------')
disp(' ')
meth= input(['Method? (1=Least sqs., 2=Galerkin, ', ...
             '3=Collocation, 4=Method of Moments) ']);
xmax= input('Maximum x value? ');
N   = input('Degree of approximation? ');
disp(' ')

if meth == 1;
  a = wrml(xmax,N);
elseif meth==2;
  a = wrmg(xmax,N);
elseif meth==3;
  a = wrmc(xmax,N);
else
  a = wrmm(xmax,N);
end;
x = [0:.1:xmax]';
plot(x,exp(-x),x,( (x*ones(1,N)).^(ones(length(x),1)*[1:N]))*a+1,'--'), ...
  xlabel('x'), ylabel('f(x)'), grid, ...
%  legend(' Exact',' Approximate'),