%% YOURNAME (DUEDATE)
%
% *IMPORTANT:*
%
% Do not change *anything* in this header (besides your
% name and due date above as needed)!
%
% Put your solution to the exercise completely at the end
% of this file.
%
%%
% <latex>
% % for Octave, or for Matlab published to LaTeX for proclatex
% \input{../setup.tex}
% </latex>
%
%% FOR, IF, WHILE, Exercise 3

if ~exist('___code___','var') ; clear ; end
format compact
more off


%% EXERCISE DESCRIPTION:
%
% Use advanced programming to create a function MakeVDM
% that creates the Vandermonde matrix corresponding to a
% given set of |x|-values.
%
% Then probe the condition number of the Vandermonde
% matrices generated by various sets of |x| values.
%
%% Hints
%
% * For 10 equally spaced x-values from 0 to 1, the matrix
% condition number should be 1.5193e+07.  The code to
% test that is already in this script; just run it.


%% Additional file: MakeVDM.m
% <include>MakeVDM.m</include>


%% TESTS
%
% Test the created function.

% number of x-values to use for testing MakeVDM
n=10
% the x-values to use for testing MakeVDM as a column
xValues=linspace(0,1,n)';
xValuesT=xValues'

%%

% find the Vandermonde matrix using MakeVDM
VDM=MakeVDM(xValues)

%%

% check the condition number
condVDM=cond(VDM)
disp('Correct =    1.5193e+07')
condVDMCorrect=1.5193e+07;
if abs(condVDM-condVDMCorrect) > 0.0002E7
    fprintf('*** MakeVDM failed!\n')
    fprintf('    Cond(VDM) is %.4E, not %.4E\n',...
            condVDM,condVDMCorrect)
    error('    Fix MakeVDM and try again!')
end

%%

% see whether help works OK too
help MakeVDM


%% SOLUTION:


