CSE541 Homework #2

Answers

Due Date:

FINALIZED


GENERAL INSTRUCTIONS


ASSIGNMENT

  1. You are given a program that implements a simple bisection method in order to compute the square root of 2. The executable is invoked with command line arguments for the low and high bracketing values and the number of iterations.

    As examples, and as part of the assignment, run the Bisection Method with the following arguments.

    bisection 1 2 20
    bisection 1 5 20
    bisection 1 10 20
    
    You are to implement the Regula Falsi Method. If you have limited programming experience, I suggest you make a copy of the Bisection Method code and modify it, keeping the same program structure. If you are a more experienced programmer, you are free to program this up from scratch any way you want as long as the compilation via a makefile and the execuation still adhere to the assignment requirements. See below on how to submit the source codes and makefile for the solution methods.

    Run the regulaFalsi method with the following arguments:

    regulaFalsi 1 2 20
    regulaFalsi 1 5 20
    regulaFalsi 1 10 20
    
    Explain the results of both the Bisection Method and the Regula Falsi Method in the hardcopy you hand in at the beginning of class on the due day. Compare the output of the Bisection Method and the Regula Falsi Method. Use sketches showing how the algorithms solve the problem where appropriate and explain how one outperforms the other for given input.

  2. In the code for the Regula Falsi Method, change the 'Real float' line to 'Real double' and re-execute the 3 runs. Explain the results. Compare the output of the Regula Ralsi Method runs that use doubles to the runs that use floats and discuss the results.

  3. Code up and run Newton's Method for the same problem (using 'floats). Use the following:
    Newton 1 10
    
    
    Note the value of the error when using starting point of '1'. Use 'verbose' mode to see the convergence. Find low and high values for the starting point where the error significantly changes (say, a couple orders of magnitude). Briefly discuss how Newton's Method solves this problem for a wide range of values (draw a diagram).

  4. Code up and run the Secant Method for the same problem (using 'floats). Use the following:
    secant 0.5 0.55 10
    
    secant 0.5 0.6 10
    
    Use verbose mode to see the convergence. Discuss the results and any difference you see.

SPECIFIC INSTRUCTIONS

The assignment is called 'hw2'.

Create a makefile that the grader can use to create your executables. The makefile, for example, can look like:

all: bisection regulaFalsi Newton secant

bisection: bisection.c
       gcc -lm bisection.c -o bisection

regulaFalsi: regulaFalsi.c
       gcc -lm regulaFalsi.c -o regulaFalsi

Newton: Newton.c
       gcc -lm Newton.c -o Newton

secant: secant.c
       gcc -lm secant.c -o secant

clean:
       rm bisection regulaFalsi Newton secant
DO NOT SUBMIT THE EXECUTABLE. The grader should be able to go to your submit directory to compile your program with:
make all
and then issue the commands as in the assignment above.

There is also amble makefile information on the web, such as this Makefile tutorial.


NOTES