looked around a little. Is there anyway to calculate trig funtions without a lookup table? =/
Do you mean without using the built-in ones?
Quick note I’d like to add to this. Most likely the provided functions in the arduino core library are just directly inherited from avr-libc. I have to look at the sources, but I doubt they would reinvent the wheel. If that is the case, please look at the following link, specifically at the time it takes to execute these functions in your AVR chip.
http://www.nongnu.org/avr-libc/user-man … marks.html
If your application is timing critical, a lookup table may be the best method. As an example, sin(1.2345) will take 1653 / (16 MHz) = 103.3125 microseconds to execute. Using a lookup table not only may reduce the time it takes for the function to execute, it may even make your memory (both flash and RAM) footprint smaller.
ohh duhh… i didn’t look to see if one was included
haha 103 microseconds per calculation wow! i guess it’s going to take some major code tweaking to get about 4 sig figs on an integration
for what it’s worth here’s the code for c++ using the rectangle method to approx an integration
double f(double x){
return sin(x)/x;
}
double integrate(double a,double b,int N){
double dx = (b - a) / N;//delta x, not instantaneous
double sum = 0;
for(int iter = 1; iter < N; iter++){
double x = a + iter*dx;
sum += f(x);
}
return sum*dx;
}
double integrateFull(double a, double b){
double area1 = integrate(a,b,1);
double area2 = integrate(a,b,2);
int N=2;
while(fabs(area1 - area2)> .00001){
area1 = area2;
N+=5;
area2 = integrate(a,b,N);
}
cout << "\nN is:"<<N<<endl;
return area2;
}
to verify code is working:
Floating point on a $3 microprocessor a’int fast!
Best to find a way to get the algorithm to work with you using fixed point arithmetic. If you need speed.
thefatmoop:
ohh duhh… i didn’t look to see if one was includedto verify code is working:
Reminds me of:
http://imgs.xkcd.com/comics/e_to_the_pi_minus_pi.png(xkcd.com)