RPM Function Help

I’m trying to write a program that uses the formula (M/m)^(1/5) to calculate the ratio of maximum(M) to minimum(m) rpms and then output the result in this format: “The ratio between successive speeds of a six-speed gearbox with maximum speed ___ rpm and minimum speed rpm is _.” This is the first time I’ve tried using pow so I’d really appreciate an explanation it of it as well. Do I need to have “#include <math.h>”? Thank you!

#include <math.h>
float M;
float m;
float r;
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.println("Please input maximum speed");
  while(Serial.available() <= 0);
  M = Serial.parseFloat();
  Serial.println("Please input minimum speed");
  while(Serial.available() <= 0);
  m = Serial.parseFloat();
  speeds_ratio(M ,m );
  Serial.print("The ratio between successive speeds of a six-speed gearbox with ");
  Serial.print("maximum speed ");
  Serial.print(M);
  Serial.print(" rpm and minimum speed ");
  Serial.print(" rpm is ");
  Serial.println(r);
}

float speeds_ratio(float M, float m)
{
  float pow(M, 1.0/5.0);
  float pow(m, 1.0/5.0);
  r = M/m;
}

The Error is in line 29, initializer expression list treated as compound expression. It’s my first pow.

I'm just wondering what relevance the 5th root has.

It's just a parameter our professor gave us. Nothing more than an arbitrary formula.

Everything is fine, except for a little hiccup in the last function:

float speeds_ratio(float M, float m)
{
  float x = pow(M, 1.0/5.0);
  float y = pow(m, 1.0/5.0);
  r = x / y;
}

You just needed two working variables, although you could shorten it (return pow(M, .2)/pow(m, .2))

econjack:
Everything is fine, except for a little hiccup in the last function:

float speeds_ratio(float M, float m)

{
  float x = pow(M, 1.0/5.0);
  float y = pow(m, 1.0/5.0);
  r = x / y;
}




You just needed two working variables, although you could shorten it (return pow(M, .2)/pow(m, .2))

It's even easier than that

float speeds_ratio(float M, float m)
{
return pow(M/m,0.2);
}

(M/m)^0.2 is exactly the same as (M^0.2) / (m^0.2)

Thanks! That fixed the problem!

return pow(M/m,0.2);

It would be a good idea to consider that m might be zero, first.

PaulS:

return pow(M/m,0.2);

It would be a good idea to consider that m might be zero, first.

Good point :slight_smile: