- Thu Apr 08, 2010 9:42 pm
#98056
looked around a little. Is there anyway to calculate trig funtions without a lookup table? =/
Where electronics enthusiasts find answers.
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;
}
thefatmoop wrote:ohh duhh... i didn't look to see if one was includedReminds me of:
to verify code is working: