Operator Matching Operand Confusion...

Hi All,

I am in way over my head writing recursive code and was hoping for some help. Here's the line of code where the error comes in:

 
B * repeated_squaring(B*B, n, (k-1)/2);


The multiplication operator is not allowed in this instance but I don't know why or how to fix it.

I am really just wondering if there is a way to multiply a variable and a function together.

Also know that B is a square random matrix of size n being multiplied to the Kth power in the code.
Last edited on
This is not enough information. That line of code is meaningless without context (how are B and repeated_squaring defined? What is repeated_squaring supposed to be doing? What about this is recursive?). It's better to show more code -- at least enough so we can get the idea of what's going on.

You also don't tell us what the error is. Don't paraphrase the error because you'll probably get it wrong or omit a critical detail. Copy/paste the actual error you're getting - in full.
Here is more of the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void repeated_squaring(Matrix B, int n, int k)
{
	Matrix C;
	{
	if (k == 1){
		cout << 1 << endl;
		cout << B << endl;
		exit(0);
	}

	if(k > 1 && k % 2!= 0){
		cout << 2 << endl;
		cout << endl;
		cout << B << endl;
		B * repeated_squaring(B*B, n, (k-1)/2);
	
	}
	else{
		cout << 3 << endl; 
		cout<< B << endl;
		repeated_squaring(B*B,n,k/2);
	}
	}
}


B is a randomly generated matrix. I have B being outputted in places in the code and 1, 2 and 3 being outputted so I can see whats going on when the code runs, not because it needs to be there.

In my main function the user inputs an n and k where n is the square matrix's size and k is the power to take the square matrix too. The code is supposed to be a repeated squaring algorithm that cuts down the amount of time it takes to take large matrices to large powers.

My problem is in the part where K is odd. I need to get B times the recursive function but I do not know how to do that.
help please!
Topic archived. No new replies allowed.