C++ :: Kronecker (direct) Vector Product

Feb 19, 2013

How to code the Kronecker/direct product of two vectors??

The direct product of the vectors a and b is given as the matrix below (note "x" refers to x with a circle around it and is the symbol for a Kronecker product):

(a1, a2,..., an) "x" (b1, b2,...,bn) = [a1b1, a1b2,..., a1bn]
[a2b1, a2b2,..., a2bn]
[ . . . . ]
[ . . . . ]
[ . . . . ]
[anb1, anb2,..., anbn]

The way I have coded the rest of the program is such that the matrix shown here is represented by a vector of length equivalent to the number of elements in the matrix. So I want the Kronecker product to give me a vector of length n^2 (where n is the number of elements in each initial vector).

View 3 Replies


ADVERTISEMENT

C/C++ :: Direct X Tool Kit Throws Errors When Loaded In

Oct 21, 2014

I have a project which I started. then tried to add the directx toolkit to the project referenced it but now my program wont load.

View 1 Replies View Related

C# :: How To Use Net Reactor Direct Rewrite Original File

Apr 10, 2014

when I use Net Reactor encrypt my project ,it will create xxxx_secure folder, But i hope Direct rewrite original file,how to do ?

View 1 Replies View Related

C++ :: How To Get The Cross Product

Oct 10, 2014

I am trying to compute the cross product of an 1x6 column vector "D" with a 6xN matrix "S".

vector< vector<float> > D(1, vector<float>(6));
vector< vector<float> > S(6, vector<float>(10)); // Example where N = 10
float cProduct = D*S; // ?

The last line fails, so I'm wondering how you would get the cross product?

View 2 Replies View Related

C++ :: For Loop To Sum Up Product Of Several Arrays

Feb 2, 2013

I need a for loop that sums up the product of several arrays.

int total = 0;
for (int i=0; index < (columns - 2); index++)
for(int indexFF = 0; indexFF < CG[index + 2] - 1; index++)
for (int indexIN = 0; indexIN < CG[index + 1] - 1; indexIN++, total++)
NRN[CG[index + 1]+indexFF] += FF[total] * NRN[indexIN + CG[index]];

right now "columns" is set to 3

CG[] is an array of 10 integers for "column groups"

for now they are set to:

CG[0] = 0
CG[1] = 3
CG[2] = 4
CG[3] = 3

NRN[] is an array of floating points
NRN uses CG to map its indexes out

0 3 7
1 4 8
2 5 9
_6

FF[] is an array of random numbers basically constants

I need the for loops to sum:

NRN[0] = 0.5
NRN[1] = 0.75
NRN[2] = -1
NRN[3] = NRN[0]*FF[0] + NRN[1]*FF[1] + NRN[2]*FF[2]
NRN[4] = NRN[0]*FF[3] + NRN[1]*FF[4] + NRN[2]*FF[5]
NRN[5] = NRN[0]*FF[6] + NRN[1]*FF[7] + NRN[2]*FF[8]
NRN[6] = -1
NRN[7] = NRN[3]*FF[9] + NRN[4]*FF[10] + NRN[5]*FF[11] + NRN[6]*FF[12]
NRN[8] = NRN[3]*FF[13] + NRN[4]*FF[14] + NRN[5]*FF[16] + NRN[6]*FF[17]
NRN[9] = -1

NRN, FF and CG are the only things in other code that I can't change in the loops

when I debug it index goes to 3 and overflows its memory. which it shouldn't because columns = 3 so "index < (columns - 2)" should stop at 1

View 2 Replies View Related

C :: Creating Product Inventory File?

Jan 26, 2013

How to make a program in C to create a product inventory file containing pro0duct name, cost and quantity and then read the prouct inventory file.

View 9 Replies View Related

C++ :: Program That Prints A Discounted Product

Sep 29, 2014

So I need to make a program that reads distance and number of days of a person that is buying a ticket. If distance is greater than 1,000 kilometers AND the person stays more than 7 days, the discount is 30% of the ticket. The cost per kilometer is $1300. Print the ticket with discount.

I used variable distance as float because it will be multiplied with 0.3 for the discount... not sure if I'm right on that.

Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
float distance;
int days;

[Code] .....

I tried another way but haven't done it in code...

ask for distance
ask for days

Ticket= (Dist x 2 x $1300)
If (dist>1000) && (days>7)

cout<<Ticket=Ticket * 0.3;
else { cout<<Ticket;

View 2 Replies View Related

C++ :: Compute Area Of A Triangle Using Cross Product

Jan 8, 2015

I have to write some cpp program which computes area of a triangle using cross product,we give 3 vertices as R2 and 3 edges as double.

I am beginning like this;

#include <iostream>
#include "R2.h"
#include <cmath>
using namespace std;
double area ( R2 *A,double *z)

[Code] .....

View 5 Replies View Related

C++ :: Calculate Product Of 4 Vertical Values In Matrix

Jun 1, 2013

I am attempting to create a program which calculates the product of 4 vertical values in the matrix. The numbers are supposed to be randomly generated and the size of the matrix is given through the command window.

However I seem to have either not pointed my matrix through all of my functions correctly, or my logic is off somewhere as I keep getting this output regardless of the size of matrix I put in:

"the location of the highest horizontal line product is: 5 0 and is the number: 0

The overall max value is 4196352 at the above coordinates."

using namespace::std;
//srand(time(0));
int h_line(int**, int, int);
int v_line(int, int,int);
int diagnol_left(int,int,int);

[Code] .....

View 2 Replies View Related

C++ :: Array Of Structures - Storing Product Information

Nov 5, 2013

I have been dealing with this problem for quite some time, I've been assigned to develop a program that can store products' information within structures (the number of products is undefined). I thought I should use an array of structures, but I don't know how to declare it properly. This is what I thought would work:

struct product {
string name;
string in_stock;
float sale_cost;
int id; }
prod [n]; //n being the undefined number of products the user will register/delete/modify

I already saw an example of array of structures, but it uses a defined number.

View 13 Replies View Related

C++ ::  sorting Ascending Order By According To Product Id / Name / Price

Jul 20, 2014

Here is my code below:

#include<fstream>
#include<iostream>
#include<stdlib.h>
#include<iomanip>
#include<string>
using namespace std;
void main() {
fstream file;
string id,name,type,price;

[code].....

I can't separate and align 4 categories neatly, how to do this solution below(the link of example for sorting Product ID in ascending order): [URL]

By the way,here is the required .txt file(test.txt): [URL]

View 4 Replies View Related

C :: Calculate Product Of Two Matrices - Segmentation Fault In Program

Oct 29, 2014

New to C Programming, I have a problem with a little program I made that calculates the product of two matrices.

And here is the error I get:

View 4 Replies View Related

C Sharp :: Retrieving USB Pendrive Vendor ID / Product ID And Serial Number

Sep 15, 2012

I am trying to retrieve the parameters from externally connected pendrive. I have been using WMI to achieve this but not able to separate the pendrive's parameters from the other USB devices (such as USBcamera,USBHub etc) ....

View 2 Replies View Related

C++ :: Class A Is No Direct Base Of Class B

Aug 8, 2014

I have something like this

class A{//interface}; //implementation
class B{//interface includes a member of type 'A'}; //in implementation of Class 'B' constructor I write

B::B():A(5){} //class 'A' had a constructor of prototype A(int);

now what compiler tells me is

[Error] type 'A' is not a direct base of 'B'

View 2 Replies View Related

C++ :: Looping - Input Numbers Until User Types 0 Then Output Product Of Non Zero Numbers

May 1, 2014

How to do the problem below using loop?

Input numbers until the user types a 0, then output the product of the non 0 numbers: e

E.g., if the user types 2 4 6 0, the program should output 48

View 3 Replies View Related

C/C++ :: Program To Print Product Of Even Numbers And Sum Of Odd Numbers Between 1 And 30

May 20, 2014

I want to make a program to print the product of even numbers between 1 and 30 and sum of odd numbers between 1 and 30. But the answer of product is negative. The photo shows the output of the code.

#include <stdio.h>
#include <conio.h>
void main ()
{
int i, even_product=1, odd_sum=0;
for(i=1;i<=30;i++) // For loop starts here!

[Code]...

View 5 Replies View Related

C++ :: Using Vector Push Back Function To Output Contents Of Vector (similar To Array)

Feb 9, 2015

How to output vector contents using the push_back function. My program reads in values just fine, but it does not output anything and I've been stuck on why.

here is my code:

#include <iostream>
#include <array>
#include <vector>
using namespace std;
int duplicate( vector < int > &vector1, const int value, const int counter)

[Code].....

View 3 Replies View Related

C++ :: Open File And Read In Rows To String Vector And Return Vector

Jun 7, 2012

I have a cpp app that reads in a number of files and writes revised output. The app doesn't seem to be able to open a file with a ' in the file name, such as,

N,N'-dimethylethylenediamine.mol

This is the function that opens the file :

Code:
// opens mol file, reads in rows to string vector and returns vector
vector<string> get_mol_file(string& filePath) {
vector<string> mol_file;
string new_mol_line;
// create an input stream and open the mol file
ifstream read_mol_input;
read_mol_input.open( filePath.c_str() );

[Code] ....

The path to the file is passed as a cpp string and the c version is used to open the file. Do I need to handle this as a special case? It is possible that there could be " as well, parenthesis, etc.

View 9 Replies View Related

C++ :: Create Class Vector As Template And Define Operations On Vector?

May 13, 2013

I need to create a class vector as a template and define operations on vectors.

And this is what I made.

#include<iostream>
using namespace std;
template<class T>

[Code].....

View 2 Replies View Related

C++ :: Recursive Function 2 - Create Vector Of Vector Of Integers

Mar 26, 2013

Lets say that I have a vector of vector of integers. <1,2,3,4> , <5,6,7,8>, <10,11,12,13>

How do I make a function that creates vector of vector of every different integers?

<1,5,10> , <1,5,11>, <1,5,12>, <1,5,13>
<1,6,10> , <1,6,11>, <1,6,12>, <1,6,13>
<1,7,10> , <1,7,11>, <1,7,12>, <1,7,13>
<1,8,10>, <1,8,11>, <1,8,12>, <1,8, 13>
<2,5,10>, <2,5,11>, <2,5,12>, <2,5,13>

and so on...

View 2 Replies View Related

C++ :: Find Function To A Vector Of Structures Vector

Jul 5, 2013

I have asked a related question before, and it was resolved successfully. In the past, when I wanted to use std::max_element in order to find the maximum element (or even sort by using std::sort) of a vector of structures according to one of the members of the structure, all I had to do was to insert a specially designed comparison function as the third argument of the function std::max::element. But the latter comparison function naturally accepts two arguments internally.

For instance, here is a test program that successfully finds the maximum according to just one member of the structure:

Code:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

[Code] ....

And the output was this, as expected:
Maximum element S.a of vector<S> vec is at: 9
[I]max element of vec.a between slot 3 and slot 6 is: 6, and its index is: 6 vec[6].a = 6
[I]max element of vec.a between slot 4 and slot 7 is: 7, and its index is: 7 vec[7].a = 7
[I]max element of vec.a between slot 5 and slot 8 is: 8, and its index is: 8 vec[8].a = 8
[I]max element of vec.a between slot 6 and slot 9 is: 9, and its index is: 9 vec[9].a = 9

However, I now need to search and find an element of vector<myStruct> according to just one member of myStruct, instead of finding the maximum or sorting as before. This presents a problem because the function std::find does not accept such a comparison function as its third argument.

This was the description of the std::find function that I found: find - C++ Reference

Code:
template <class InputIterator, class T> InputIterator find (InputIterator first, InputIterator last, const T& val);

I could also find another function called std::find_if, but this only accepts a unary predicate like this: find_if - C++ Reference

Code:
template <class InputIterator, class UnaryPredicate> InputIterator find_if (InputIterator first, InputIterator last, UnaryPredicate pred);

And once again this is either inadequate of I don't see how to use it directly, because for the third argument I would like to insert a function that takes two arguments with a syntax like this:

Code:
int x=7;
std::vector<S>::iterator result;
result = std::find(vec.begin(), vec.end(), []( const (int x, const S & S_1) { return ( x == S_1.a ) ; } ) ;

Is there another std function that I can use to make search and find an element according to just one member of myStruct?

Or perhaps there is a clever way to pass two arguments to the unary predicate.

View 4 Replies View Related

C/C++ :: Cannot Print Vector Of Vector Of Doubles

Mar 31, 2014

I am trying to print a matrix solution that I've stored in a vector of doubles. The original matrix was stored in a vector of vector of doubles. I want to print to the screen and an output file. Right now it just prints to screen column-style and the output file is horizontal-style. I tried to change the solution from vector of doubles to a vector of vector of doubles like the original matrix but when I run my code it crashes. Here is what I am referring to:

void readMatrix(vector<vector<double>> &matrix, vector<double> &b, int &N, string input) {
ifstream in(input);
in >> N;
matrix.resize(N);
b.resize(N);

[Code] ....

However when I change my printResult function to this (I removed the string argument because I just want to get it working to the screen first):

void printResult(vector<vector<double>> &sol, const int N) {
//ofstream out(output);
//int j;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++){

[Code] ....

The program crashes. Am I even printing the matrix correctly?

View 4 Replies View Related

C/C++ :: Swapping Vector Int And Vector Strings

Mar 30, 2013

I want to have it so that when i ask for the person witch item they want to drop on the ground it goes into another vector that i can pick back up the item if they want it back and erase when they walk away.

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cmath>  
using namespace std;  
    struct InventoryItem

[Code] ....

View 4 Replies View Related

C++ :: Can't Read In Matrix Into Vector Of Vector Of Int

Mar 24, 2012

Code:
#include <iostream>
#include <istream>
#include <fstream>
#include <vector>

[Code]....

Why is it reading in nothing for the arrays, and also making the size of the total thing the total number of numbers? It should have a size of 2, not 5.

View 14 Replies View Related

C++ :: Copy Part Of Vector 1 To Vector 2

Jun 21, 2012

I am trying to copy vector to vector as follow:

Code:

std::vector<unsigned char> vec1;
//insert some values into vec1
std::vector<unsigned char> vec2;

Now I want to to copy 2 bytes from vec1 starting at index 5., why do i need to know how many bytes from the end of vec1?? can't i just specify how many bytes i want to copy from starting index?

std::copy(vec1.begin()+5, vec1.end()-??, vec2.begin());

View 2 Replies View Related

C++ :: Converting 1D Vector Into 2D Vector

Apr 20, 2013

Code:
#include <iostream>
#include <vector>
int main() {
std::vector<std::vector<double> > DV; //2d vector
std::vector<double>temp(8,0.0); //1d vector

[Code] .....

The conversion actually works but it does not give the expected the result. The output should be:

Code:
1 2 3
4 5 6
7 8

and it outputs:

Code:
123123123

View 5 Replies View Related







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