C/C++ :: Matrix Multiplication (Vectors)

Oct 31, 2014

I am writing a brute force implementation of matrix multiplication:

Header file:

vector<vector<int> > matrix_multiplication(vector <vector<int> >& a, vector <vector<int> >& B)/>/>/>;

Source file:

vector<vector<int> > matrix_multiplication(vector <vector<int> >& a, vector <vector<int> >& B)/>/>/>{
int n = a.size();
vector< vector <int> > c (n , vector<int> (n));
for (int i =0 ; i<n ; i++){
for (int j =0 ; j < n ; j++){
for (int k ; k < n ; k++){
c[i][j] = a[i][k] + b[k][j];

[Code] ....

I keep on getting occasional seg faults />/>. I can't see why.

View 10 Replies


ADVERTISEMENT

C++ :: Accept Matrix As Argument And Display Its Multiplication Matrix

Jun 1, 2014

I just want to know the code of the program: Write code to accept matrix as aurgument and display its multiplication matrix which return its multiplication matrix.

View 1 Replies View Related

C++ :: Using Vectors For Manual Multiplication?

Jan 15, 2013

I'm trying to solve Project Euler 16 where you have to calculate 2^1000. SO I made a program that would solve multiplying a number b a single digit factor through manual multiplication in a vector, just to test things out.

The problem is when I take things out of main and try to make a separate function, the original number is never multiplied.

Here's my code with functions...

/*Using vectors manually to multiply a number to a positive power.*/
#include <iostream>
#include <vector>
using namespace std;
void print_vector(const vector<int>& v);

[code]....

Here is the other code, not using functions but even if I use an extra for loop to multiply by the same factor several times, it still does the same thing.

/*Using vectors manually to multiply a number by two (or any single digit factor).*/
#include <iostream>
#include <vector>
using namespace std;
void print_vector(const vector<int>& v);

[code]....

View 5 Replies View Related

C++ :: Matrix Multiplication Using Pointers

Feb 15, 2014

Code:
#include<stdio.h>
#include<conio.h>
void main()

[Code] .....

This program on running returns an error of "ILLEGAL USE OF POINTER".

View 4 Replies View Related

C :: Matrix Multiplication Using Pointers

Feb 17, 2014

Code:
#include<stdio.h> Code: #include<conio.h>
void main() {
int *a[2][2],*b[2][2],*c[2][2],i,j,k;
Printf("
ENTER a MATRIX ELEMENTS

[Code] .....

View 4 Replies View Related

C++ :: SSE Matrix Multiplication Error

Apr 25, 2014

I have been using SSE/ SIMD Matrix multiplication approaches and I persistently get this error:

void mmul_sse_nsize(const float * a, const float * b, float * r, int size) {
__m128 a_line, b_line, r_line;
int bound = size*size;
int rows = size;

[Code] ....

The code almost never throws the error when matrices are size NxN, N =4.

Also, I have a 4 core laptop with 2 GB RAM and I am using VS2013.

View 3 Replies View Related

C/C++ :: Matrix Multiplication Using Files

Dec 12, 2014

I am trying to read two matrices from individual .txt file, and later trying to multiply them. But I am unable to succeed.

Here is the code.

#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
// Here starts the main
int main()
{ // The two input values
FILE *inputFile1;
FILE *inputFile2;

[Code] .....

I am able to get only the first values as the output. The first matrix is 5x3, and the second one is a 3x3 matrix.

Matrix 1
1 2 3
4 5 6
7 8 9
10 11 12

Matrix 2
1 2 3
4 5 6
7 8 9

The output which I am getting is

Enter File name of matrix #1 - with extention - : matrix1.txt
Enter File name of matrix #2 - with extention - : matrix2.txt
Rows1 = 1 Cols1 = 2
Rows2 = 1
Cols2 = 2Cant multiply those two matrices

View 11 Replies View Related

C++ :: Matrix Vector Multiplication

Jan 30, 2015

I have Problem with matrix vector multiplication in program..

void matrixVector ( const int n, const double* A, const double* x, double* y ){
//for(int i = 0; i < n; i++){
// y[i*n] = 0.0;
// }
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
y[i*n] += A[i*n+j]*x[j*n];

[Code] ....

View 3 Replies View Related

C/C++ :: Matrix Multiplication Without Using Arrays

Aug 31, 2014

How to write matrix multiplication (without using arrays) in C ....

View 1 Replies View Related

C++ :: Matrix Multiplication 3x3 For Loops?

Apr 12, 2013

So basically I have to tell the user to input data and i use a for loop:

for (i=0; i< 3; i++)
cin >> p[i][0],p[i][1], p[i][2];

Now for the confusing part is, what do i put in the nested for loops to multiply them and output them so it looks something like

matrix p,r1: # # #
" ",r2: " "
" " " "

View 1 Replies View Related

C :: Multiplication Of Matrix Called Betrix?

Nov 11, 2013

I would like to know how could I make multiplication of matrix called betrix in this code:

Code:
printf("transposed matrix:
");
int trantrix[size][size]; //transposed matrix
for(i=0;i<size;i++) {
for(j=0;j<size;j++) {
trantrix[i][j] = matrix[j][i];
printf("%d ",trantrix[i][j]);

[Code] ......

View 3 Replies View Related

C++ :: Forming A Matrix Multiplication Program

Oct 9, 2013

I just started Linear Algebra for my programming degree and to full understand everything I want to put it into code and make my own "matrix calculator." I have all the theory but I am having issues keeping the matrix variable and moving it around the class' functions to create it and output it. Once I know I have it saved I think I can get the addition/multiplication to work. Here is the code I have so far:

#include <string>
#include <iostream>
using namespace std;
class matrix {

[Code] ....

View 5 Replies View Related

C++ :: Program Matrix Multiplication But It Work Not For Big Arrays?

Mar 9, 2014

I have a program matrix multiplication but it work not for big arrays. n should be bis 200.

#include <iostream>
#include <time.h>
#include <cstdlib>

[Code]....

View 6 Replies View Related

C :: Developing Native Matrix Multiplication Algorithm For 53 Bits

Mar 24, 2014

I am actually working on IEEE Arithmetic especially the IEEE 754 specification where the IEEE double only have 53 bits of precision. I am working on Z/nZ matrix multiplication that works on 53 bits specs. How to write a matrix multiplication algorithm that works well on 53 bits IEEE precision standard.

View 5 Replies View Related

C++ :: Dynamic Massive - Multiplication Of Positive Matrix Elements

Oct 5, 2014

I have a problem with dynamic massive. My task was to find the multiplication of positive matrix elements with using indexes and seperated compiling.

Compiler doesn't warn me about any mistake, but result is not right, it is even not a number.

Header.h

#include <iostream>
#include <math.h>
using namespace std;
float multi(int k, int t, float **p);

[Code] ....

View 5 Replies View Related

C/C++ :: Parallelize Matrix Multiplication Function Dynamically And Statically

Oct 1, 2014

I've been trying to get my matrix multiplication program to run a few different ways. My assignments wants me to run it statically using chunks, but we're not supposed to use OpenMPs scheduler. So I'm not sure how that's possible. And secondly, we have to run it dynamically using locks/unlocks.

Static (not sure how to implement chunk)

#pragma omp section
{
printf("Thread %d doing matrix mult", threadID);
if (matrixAcols != matrixBrows) {
cout << "Error, operation not possible" << endl;

[Code]....

The code will run for a long time too. It uses as many threads as we tell it to but it never speeds up the results.

Quote
Thread 2 doing matrix mult
Thread 4 doing matrix mult
Thread 2 doing matrix mult
Thread 4 doing matrix mult
Thread 2 doing matrix mult
Thread 4 doing matrix mult
Thread 2 doing matrix mult
Thread 4 doing matrix mult
Thread 4 doing matrix mult
Thread 4 doing matrix mult
Thread 4 doing matrix mult
Thread 4 doing matrix mult
Thread 4 doing matrix mult
Thread 4 doing matrix mult

View 2 Replies View Related

C/C++ :: Sequential Matrix Multiplication - Error In Execution Time

Apr 30, 2014

I wrote program for Sequential matrix multiplication .But after execution for any input value( ex. 100,150,400) it shows the execution time is 0.000 msec.

#include <stdio.h>
#include <math.h>
#include <sys/time.h>
void print_results(char *prompt, int N, float *a);
int main(int argc, char *argv[])

[Code] ......

View 2 Replies View Related

C++ :: Matrix Class Using Vectors

Jul 23, 2012

I have implemented matrix class using vectors. code is

template <class T>
class CBSMatrix : public CBSVector< CBSVector<T> >
CBSMatrix(long r,long c, T t) {
setsize(r, c);
init(t);

[Code] .....

Although i have implemented the cols() but things in it are confusing me specially this line "if(size()) return at(0).size();" and "CBSVector<T> v(cols());" this line in add row function is also troubling me. in main i have done some thing lyk CBSMatrix <int> mat(5,5,0); now how to put values in this matrix. How to put values in this template based and vector based wired matrix because first row is created in this and then cols are added to that row.

View 14 Replies View Related

C/C++ :: Sequential Matrix Multiplication Program - Syntax Error Near Unexpected Token

Apr 30, 2014

I wrote a sequential matrix multiplication program in c.

After execution i get error like
./mul.c: line 11: syntax error near unexpected token `('
./mul.c: line 11: `int main(){'

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define wA (30 * 16)
#define wB (50 * 16)
#define hA (80 * 16)
#define hB wA
#define wC wB

[Code] ....

View 4 Replies View Related

C++ :: List Of Vectors (vector Of N Vectors Of M Elements)

Mar 19, 2014

I create a list of vectors (a vector of n vectors of m elements).

std::vector <std::vector <int> > vsFA (n, std::vector<int>(n));

How I assign values? I try below, but not worked

void armazenaFA( std::vector <int> &vFA) // this function only knows about vFA
{ vsFA[n] [m]= simTime().dbl();
OR
vsFA[n].push_back(simTime().dbl());
}

View 1 Replies View Related

C++ :: Create Two Vectors And Then Loop Through The Vectors

Sep 19, 2014

This is probably a very basic question, but I need to create two vectors and then loop through the vectors and output each pair that is found.

The user will input min1 and max1 with step1 for the first vector and min2 and max2 and step2 for the second vector. Then the loops will go through and return the combinations will return each pair of the two vectors.

So if I input min1=1 and max1=10 and step1=1 and same for vector two the return would be:

[1,1]
[1,2]
.
.
.
[10,10]

This is for part of a homework assignment, but I can't continue on the assignment without first getting this simple part to work.

View 1 Replies View Related

C++ :: Using OOP To Implement Matrix Class That Provide Basic Matrix Operations

Mar 27, 2013

i want to know how i can solve this question? do i need to create a class or write the program codes.

View 12 Replies View Related

C/C++ :: Assign A Matrix To Submatrix Of A Bigger Matrix?

Feb 27, 2012

I want to assign a matrix to submatrix of a bigger matrix.

ublas::matrix<int> A(8,5);
ublas::matrix<int> B(2,5);
for(size_t i=0;i<A.size1();++i)
for(size_t j=0;j<A.size2();++j)
        A(i,j)=i*A.size2()+j+1;
for(size_t i=0;i<B.size1();++i)
    for(size_t j=0;j<B.size2();++j)
        B(i,j)=i*B.size2()+j+5;
ublas::matrix_range<ublas::matrix<int> > a(A,ublas::range(0,2),ublas::range(0,5));
a=B;  

and it works.

but if the matrix is compressed_matrix type, there's something with it. the error log as below:

Check failed in file boost_1_48_0/boost/numeric/ublas/detail/matrix_assign.hpp at line 1078:
detail::expression_type_check (m, cm)
terminate called after throwing an instance of 'boost::numeric::ublas::external_logic'
what(): external logic
Aborted

I'm not sure this is a bug or not.

View 2 Replies View Related

C++ :: Find Matrix P For A Square Matrix A

May 25, 2014

I have to prepare a project. But I don t know how can I do this. Program will find a matrix P for a square matrix A such that P^-1 A P ....

View 15 Replies View Related

C++ :: How To Convert Compact Form Of Matrix Into Matrix Form

Oct 4, 2014

3 3
2 1 3 2 3
1 0 2
1 2 6

First line shows row and column number

First index of the second line tells the number of non-zero entries of the first row and second index tell the column number where the non zero entry is placed

for 1st row of matrix:

non-zero entries=2
column number=1
non-zero entry=3
column number=2
non-zero entry=2

covert this in the given form
0 3 3
2 0 0
0 0 6

View 1 Replies View Related

C++ :: If Statement Multiplication By Zero

Mar 28, 2013

I want to set an integer to zero when it easy equal to another integer, but it seems that the program for some reason won't set the integer to zero. Here is the example of that code:

#include <iostream>
using namespace std;
int main () {
int n = 2;
int r = 2;
if(n==r)
n++;
r*0;
cout << " n is " << n << endl;
cout << " r is " << r << endl;
}

What am I doing wrong, it should say that "n is 3" and "r is 0".

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved