Question

Design an abstract data type for a matrix with integer elements in a language that you...

Design an abstract data type for a matrix with integer elements in a language that you know, including operations for addition, subtraction, and matrix multiplication. Can any one help me towrite this programme in F# language using visual studio 2019.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

An abstract data type (ADT) is an object with a generic description independent of implementation details. This description includes a specification of the components from which the object is made and also the behavioral details of the object. Instances of abstract objects include mathematical objects (like numbers, polynomials, integrals, vectors), physical objects (like pulleys, floating bodies, missiles), animate objects (dogs, Pterodactyls, Indians) and objects (like poverty, honesty, inflation) that are abstract even in the natural language sense.

In order to define an ADT we need to specify:

  • The components of an object of the ADT.
  • A set of procedures that provide the behavioral description of objects belonging to the ADT.

There may be thousands of ways in which a given ADT can be implemented, even when the coding language remains constant. Any such implementation must comply with the content-wise and behavioral description of the ADT.

Examples

  • Integers: An integer is an abstract data type having the standard mathematical meaning. I
  • Real numbers: There are mathematically rigorous ways of defining real numbers (Dedekind cuts, completion of rational numbers, etc).
  • Complex numbers: A complex number may be mathematically treated as an ordered pair of real numbers.
  • Polynomials with real (or complex or integer or rational) coefficients with the standard arithmetic.
  • Matrices with real (or complex or integer or rational) entries with the standard matrix arithmetic (which may include dimension, rank, nullity, etc).
  • Sets are unordered collections of elements. We may restrict our study to sets of real (or complex) numbers and talk about union, intersection, complement and other standard operations on sets.

For example:-

for a complex number:-

 typedef struct { double real; double imag; } complex; 

//addition can be performed

complex cadd ( complex z1 , complex z2 ) { complex z; z.real = z1.real + z2.real; z.imag = z1.imag + z2.imag; return z; } 

//subtraction can be performed

complex csub ( complex z1 , complex z2 ) { complex z; z.real = z1.real - z2.real; z.imag = z1.imag - z2.imag; return z; } 
void cprn ( complex z ) { printf("(%lf) + i(%lf)", z.real, z.imag); } 

for the matrix:-

#define MAXROW 10 #define MAXCOL 15 typedef struct { int rowdim; int coldim; complex entry[MAXROW][MAXCOL]; } matrix; 
matrix madd ( matrix A , matrix B ) //addition { matrix C; int i, j; if ((A.rowdim != B.rowdim) || (A.coldim != B.coldim)) { fprintf(stderr, "madd: Matrices of incompatible dimensions\n"); C.rowdim = C.coldim = 0; return C; } C.rowdim = A.rowdim; C.coldim = A.coldim; for (i = 0; i < C.rowdim; ++i) for (j = 0; j < C.coldim; ++j) C.entry[i][j] = cadd(A.entry[i][j],B.entry[i][j]); return C; } 
matrix msub ( matrix A , matrix B ) { matrix C; int i, j; if ((A.rowdim != B.rowdim) || (A.coldim != B.coldim)) { fprintf(stderr, "madd: Matrices of incompatible dimensions\n"); C.rowdim = C.coldim = 0; return C; } C.rowdim = A.rowdim; C.coldim = A.coldim; for (i = 0; i < C.rowdim; ++i) for (j = 0; j < C.coldim; ++j) C.entry[i][j] = csub(A.entry[i][j],B.entry[i][j]); return C; }
Add a comment
Know the answer?
Add Answer to:
Design an abstract data type for a matrix with integer elements in a language that you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi can any one help me with this programme to translating in F# language using visual...

    Hi can any one help me with this programme to translating in F# language using visual studio. //Include the required header files. #include //Define the main() function. int main() { //Declare the required variables. int x,y; //Prompt the user to enter the input. printf(“Enter the value of x : “); scanf(“%d”,&x); //Check the value of x and set the value of y. if(x>10) { y=x; } if(x<5) { y=x*2; } if(x==7) { y=x+10; } //Display the value of y. printf(“\nThe...

  • In C++ Design a class to perform various matrix operations. A matrix is a set of...

    In C++ Design a class to perform various matrix operations. A matrix is a set of numbers arranged in rows and columns. Therefore, every element of a matrix has a row position and a column position. If A is a matrix of five rows and six columns, we say that the matrix A is of the size 5 X 6 and sometimes denote it as Asxc. Clearly, a convenient place to store a matrix is in a two-dimensional array. Two...

  • The assignment In this assignment you will take the Matrix addition and subtraction code and modify...

    The assignment In this assignment you will take the Matrix addition and subtraction code and modify it to utilize the following 1. Looping user input with menus in an AskUserinput function a. User decides which operation to use (add, subtract) on MatrixA and MatrixB b. User decides what scalar to multiply MatrixC by c. User can complete more than one operation or cancel. Please select the matrix operation 1- Matrix Addition A+ B 2-Matrix Subtraction A-B 3Scalar Multiplication sC 4-Cancel...

  • It is required to write a Matrix Calculator Program using C Programming Language that could only...

    It is required to write a Matrix Calculator Program using C Programming Language that could only perform addition, subtraction, and multiplication of two matrices of appropriate dimensions. Your program should prompt the user to select a matrix operation from a list of options that contains the aforementioned operations. Then, the user should be prompted to enter the dimensions of the two operand matrices. Next, your program should prompt the user to enter the elements of each matrix row-wise. Your program...

  • write in C++ polynomial class that the data type of the coefficients is a template parameter....

    write in C++ polynomial class that the data type of the coefficients is a template parameter. This data type can be any type that has operators for addition, subtraction multiplication and assignment. The class should have a default constructor which results in a zero value. For example our template class would allow us to build polynomails where coefficients are complex numbers ( using the complex<double> type < complex>)

  • To understand Parnas partitioning, consider writing a module to implement an abstract data type called a...

    To understand Parnas partitioning, consider writing a module to implement an abstract data type called a stack with associated operations PUSH and POP. The implementation of this module should be hidden from all calling modules. A data item should be passed to the PUSH procedure with assurance that it will be placed on the stack. Similarly, the POP procedure should return a data item from the stack and adjust the stack accordingly. Access to the stack in memory via any...

  • Problem 3 (20 pts) It is required to write a Matrix Calculator Program using C Programming...

    Problem 3 (20 pts) It is required to write a Matrix Calculator Program using C Programming Language that could only perform addition, subtraction, and multiplication of two matrices of appropriate dimensions. Your program should prompt the user to select a matrix operation from a list of options that contains the aforementioned operations. Then, the user should be prompted to enter the dimensions of the two operand matrices. Next, your program should prompt the user to enter the elements of each...

  • OUTCOMES After you finish this assignment, you will be able to do the following: Define an...

    OUTCOMES After you finish this assignment, you will be able to do the following: Define an abstract class Create concrete classes from an abstract class Overload an operator Split classes into .h and .cpp files Open files for reading Write to files Use output manipulators such as setw, fixed, and setprecision DESCRIPTION A binary arithmetic operation takes two double operands (left and right) to perform addition, subtraction, multiplication, or division on. For example, 10 + 11 is an addition (+)...

  • With this program you are going to design a math practice program for younger users. You...

    With this program you are going to design a math practice program for younger users. You will ask the user to enter two numbers. Only numbers may be entered. If the user enters a word, the program should disregard the entry and wait for an integer entry. There will not be another prompt if the user enters data other than whole numbers (integers). Here is a sample run: Your static methods should accept two integers and return an integer. Do...

  • Please code in C++. link to continue the code is this below or you can make...

    Please code in C++. link to continue the code is this below or you can make your own code if you wish(fix any mistakes if you think there are any in it): cpp.sh/3qcekv 3. Submit a header file (project3.h), a definition file (project3.cpp), a main file (main.cpp), and a makefile to compile them together. Make sure to run the command make and produce an application file and include it with your submission. For this project, you are required to create...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT