• Assignment #4: Change of instructions: Your file problemX.txt should only contain the output of the file problemX.m (not the Matlab commands. Do not use echo on).

    Make sure that all output is clearly labeled so that it is clear what each number means and by what line in the .m file it was generated.

    • Problems 3 and 4: Stop the Newton iteration when ||x(k)-x(k-1)||2 becomes smaller than some tolerance.
    • Problem 3: In Matlab you can plot the contours where, e.g., cos(x2) - sin(xy) - .5 = 0 for x in [-5,5] and y in [-4,4] as follows:
      [X,Y]=meshgrid(-5:.1:5,-4:.1:4);
      contour(X,Y,cos(X.^2)-sin(X.*Y)-.5,[0 0])  % use .*,./,.^ !

      You can superimpose several contours by using hold on after the first contour command.

    • Problem 4: You need to write m-files f.m and J.m for the function and the Jacobian. The file f.m should look like this:
      function w=f(v)
      w = zeros(19,1);
      w(1) = ...
      for i=2:18
        w(i) = ...
      end
      w(19) = ...

      The file J.m should look like this:

      function a=J(v)
      a = sparse(19,19); % 19x19 zero matrix as sparse structure
      ...          % row 1 
      for j=2:18   % rows 2,...,18
        a(j,j-1) = ...
        a(j,j)   = ...
        a(j,j+1) = ...
      end
      ...          % row 19

      Use plot(0:.05:1,[0;v;0]) to plot the angle of the rod vs. the arclength.