Hints for Assignment 2 (AMSC460, Fall 2018)

Problem 1: Proceed exactly as in page 8-10 in the notes.
Problem 2: For (i) use lunp.m for Gaussian elimination without pivoting.
For (ii) you can define A by A=zeros(10,10); for i=1:10; for j=1:10; A(i,j)=1/(i+j-1); end; end
For (iii) check that for n=5 your code gives you this matrix:
     1     0     0     0     4
    -1     1     0     0     4
    -1    -1     1     0     4
    -1    -1    -1     1     4
    -1    -1    -1    -1     4
Problem 3(b) Write an m-file heatmat.m for initializing the matrix:
function A = heatmat(N)
n = N-1; M = n^2;  A = zeros(M,M);  
for i=1:n                    % for columns 1 to n
  for j=1:n                  % for rows 1 to n
    k = i + n*(j-1);         % k is number of point in row j, column i
    A(k,k) = ...;  
    % if there is a point to the left:  A(k,k-1) = ...
    % if there is a point to the right: A(k,k+1) = ...
    % if there is a point below: A(k,...) = ...
    % if there is a point above: A(k,...) = ...
  end
end
Check that your code gives the correct A and b for N=4.
Let u be the solution vector of the linear system. Then the temperature at the point (i/N, j/N) is given by u(i+(j-1)*(N-1))
Do NOT print out the solution vector u. Only print out the temperature in the point (1/4,1/4) with 15 significant digits.
How to make a contour plot of the temperature:
x=(0:N)/N; v=zeros(N+1,N+1); v(1:N+1,1)=100; v(2:N,2:N)=reshape(u,N-1,N-1);
contour(x,x,v',30); axis equal; axis([0,1,0,1]); colorbar

Problem 3(c),(d): How to use fprintf
What is the largest value of M where you can still solve the problem in Matlab: Keep doubling the value of N until the program fails.
Problem 3(d): Use spgridmat.m to initialize A. (example for using spgridmat). Check that your code gives the correct matrix: for N=4 print out full(A)
Problem 4 For the upper bound you have to use the maximum value of \(|f^{(n)}(t)|\) over the interval. This can sometimes give an upper bound which is MUCH larger than the actual error.