Answer:
1)
#include <iostream>
using namespace std;
#define N 4
void multiply(int mat1[][N],
int mat2[][N],
int res[][N])
{
int i, j, k;
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
{
res[i][j] = 0;
for (k = 0; k < N; k++)
res[i][j] += mat1[i][k] *
mat2[k][j];
}
}
}
int main()
{
int i, j;
int res[N][N];
int mat1[N][N] = {{0, 0, 0, 0},
{0, 1, 2, 3},
{0, 2, 4, 6},
{0, 3, 6, 9}};
int mat2[N][N] = {{0, 1, 2, 3},
{1, 2, 3, 4},
{2, 3, 4, 5},
{3, 4, 5, 6}};
cout << "Matrix A is \n";
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
cout << mat1[i][j] << " ";
cout << "\n";
}
cout << "\nMatrix B is \n";
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
cout << mat2[i][j] << " ";
cout << "\n";
}
multiply(mat1, mat2, res);
cout << "\nResult matrix is \n";
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
cout << res[i][j] << " ";
cout << "\n";
}
return 0;
}
2)
#include <bits/stdc++.h>
using namespace std;
#define MAX 4
#define MAX_THREAD 4
int matA[MAX][MAX] = {{0, 0, 0, 0},
{0, 1, 2, 3},
{0, 2, 4, 6},
{0, 3, 6, 9}};
int matB[MAX][MAX] = {{0, 1, 2, 3},
{1, 2, 3, 4},
{2, 3, 4, 5},
{3, 4, 5, 6}};
int matC[MAX][MAX];
int step_i = 0;
void* multi(void* arg)
{
int core = step_i++;
for (int i = core * MAX / 4; i < (core + 1) * MAX / 4; i++)
for (int j = 0; j < MAX; j++)
for (int k = 0; k < MAX; k++)
matC[i][j] += matA[i][k] * matB[k][j];
}
int main()
{
int i, j;
cout << endl
<< "Matrix A" << endl;
for (int i = 0; i < MAX; i++) {
for (int j = 0; j < MAX; j++)
cout << matA[i][j] << " ";
cout << endl;
}
cout << endl
<< "Matrix B" << endl;
for (int i = 0; i < MAX; i++) {
for (int j = 0; j < MAX; j++)
cout << matB[i][j] << " ";
cout << endl;
}
pthread_t threads[MAX_THREAD];
for (int i = 0; i < MAX_THREAD; i++) {
int* p;
pthread_create(&threads[i], NULL, multi, (void*)(p));
}
for (int i = 0; i < MAX_THREAD; i++)
pthread_join(threads[i], NULL);
cout << endl
<< "Multiplication of A and B" << endl;
for (int i = 0; i < MAX; i++) {
for (int j = 0; j < MAX; j++)
cout << matC[i][j] << " ";
cout << endl;
}
return 0;
}
Consider the product of two matrices A and B of dimensions 4 x 4 as shown...
Consider the product of two matrices A and B of dimensions 4 x 4 as shown below. 0 1 2 3 11 2 3 4 | 0 1 2 3 I 1 0 2 46X2 3 4 5 I 0369 0 0 0 0 I I 14 20 26 32 I - 28 40 52 64 I I 42 60 78 96 I 3 456 1. Write a program to find the product of two matrices. The program should display...
IN JAVA PLEASE!!! :) Multithreading can help in achieving parallelism in computational problems. This makes the program’s response to generate output faster. It is achieved by delegating independent tasks within the program to separate threads instead of creating a sequential routine. Consider the following sample double array: 3 11 5 19 1 8 4 16 7 18 17 6 3 23 9 If the problem is to display all the row-sums and all the column-sums, a sequential program would use...
06) Write a C program to perform matrix operations based of threads. The program accepts from the user a positive integer N. A menu is given to the user: 1. generate matrices: generates three NxN matrices A, B, C with random integer numbers between 0 and 9 2. add: matrix D- A+B+C 3. subtract: matrix D A-B-C 4. display matrices: A, B, C, D 5. display count of result values more than 8. 6. exit: terminate the program When the...
Matrices are used to encode and decode encrypted 6: Matrices and Cryptography messages. Using the following code, Task KİLİMİN | SPACE |-Z --T-T-u一ㄒㄧˇ-ㄒㄧ-w-ㄒㄧㄨㄧㄧㄧㄚ s116 17 18 19 20 21 22 23 24 25 26 The sentence MATRICES ARE FUN becomes: FİUİN AİRİE 0161211 14 9L3151 1910|111813 a. To encode the message, multiply by an invertible matrix A. Write the coded message in a 3x6 matrix, adding 0's for blanks. Calculate the product using a graphing calculator. [7-3-31「13 18 5 1...
Please how all work! 1. Find the eigenvalues and corresponding eigenvectors of the following matrices. Also find the matrix X that diagonalizes the given matrix via a similarity transformation. Verify your cal- culated eigenvalues. (4༣). / 100) 1 2 01. [2 -2 3) /26 -2 2༽ 2 21 4]. [42 28) ( 15 -10 -20 =4 12 4 -3) -6 -2/ . 75-3 13) 0 40 , [-7 9 -15) /10 4) [ 0 20L. [3 1 -3/
Are the two matrices similar? If so, find a matrix P such that B =p-TAP. (If not possible, enter IMPOSSIBLE.) 3 00 300 0 1 0 0 2 0 002 O 01 P= 11
Write a MATLAB program that loads two matrices A and B from the files hw41matA.txt andhw41matB.txt and multiplies them together to obtain matrix C such that the element C(i,j) ofmatrix C is given by: C(i, j) = ∑A(i, k) ∗ B(k, j) where n = number of columns in A = number of rows in B. Display the matrix C in defaultMATLAB format. You cannot use the MATLAB matrix multiply or other inbuilt MATLAB functions forarithmetic operations. You must implement it....
Activity 15 - Matrices, Sequences and Conics Math 180 Task 6: Matrices and Cryptography messages. Using the following code, Matrices are used to encode and decode encrypted KİLİMİN 2 | 3 | 4 | 5 | 6 17 18 T-9 10111 | 12 | 13 | 14 一0一ㄧ一Pー1_Qー1.RT-s-T_T-I-U 15 16 17 18 19 20 21 ㄨㄧㄒㄧㄚ 1-2.TSPACE 24 25 26 ˇ一ㄒ一w 22 23 The sentence MATRICES ARE FUN becomes: AİRİE 13 1 20 189 3 5 19 0 1 18...
The C++ program below contains a function that adds a specific row of two matrices and store the result in the corresponding row of a third matrix. This is done by a loop to invokes a function that adds a single row of the two matrices. By the end of the loop all rows should be added and stored in the result matrix. The rows are added sequentially one after the other. You are required to modify the program below...
C# 1. Given two lengths between 0 and 9, create an rowLength by colLength matrix with each element representing its column and row value, starting from 1. So the element at the first column and the first row will be 11. If either length is out of the range, simply return a null. For exmaple, if colLength = 5 and rowLength = 4, you will see: 11 12 13 14 15 21 22 23 24 25 31 32 33 34...