This code compiles but refuses to run. NONE of the cout statements appear, as if the program is in an infinite loop except that its not.

#include "matrixOpsLibrary.h"
#include <iostream>

using namespace MattsMatrixSpace;
using std::cout; using std::endl;

Mat pattern( unsigned K ){
	cout<<"5";

	Mat alpha; //this becomes our A variable which we use throughout the rest of the program
	cout<<"4";

	for( unsigned k=1; k<=K; ++k ){
	cout<<"k:"<<k<<" ";
		Vec temp;
		Vec base = zeros( 2^(K-k) ) | ones( 2^(K-k) );
		for( unsigned l=0; l<2^(K-1); ++l ) temp = temp | base;
		alpha = concat( alpha, temp );
	}
	alpha = concat( alpha, sumr(alpha) );

	Vec temp = zeros(2^K);
	for( unsigned k=0; k<K; ++k ) {
		cout<<"k:"<<k<<" ";
		temp = temp - 10^(K-k-1)*getCol( alpha, k );
	}
	cout<<"1";
	alpha = concat( alpha, temp );
	alpha = sortbyc( alpha, concat( K, K+1 ) );
	cout<<"2";

	alpha = chop( alpha, 0, K-1 );
	cout<<"3";

return alpha;
}

int main(){
	cout<<"7";
	unsigned K = 20;
	cout<<"6";
	Mat A = pattern( K );
	cout<< A.size() << " rows and " << A[0].size() << " columns." <<endl;
return 0;
}

Recommended Answers

All 10 Replies

>> l<2^(K-1);

thats not correct, if you are looking for the power function, then you need to include cmath:

#include <cmath>
#include <iostream>
int main(){
 using namespace std;
 float res = std::pow(2.0f,4.0f); //2^4 = 16
 cout << res << endl;
}

can i create a....

double operator^ (double a, double b){
return pow(a,b);
}

and do something similar for integers?

can i create a....

double operator^ (double a, double b){
return pow(a,b);
}

and do something similar for integers?

No. I think you are using the wrong language,why not matlab?

Now I have std::pow(2,K) instead of 2^K for all uses of ^ in my program. cmath is included.

Now I am getting the error

"test2.cpp:17: error: call of overloaded ‘pow(int, unsigned int)’ is ambiguous"

on each instance of pow

No. I think you are using the wrong language,why not matlab?

Unfortunately I MUST make this program in cpp, and not matlab or ox or octave. ;)

I can change the ints to doubles in the first argument.

In the second argument, I can use int for K's instead of unsigned, but it would be better if I could funnel my unsigned into ints in a pow function to make it easier to deal with.

double pow( double a, unsigned b){
int c = (int) b;
return pow( a, b );
}

is that good?

I can change the ints to doubles in the first argument.

In the second argument, I can use int for K's instead of unsigned, but it would be better if I could funnel my unsigned into ints in a pow function to make it easier to deal with.

double pow( double a, unsigned b){
int c = (int) b;
return pow( a, b );
}

is that good?

That function will not do what you want, call it something else like so

double power(const double base, const double exponent){
 return std::pow(base,exponent);
}

Then you can pass your regular datatypes to that functionint res = power(2,4);

That function will not do what you want, call it something else like so

double power(const double base, const double exponent){
 return std::pow(base,exponent);
}

Then you can pass your regular datatypes to that functionint res = power(2,4);

Line 20 is where I put the double power() function you suggested.

"matrixOpsLibrary.h:20: error: named return values are no longer supported"

make sure you have braces, {} , around the return statement

thanks man! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.