Math 4610 Tasksheet 3: Passing Functions in Programming and Shared Libraries Solved

$24.99 $18.99

  The following tasks comprise the second homework assignment for the class. In the class, we have talked about a few basic content items. Task 1. Rewrite of Code in C. You should have at least 6 routines that implement some method for finding roots of functions of one real variable. We have also talked…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

 

The following tasks comprise the second homework assignment for the class. In the class, we have talked about a few basic content items.

Task 1. Rewrite of Code in C.

You should have at least 6 routines that implement some method for finding roots of functions of one real variable. We have also talked about a version of the Bisection method written in C. In this task you will be create C versions of the codes you have written for root finding. Create a C version of each of the codes created in Python or other language. You should end up with at least 6 files. Make sure that the code compiles using a command in a command terminal like the following

% gcc -c bisect.c

to create a file like bisect.o.

Task 2. Passing a Function to a Function.

Create a code in C that will test the Newton Method object module. The code should be able to pass a function pointer to the code that implements the method. You should use the template handed out in class. The template shows one method for passing a function pointer into the bisection method routine provided by the instructor. Test your results on the function

f (x) = x ex

The results should be the same as in previous tasks.

Add the rest of the methods to the test program and compile and load the object files. Use a command like

% gcc -o testRootFinding testRootFinding.c *.o

to link and load the codes. Make sure that the methods produce the same value on the test problem in Task 2. Show the results in your write up of the problem.

Task 4. Shared Library Creation

Create a shared library of the root finding methods. There should be at least 6 routines in your arsenal of algorithms. To complete the task, do the following.

Create a copy of the files in a folder, say temp using

% mkdir temp % cd temp

Compile the files containing your code individually. For example

% gcc -c bisect.c

Once you have the object files for each of the methods, create a shared library from the files using

% ar rcv root_finding.a *.o % ranlib root_finding.a

Check the work using the table of contents option in the archive command as follows.

% ar tv

This will give you a list of the files in the shared library.

Cut an past screen shots of the commands and the results into the homework you submit.

Task 5. Test the Shared Library

In this task recompile the test code, but use the shared library to link and load the object models. Test the code on the same sample problem in this Tasksheet. The results should be identical to your previous results. Your command will look something like

Report the results of the work using screen shots.

Math 4610 Tasksheet 3: Passing Functions in Programming and Shared Libraries Solved
$24.99 $18.99