Hi, i am trying to do something that i thought was going to be quite simple but really does not seem to be now.... i am just trying to run the below calculation, i have tried lots of different combinations with brackets but no matter what i do it seems not to like it... or is it not possible to have a number to the power of a decimal (float) number...? any help would be greatly appreciated!!
int changingInt = 3;
float constantNum = 1.56;
uint32_t constantNumLong;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
constantNumLong = uint32_t(constantNum);
Serial.println(771932220UL+((120UL-771932200UL)/(1+pow((uint32_t(changingInt)/17433UL),constantNumLong))));
//Serial.println(771932220UL+((120UL-771932200UL)/(1+(uint32_t(changingInt)/17433UL)^constantNumLong)));
//Serial.println(771932220UL+((120UL-771932200UL)/(1+(uint32_t(changingInt)/17433UL)^(1.56)UL)));
}
void loop() {
// put your main code here, to run repeatedly:
}
Hmm ok, can see now that there was no chance that it was going to work the way that it was...
Also i had gotten myself into the mind set that all of this had to happen in "Long format" but it is just the answer that i need to be in Long as i need to subtract it from millis later in the code.
so the equation that i am trying to calculate is this one in the pic, where the 3 will change based on sensor data....
and cannot be accurately computed on an Arduino with single precision floats (six to seven digits of precision). There is undoubtedly a much better approach, but you will need to explain what you are trying to accomplish.
Thanks for the feedback, and i have not stopped trying to solve it since i posted the question, just so you don't think that i am just wanting for the answer to fall in my lap
I am using a Mega.
Basically i have sensor data coming in and the higher changingInt (3 in the above example) number gets the more the result needs to change, but it is not a lineal system.
So basically (as i am sure you all know) the root of my problem (as far as i could see it) was when i was trying to divide 3 by 17433. But the little trick that i did find is that you if put the equation into Wolframalpha.com it gives you alternative forms to that equation (or equations that are very very close to it) by looking through these i was able to find one that did not have any very small numbers in it (see below) now this works as it should and i get the right numbers out, thanks for the help!
Oh and i am still using the pow( ) function but can't really see how i can do it without it....
float changingInt = 3;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println((578987000 + 771932000 *pow(changingInt,1.56))/(4135620 + pow(changingInt,1.56)));
}
void loop() {
// put your main code here, to run repeatedly:
}
It might be useful to state what this equation relates to and how the output of your sensor varies ( resolution , max/min values) ; there may be a better way .
If that “3” varies from 1 to 1000, you will barely see any change in the equation solution , the answer would always be 140