Assignment 5 - Computing Function Values Iteratively

You hand in this assignment by showing it to the lecturere when it is completed. It is enough to show the program after exercise 6 of this assignment had been done, exercises 1 to 5 are just for self-check and preparation for exercise 6.
  1. Getting Started.
    Log on your UNIX account and go into the right directory.
            cd public_html 
    Download this page onto your computer and place it on your webpage.
            wget http://www.comp.nus.edu.sg/~gem1501/assignment05.html
            chmod 755 *.html 
    The wget command copies a file into your page.
    In the case that you have messed up your file completely,
    you can do the following commands to get it back.
            rm assignment05.html
            wget http://www.comp.nus.edu.sg/~gem1501/assignment01.html
            chmod 755 *.html 
    The "chmod" command makes everything on your webpage publically readable.
    So you can look with your browser at your page.
    Use an editor like pico and vi to look at the file.

  2. Make yourself familiar with the program
    Most of a webpage is written in Hypertext Markup Language (HTML).
    But this page contains also some parts in Java Script.
    Note that there is an other programming language with
    the name Java, but Java Script shares with it just the name.
    These parts are mixed into the html-page.
    In order to make it easier for you to learn to program
    with Java Script, you receive almost ready programs.
    So you do not need to learn html.

    For editing the relevant parts, you have to find the program.
    Search for the variables surname and givenname in the page.
    There should be a place with the string "var surname" in the text of the webpage.
    Find it with the search option of your editor.
    Replace the values of the variables by your name and look at the result with a browser.
    Replace the value of the student number by your number.
    Use the reload-button to see what you have done.

  3. Analyze the function in the webpage
    Which of the following equations satisfies the current function:
    (a) F(n) = 2^n;
    (b) F(n) = n^2;
    (c) F(n) = 1+2+...+n.

  4. Start to modify the program.
    Read the program. In particular the loop starting with "while".
    Edit the page and try once after the other to program the following functions:
    (a) F(n) = 1*2*...*n;
    (b) F(n) = 5^n;
    (c) F(n) = n^3;
    (d) F(n) = 3*n*n-3*n+1.

  5. Display more values.
    Identify the variable which controls the number of values printed.
    Go to the place where it is defined.
    Change the value such that F(0) ... F(40) are displayed.

  6. Handing in the program
    To hand in the program, do the task below and then show the
    final result to your lecturer during a laboratory session.

    Take the Function F(n) = 3*n*n-3*n+1 from Task 4.(d).
    Introduce a new function G satisfying G(n) = F(1)+F(2)+...+F(n).
    For doing this, declare a new variable h at the place
    where the other variables are declared and assign to it the value 0.
    In the loop after computing m, let h = m+h.
    Output F(n) and G(n) at each round.
    For the output, make an output of the form "F(n) = m, G(n) = h;"
    using the Plus-Sign for string concatenation and putting letters
    which do not belong to variables into quotes.
    So the first two lines and the last line of output should be:
            F(1) = 1; G(1) = 1;
            F(2) = 7; G(2) = 8;
            ......
            F(40) = 4681; G(40) = 64000.
            
    Take care of the dot at the end of the last line and of the semicolons before.
    Make sure that the loop runs until 40.

Java Script Starts Here.


Java Script Ends Here.