F
Fan Zhang
Hi,
I am working on a program which can do numerical evaluations for
integrations. The program I have is like this,
double foo(p1, p2)
double p1, p2;
{
double kk,step;
int ii;
step_sz=(p2-p1)/100.;
kk=0.;
for (ii=0;ii<100;ii++)
kk+=sin(p1+ii*step_sz)*step_sz;
return (kk);
}
This program used the basic Newton method. My question is here in my program
foo, I can only calculate the integrations for a sine function. If I want to
do an integration for a cosine function, I need to rewrite another function
foo1 with cosine being inserted in. I am sure there is a neat way to do this
without writing another function. But I do not have an answer after thinking
about it for a while. Could anybody please let me know how it is achieved?
Thanks a lot.
Regards,
Fan
I am working on a program which can do numerical evaluations for
integrations. The program I have is like this,
double foo(p1, p2)
double p1, p2;
{
double kk,step;
int ii;
step_sz=(p2-p1)/100.;
kk=0.;
for (ii=0;ii<100;ii++)
kk+=sin(p1+ii*step_sz)*step_sz;
return (kk);
}
This program used the basic Newton method. My question is here in my program
foo, I can only calculate the integrations for a sine function. If I want to
do an integration for a cosine function, I need to rewrite another function
foo1 with cosine being inserted in. I am sure there is a neat way to do this
without writing another function. But I do not have an answer after thinking
about it for a while. Could anybody please let me know how it is achieved?
Thanks a lot.
Regards,
Fan