-1

I am trying to integrate a couple of equations, but the program fails to compile. The error message that appears says: "too many arguments to function pow"

I will show the problematic part of the code and then make two specific questions.

 #include <stdio.h> 
 #include <math.h>


 struct Par{
   double gamma1, gamma2;
 } aa;



 void ecuaciones(int n, double v[], double dv[], double t){
 dv[0]=v[6]   ; 

 dv[1]=v[7]   ;

 dv[2]=v[8]   ;

 dv[3]=v[9]   ; 

 dv[4]=v[10]   ; 

 dv[5]=v[11]   ; 

 dv[6]= aa.gamma1*(v[3]-v[0])*pow( (pow(v[0]-v[3], 2)+pow( v[1]-v[4], 2)+pow( v[2]-v[5], 2)), -1,5)  ; 

 dv[7]= aa.gamma1*(v[4]-v[1])*pow( (pow(v[0]-v[3], 2)+pow( v[1]-v[4], 2)+pow( v[2]-v[5], 2)), -1,5)    ; 

 dv[8]= aa.gamma1*(v[5]-v[2])*pow( (pow(v[0]-v[3], 2)+pow( v[1]-v[4], 2)+pow( v[2]-v[5], 2)), -1,5)   ; 

 dv[9]=  -aa.gamma2*(v[3]-v[0])*pow( (pow(v[0]-v[3], 2)+pow( v[1]-v[4], 2)+pow( v[2]-v[5], 2)), -1,5)  ; 

 dv[10]=  -aa.gamma2*(v[4]-v[1])*pow( (pow(v[0]-v[3], 2)+pow( v[1]-v[4], 2)+pow( v[2]-v[5], 2)), -1,5)  ; 

 dv[11]=  -aa.gamma2*(v[5]-v[2])*pow( (pow(v[0]-v[3], 2)+pow( v[1]-v[4], 2)+pow( v[2]-v[5], 2)), -1,5) ; 

So... the problem is in the dv´s from 6 to 11. The questions are the following:

Is it ok to use the "pow" function in this case or is it just defined for constant bases? In case the answer is yes (which im almost sure it is), then the following doubt appears: How can i compose a pow function with another one?

For the sake of clarity, this is what i want to express using a composition of "pow" functions: enter image description here

Note that there´s at least one way to go around this problem: that is to write the squared terms from the base in the form A*A= A squared instead of using pow. Given the fact that the base could be raised to a non-integer power, my opinion is that the general case solution is still very important.

MD XF
  • 7,860
  • 7
  • 40
  • 71

2 Answers2

2

Change all -1,5 to -1.5. I assume you are trying to calculate powers to 3/2.

OOPer
  • 47,149
  • 6
  • 107
  • 142
  • That fixed it. Thanks! Stupid typo... – Gato Mazzei Jul 13 '16 at 19:57
  • Note that you can simplify `pow(n, 2)` as `double sqr(n) { return n * n; }`, and then you get `pow(sqr(v[0] - v[3]) + sqr(v[1] - v[4]) + sqr(v[2] - v[5])), -1.5)`. Also note that `pow(n, -1.5)`is equivalent to `1.0 / (n * sqrt(n))`. – Rudy Velthuis Jul 13 '16 at 20:03
0

It is ok to use the pow function in this case.

You are receiving an error because your outer pow functions have three arguments each, when pow only accepts two arguments.

pow( (pow(v[0]-v[3], 2)+pow( v[1]-v[4], 2)+pow( v[2]-v[5], 2)), -1,5)

simplifies to

pow(some_number, -1, 5)

So this needs to be fixed so that pow has a base and an exponent only.

Alden
  • 2,229
  • 1
  • 15
  • 21