AMSC 661 / CMSC 661 Homework 1 FAQ

Known typos:

  • "finitediff.m" should be "finitediff1.m" in two places on p. 2.
  • In Problem 5, the basis elements should be
    psi_1, phi_1, ..., psi_{m-1}, phi_{m-1}, psi_m.
    instead of
    psi_1, phi_1, ..., psi_{m-2}, phi_{m-2}, psi_{m-1}.
  • At the bottom of p. 3, psi = 1 at x_{j-1}+h/2, not x_j + h/2.
  • Question: In working on the HW, I went to code up the different functions provided to build the ODEs and noticed that you had provided several different solutions [ u(x) ] and no inhomogeneous terms [ f(x) ]. Do you mean for the "u(x)"s to be "f(x)"s?

    Answer: No, the given u's are meant to be the true solutions, so that you can compare the computed results with them. Plug u, a, and c into the equation to determine f in each case.

    Question: I am a bit unclear on the returns from the "a" function. It's use in the line: [a0,ap] = feval(a,xmesh) and subsequent uses of the returned variables indicates that they are both vectors, but the function "a" should operate like "c", etc. and return a single vector of the same size as "x".

    Answer: I had it return values of a and, optionally, values ap of a'. We use these values in finitediff1.m in forming "bdiff".

    Question: The function a_4 never seems to be used.

    Answer: True. You can ignore it. It is an artifact from a draft version.

    Question: I am confused about the number of data points you want for the output uval.

    Answer: Yes, you are correct that the instructions are not so clear. In problem 5, do something like this:

    m = floor(M/2);
    x = linspace(0,1,m+1);
    h = x(2);
    xval = linspace(h/2,1-h/2,2*m-1)';

    Then the vector x contains the endpoints of the subintervals, and xval contains the values in x (except for x=0 and x=1) along with the midpoint of each of the subintervals. So uval should be the value of the computed solution at xval.

    Question: The evaluation of a'(x) by "[a0,ap] = feval(a,xmesh);" doesn't work due to "too many output arguments". Though you explained this problem a bit on faq, I'm still confused if we can evaluate a'(x) at the mesh points directly by call of Matlab function(s). If not, shall we use central difference to approximate a'(x) by a0? Thank you!

    Answer: You need to write your own function called a.m. Evaluate the derivative analytically. If a(x) = x^2, for example, then the instructions might look like this:

    function [ax,apx] = a(x)
    ax = x.*x;
    apx = 2*x;

    Question: Should I output both ucomp and uval in fe_quadratic, or I just need to output uval?

    Answer: The outputs from fe_quadratic should be A,g,xmesh,ucomp,uval.

    Question: I was just wondering ... should we even delve deep into why we choose the vectors adiffl, bdiffl etc are formed the way they are and then how spdiags works?

    Answer: In order to do the later problems easily, you will need to understand how spdiags works and why those vectors were padded in that particular way.

    Question: You say to "compute three approximations for each algorithm and each problem." What "approximations" are you speaking of here? How many total should we get in all for this problem?

    Answer: 3 approximations, with number of unknowns 9, 99, and 999.
    4 algorithms: finitediff1, finitediff2, fe_linear, fe_quadratic.
    7 test problems (from Problem 6)
    so 3*4*7 values of || u_computed - u_true||_{infinity}.

    Question: I am confused about the definition of M.

    Answer: Yes, that is not very clear. Document your programs carefully enough so that a user would not be confused, and in Problem 6, run each of the 4 algorithms with 9, 99, and 999 unknowns, regardless of how you need to define the input value of M to make this happen. Compute the infinity norm of the vector of error values at the x coordinate at 9, 99, and 999 places.

    Question: When we turn in the homework assignment, are the functions the only matlab files you want or do you want us to turn in the files we used to produce the call these for the problems? Do you want us to turn in the little functions a, c, and f?

    Answer: Please turn in ALL of your files, including a, c, f, your "main" programs, ....

    Question: I don't understand the difference between ucomp and uval in Problem 5.

    Answer: ucomp contains the coefficients of the approximate solution in the basis created by the phi's and psi's. If we want to evaluate the approximate solution anywhere, we need to know these coefficients.

    At the midpoint h/2, for example, the value of the approximate solution is ucomp(1)*psi_1(h/2) + ucomp(2)*phi_1(h/2).
    At h/4, the value is ucomp(1)*psi_1(h/4) + ucomp(2)*phi_1(h/4).

    So we use the ucomp values, along with the values of the basis functions, to form the uval entries, the value of the approximate solution at h/2, h, 3h/2, ....

    Question: A Matlab issue:

    Answer: There are many questions concerning passing parameters. I'll describe one possible way to get information passed down. If you use another way (global variables, etc.), that is fine. As an example, in evaluating the right-hand side, you need to compute (f,phi(j)), which can be done, for example by calling quad:

    quad(@fphi,lo,up,tol,0,j)
    where lo and up are the limits of integration, tol is the desired bound on the approximate integral, and any parameter after the 0 is just passed through to fphi. So quad will call fphi to get function values at the points in the vector x by a statement equivalent to

    ivals = fphi(x,j)
    so we have succeeded in telling fphi which basis function to compute. Your function fphi can then pass j down to whatever other functions it uses in the computation of f(x)*phi_j(x).

    Question: I don't understand what the basis functions look like.

    Answer: See Figure for an example with 4 subintervals, 3 interior mesh points.