0% found this document useful (0 votes)
24 views

Assignment Definition --- Matrix Maths C Programming

8h8b8b ohobbo obb

Uploaded by

M.Taimoor Joyyah
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Assignment Definition --- Matrix Maths C Programming

8h8b8b ohobbo obb

Uploaded by

M.Taimoor Joyyah
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Matrix Maths

This assignment is an activity that must be completed outside of scheduled labs.

Submission: You must submit a zipped package of 4 populated C source files and one
header file. Templates for these files will be provided.

You must make sure that your code runs on Code::Blocks with MinGW-w64 (GCC)
compiler before submitting.

Do not change the function definitions or header files provided.

Assignment briefing:
This assignment will assess your ability to solve a problem using these C programming
elements: repetition (e.g. for.. or while..), selection (if), structures, two dimensional arrays,
pointers, I/O and functions. The assignment will be marked with a combination of
automated test scripts and manual analysis of the code. It is important to follow the
templates provided, you could score zero for the automated testing marking.

You have been asked to implement linear algebra and test it in a PC-based environment.
There is no requirement to deploy this code onto an embedded processor. There are also
some in-house style rules and program structure constraints you must observe. A set of
template files are provided that you will create code within to meet the requirements
described below.

1. The linear algebra functions will be written in a module called algebra.c. Two
functions are provided with their interface declaration in “AssignmentHeader.h”. One
function will calculate a matrix determinant, the other the inverse of a matrix. The
inputs will be a square matrix of up to size 2x2.
2. A demonstration module, demo.c, which contains functions to robust read data from
file, create example matrices and show the processed results from the linear algebra.
This will serve as an acceptance test.
3. A unit test harness will be populated to provide a minimum of the unit test functions
described in this document. You should use these test functions to help design the
code by considering what is needed to make them pass. You may (and are
encouraged) to add additional test functions to help create a robust program. The
pass/fail status of these functions should be printed to screen.
The c file “assignment_1.c” should not need to be changed, it runs the main function which
calls the tests and demo.

Your task is to write a C program that meets these requirements for the linear algebra, the
demo and the test environment:

Linear Algebra Requirements (solution to be implemented in the supplied algebra.c


file)
1. Your code should only be placed between comments indicated like this:
a. // STUDENT CODE START
b. // STUDENT CODE END
2. There must be a dedicated function to calculate the determinant of any real-valued
2x2 matrix and a 1x1 matrix.
3. Matrices must be stored in the matrix_t structure type defined in the
AssignmentHeader file.
4. The matrix structure must have these fields
a. Matrix data values as a 2D array of floats with maximum array size 10x10
b. Integers nrows and ncols define the number of rows and columns
attempted to be populated with data values in the mValues 2D array
c. status integer to defined as
i. 0 when not successfully populated / initialised with data
ii. 1 when initialised as defined dby nrows, ncols
5. The determinant function must have a use a function declaration (interface) of the
following form:
a. int matrixDeterminant(matrix_t matIn, float *detOfIn);
b. The function returns a status integer, where values greater than 1 are
returned if no errors.
c. matA is the input matrix, &det is the memory address of the float to return the
calculated determinant scalar.
6. There must be a dedicated function to calculate the inverse of any real-valued and
non-singular square 2x2 matrix and a 1x1 matrix.
7. The matrix inversion function must use a function declaration (interface) of the
following form:
a. int matrixInverse(matrix_t matIn, matrix_t *matInvOfIn);
b. The function returns a status integer, where values greater than 1 are
returned if no errors.
c. matIn is the input matrix.
d. &matOInvOfIn is the memory address of the matrix struct to store the
inverse in one or more of its elements.
8. The algebra functions shall return an error if supplied with an uninitialised input
matrix.
9. The algebra functions shall return an error if supplied with an input matrix not
meeting the requirements.
a. The algebra functions shall use stdint.h definitions of integers to help with
portability
10. You may assume an efficient single precision FPU exists on the target hardware
Demonstration Requirements (solution to be implemented in the supplied demo.c file)

1. All user interactions and print messages must be kept in the demo() function, any
scanf or printf used during development must be commented out or deleted in other
functions.
2. Your code should only be placed between comments indicated like this:
a. // STUDENT CODE START
b. // STUDENT CODE END
3. The demo shall obtain input from a user to specify the size of a matrix (nrows * ncols)
to populate with maximum allowed dimension of 10x10 elements
4. Non-numeric or negative user input shall be rejected until valid input is provided
using a function checkSizeInput.
5. The demo must use a function matrixFileInput to read a ASCII coded list of
floating point numbers from a text file (matrix.txt supplied).
6. matrixFileInput will detect and report errors if file not present or insufficiently
populated with numbers
7. All matrices must be stored in the matrix_t structure type defined in the
AssignmentHeader file.
8. The status of the matrix created from file shall be set to 1 only if successfully created
to user input size.
9. The demo must use function matrixDisplay to print the imported matrix to screen
as a grid consistent with Figure 1
10. The function createSubSqMatrix shall extract a square matrix subset of the
matrix from a validated user supplied offset (row, column) with size dimension *
dimension.
11. The demo shall create a 2x2 subset of the imported matrix
12. The demo shall call and display the determinant and inverse result produced by the
linear algebra functions in a manner consistent with Figure 1
13. The demo shall allow a repeat demo in indicated by a user prompt.
14. The following function definitions must be used as supplied in the assignment file
pack
a. int matrixFileInput(matrix_t *matA, const char
*filename_str);
b. int matrixDisplay(matrix_t mat);
c. int checkSizeInput(const char *inputNumber_str, int
*numberValidated, int numberMax);
d. int createSubSqMatrix(matrix_t matInput, matrix_t*
matSubset, int startRow, int startCol, int dimension);
15. The supplied template provides description of the function inputs, outputs and
required behaviour
16. The functions used shall be made robust to ill-formed inputs and missing data proven
via unit tests

Unit Test Requirements1 (solution to be implemented in the supplied test.c file)

1. Code unit tests must be written in test.c file


2. The set of mandated tests shall be completed by adding code to the sections marked
for your code
3. Descriptions and expected outcomes of these tests are provided in the template
test.c
4. The tests shall print the results as required by the description in the template test()
function

1 NOte: it is unusual for unit tests to be mandated in this detail (here to help with the assignment!) but they may
form part of a information pack to illustrate the assurance processes in place for ht ecode development.
5. You should use custom ‘helper’ functions, called by the test case functions to make
your code cleaner. Examples may include:
a. matrix construction function for example/test matrices
b. matrix comparison test
6. You should use an extended set of tests to help design and check the code you write

Additional Instructions:
1. Use the function definitions supplied, you may create other functions to call from
these if this helps with managing complexity
2. Your code should only be placed between comments indicated like this:
a. // STUDENT CODE START
b. // STUDENT CODE END
3. A sample matrix.txt file with 100 numbers is available on AER204 Assignment
section.
4. Please note that you will need to test your code thoroughly to cover every possible
scenario (eg to get a det=0). I will be using different test data to test your program.
5. The main() function is supplied in assignment_[ver].c You are not expected to need
to modify this file.
6. House Rules for assignment2:
a. You cannot use global variables. If you use global variables (i.e.
variables that may be changed by multiple functions), then you will get
0 for the whole code.
b. However, global constants and #define are encouraged. You cannot use
unconditional loops, for example while(1) loops with break conditions.
You will get 0 for the whole code. You can use a while(CONDITION) loop
where CONDITION is a variable or logic statement.
c. You must not use break (unless it is part of a switch case).
d. You must not use goto or continue.

Figure 1: A sample screenshot of the expected output from this code

2 These constraints are to force good code practice, as indicated in Lectures there are occasions where it
acceptable to use these constructs but usually there is a better way.

You might also like