I'm a french arduino user,
I try to solve a mathematical equation
This one:
— x will be a variable
— y the solution
I've read the arduino reference but i don't understand
In the arduino language, i have sqrt(), pow() but i don't known how i can add the little "3" (linked to the square root) ?
Only if x > 0 or you should handle the sign separately!!
Now, let's not lose our heads here!
For standard C and C++ math library functions (including avr-libc implementations), a domain error occurs if the argument of the log function is negative, and a domain error occurs if the first argument of the pow function is finite and negative and the second argument is finite and not an integer. (The functions return the floating point constant nan---means "Not a Number".)
There's a real good reason for these things: The real-valued mathematical functions are not defined for these arguments. Finding the log of the absolute value of a negative number and then attaching the minus sign in a program is not a recipe for success, I'm thinking.
Regards,
Dave
Footnote:
Although the mathematical definition of the power of a positive number is defined in terms of exponential and log functions, why would a programmer call two functions when the single call to the pow() function does the job?
Furthermore, in general...
The pow() function can calculate the power of a negative base to an integer power, but using the log() does not compute for these cases.
Very true what you said but It depends (as allways).
The cubic root (CR) from -8 = -2 because -2 * -2 * -2 = -8 . So solutions for CR exists. For every number in R- the CR is an element from R- and for every number in R+ the CR is an element from R+. Furthermore abs (CR(x)) == abs(CR(-x))
// R- = all negative real numbers
Because the log() function cannot handle negative values it is valid and mathematically correct (in the case of cubic root) to do the math in the R+ domain and correct the sign afterwards. In fact this trick is mathematically valid with all uneven roots. (uneven numbers are integer by definition)
I agree that this kind of "tricks" with math are more error sensitive, one must understand the math behind the code and document it well - which I didn't - to prevent introducing bugs when the code is upgraded or changed.
Although the mathematical definition of the power of a positive number is defined in terms of exponential and log functions, why would a programmer call two functions when the single call to the pow() function does the job?
Normally if pow() can do the job, stick with pow(),
unless you need to have control over how the calculation is made e.g. because of the numerical stability.
Goos:
My curve work between 0 > 100 in the X and Y axis,
I need it beetween 1000 in X and 256 in Y but i don't known how ...
The Arduino program is generating data for 0..256. I think the program you are using to generate the graph is limiting the output range. Perhaps there is a way to override the default dimensions of the graph.
You are very friendly.
I do not have time to continue to hardwork on before next weekend because
i have many things to do this week but I'll let you know as soon as possible !
I'll post the final code soon (although I'm not a professional) !
I have test with this two solutions, for looking the returned value by serial:
Booth work great
— The range is now between 0 ... 256 (on X & Y axis)
void setup()
{
Serial.begin(9600);
}
void loop()
{
float val=0;
for (int i=0; i <= 256; i++ ){
float result = (i + 17)/42.9948; // robtillaart solution
float val = result * result * result; // robtillaart solution
Serial.print("Level > ");
Serial.print(i);
Serial.print(" - Value > ");
Serial.print(val);
Serial.println(" ");
delay(10);
}
}
void setup()
{
Serial.begin(9600);
}
void loop()
{
float val=0;
for (int i=0; i <= 256; i++ ){
val = pow((i+17)/42.9948, 3.0); // davekw7x solution
Serial.print("Level > ");
Serial.print(i);
Serial.print(" - Value > ");
Serial.print(val);
Serial.println(" ");
delay(10);
}
}