3 views

Uploaded by umeshamy

Project 9

- matrix algebra
- Matlab_Formulas_List
- 1984 Santoro - An Improved Algorithm for Boolean Matrix Multiplication
- Matrix
- ES26-LE03-Handson
- Engineering Math Review
- Solution Chapter2
- Wap to Do Transpose of a Matrix
- Ac 3418721884
- Matlab Tutorial
- RPT-F5-2012
- Matlab Tutorial
- MATLAB SUMMARY
- Assignment 1
- Matrix Methods,Applied Linear Algebra,Third Edition
- Matrix
- GriffithsMatlabIntro Verion 3.0
- HW
- L1F12BSCS2353.pdf
- Appendix A

You are on page 1of 4

Fall 2014

Programming Project #9

Assignment Overview

You will create a sparse matrix data structure using an underlying STL map and overload

various binary operators to exercise the data structure

This assignment is worth 50 points (5.0% of the course grade) and must be completed

and turned in before 11:59PM on Monday, Nov 17th . This is two weeks because of the

midterm on Nov 6th.

Background

A sparse matrix is a regular mathematical matrix where most of the elements have a 0

value. They are often used in science and engineering applications (see

http://en.wikipedia.org/wiki/Sparse_matrix ). Because they have 0's as most of the values,

special data structures and algorithms are required to be efficient in their use.

A Different Specification

The specification for this project will be a little different. In the past we have provided

both a main and a header file. From now on we will only provide the main. Your job is to

design the class to meet the specifications as provided by the main and that meets the

notes below.

One file

What you will turn in is a single file that contains the class declaration and the definitions.

If you need examples of how to do that, look at worksheets 14 and 15. This makes the

grading process easier. No other reason than that.

Updated 11/6. You will turn in two files: class-09.h and class-09.cpp Handin will allow

turning in both files.

Specifications

the underlying data structure will be a map. It will map a pair<long,long>

(representing the row,column address respectively) to a long .

constructors

o two arg: two longs indicating the number of rows and columns respectively.

SparseMatrix mat(100,50) makes mat with 50 rows each with 100

colums 100 rows with 50 columns each

o three arg: two longs indicating row and column, and an initializer list of longs.

The longs come in triples where each triple indicates: row, column, value to

be set in the matrix. SparseMatrix

mat2(5,5,{1,1,100,2,2,200}) makes mat2 a 5x5 matrix with the

value at 1,1 set to 100 and the value at 2,2 set to 200

operator(row,col) . Takes two args (row,col) and returns a long.

o The two argument longs indicate row and column and return either 0 or, if the

location's value has been set, the value. mat(1,1) will return either a 0 or

the value set at 1,1.

o You could overload a subscript operator (operator[]) but only with one

argument, the index of the element. If you want two indicies like

(row,column), you overload operator(). This operator is usually

interpreted as the function operator, but for now it will be the accessor

function. Note: It cannot be used to set a value, only return it.

.set(row,col,val) method. Takes 3 args: row, column and value. No return.

o Sets the value of the matrix at location row,column to value.

.dimensions() method. No args, returns a pair<long,long>

o returns the dimension (the row and column size) of the matrix

.element_count() method. No args, returns a long

o returns the number of non-default values in the matrix

Operations supported

addition between two matrices. Example shown below

addition between a matrix and a long.

o Should be commutative: 5 + mat == mat + 5

o Note: we make the decision that, for scalar addition, we only modify the

non-default values. Could be done differently, but that is what we do here.

multiplication between two matrices. Example shown below

multiplication between a matrix and a long

o should be commutative as addition with long

o since the default value is 0, the only values potentially changed are the

non-default values

printing. Should be able to print using cout << mat << mat2 <<endl;

o only non-default values are printed

o those values are printed in order

smallest row first

within the row, smallest column first

Errors

Certain errors require that you throw an exception. We cover exceptions in lab10 this

week. Summary, throw a runtime_error if you run into any of the following issues:

matrix-matrix addition requires that the two matrices have the same dimensions, the

same row and column size

matrix-matrix multiplication require that the row column size of the first matrix have

the same size as the column row size of the second matrix

Anything else you need!!!

You are defining your class, so any other functions/members you might need, feel free to

add them. The test will only involve using the main provided.

Important things to Note

1. You should try to make your code efficient. One of the things you learn is that

efficiency should come after you get the thing to work. So getting it to work should

be the most important goal. But afterwards, think about how to make it more efficient.

If you have a 1000x1000 matrix (106 elements) and only 1000 non-default values (say

the identity matrix), it would be wasteful, though not incorrect, to do 106 adds or 106

multiplies to find the answer.

a. it's easier to be efficient with adds, much easier, than with multiplies.

2. Don't worry about any of the errors to begin with. Write correct code and see if it runs

Add Matricies

Take a look at http://en.wikipedia.org/wiki/Matrix_addition

matrix + matrix

matrix + scalar

o adds the scalar to every element of the matrix.

o Remember, for our SparseMatrix, we only modify non-default values

1 2

6

7

3 4 + 5 = 8

9

5 6

10 11

Multiply Matricies

See http://en.wikipedia.org/wiki/Matrix_multiplication

matrix * long

matrix * matrix

Multiply Matricies

Deliverables

class-09.cpp and class-09.h -- your source code solution and your header

file will be required to solve the problem.(remember to include your section, the date,

project number and comments). Remember, you do not provide main-09.cpp

1. Please be sure to use the specified file names

2. Save a copy of your file in your CSE account disk space (H drive on CSE

computers).

3. You will electronically submit a copy of the file using the "handin" program:

http://www.cse.msu.edu/handin/webclient

Assignment Notes

- matrix algebraUploaded bymckegan
- Matlab_Formulas_ListUploaded byKevin Dispo Montajes
- 1984 Santoro - An Improved Algorithm for Boolean Matrix MultiplicationUploaded byPadma Venu
- MatrixUploaded byZakky Indra Nugroho
- ES26-LE03-HandsonUploaded byWilmarc
- Engineering Math ReviewUploaded bythepdm
- Solution Chapter2Uploaded bytj086
- Wap to Do Transpose of a MatrixUploaded byAnkit Prasad
- Ac 3418721884Uploaded byIJMER
- Matlab TutorialUploaded byAnonymous UoHUag
- RPT-F5-2012Uploaded byNie Anthon
- Matlab TutorialUploaded byjudith matienzo
- MATLAB SUMMARYUploaded byZachary
- Assignment 1Uploaded byMaruthi Ram
- Matrix Methods,Applied Linear Algebra,Third EditionUploaded byk_ij9658
- MatrixUploaded byCornelius Alvin Prilly
- GriffithsMatlabIntro Verion 3.0Uploaded byiuliagherman
- HWUploaded bySuresh Kumar Gadi
- L1F12BSCS2353.pdfUploaded byMuhammad Asif Asif
- Appendix AUploaded bycemnuy
- Sol.Prob1Uploaded byDavidQ
- Lab13 2D ArraysUploaded byScribdd3r
- Business Travel Market Metrics a Global Analysis of Business 3710Uploaded byAbhishek Seth
- 59_functions in ExcelUploaded bysunil devatwal
- siksek_aanotesUploaded byTrần Nam Sơn
- 1112 QMDS100 Fall1 OutlineUploaded byJacky Tang
- M51A Online SolutionsUploaded byFabian Hagen
- TenSorUploaded byrjd150
- Opencv UserUploaded byapoks88
- If EmUploaded byapi-3698788

- Tugas matematikaUploaded byHasan Hairulla
- Multivariate Statistical functions in RUploaded byMichail
- IBHM_268-304Uploaded byalphamale173
- Machine Learning - Stanford University _ CourseraUploaded byDaniel Flores
- Lecture on MATLAB for Mechanical EngineeUploaded bySakthikumar Chandrasekaran
- TRANSFORMATIONUploaded byBurhan Basit
- NumericalUploaded byHenry Torres
- Boyd & Vandenberghe_Introduction to Applied Linear Algebra (Cambridge, 2018)Uploaded bylgpacheco
- 03 Linear Algebra CopyUploaded bywerwerwer
- Rudiments of Io AnalysisUploaded byJay-ar Mira
- D mathematics Notes Booklet.pdfUploaded byHadi Hassan
- MainUploaded bySteven Zhao
- System of Linear EquationsUploaded byHucen Nashyd Mohamed
- D&C1Uploaded byvkry007
- Self Reconfigurable HEVCUploaded byMarco Antonio
- Add Maths.pdfUploaded byEsther
- Nit InUploaded byraviroshan2talk
- numerical methodsUploaded byBaljinder Kamboj
- book_linear ALGEBRA.pdfUploaded byJeyakumar R
- 110 Matlab Mathcad TextUploaded byCÁSSIO DANIEL
- Binary Matrix FactorizationUploaded byMuhammad Sami Ullah
- MTH302FAQsUploaded byRamesh Kumar
- Flight Dynamics ManualUploaded byedwardsilva
- CBSE Class 12 Outside Mathematics Sample PaperUploaded byPraveer Saxena
- Abstract Algebra Cheat SheetUploaded bylpauling
- numarray-1.5Uploaded bykricks92
- Wikipedia: MatrixUploaded byMaiara e maraiara
- 25429932-Analysis-of-Water-Distribution-Systems-Using-A.pdfUploaded byTrần Vân
- applied-la-2013.pdfUploaded byImad Siddiqui
- CFA based SBOX and Modified Mixcolumn Implementation of 8 Bit Datapath for AESUploaded byidescitation