I was wondering how to use the Trapezoidal Rule in C++. My homework states this:

Integration.

Write a program to integrate an arbitrary time-‐domain signal, with a variable sample interval and variable limits of integration. Test your program on a simulated time-‐domain signal.

So far, I have this for my code:

#include <stdio.h>

#include <math.h>

float integrate(float,float);

int main(void)

{

int i;

int imax=100;

float result, x,y[imax];

float xscale=2;

for(i=0;i<imax; i++)

{

x=xscale*i;

y[i]=sin(x);

result= integrate(x,y[i]);

printf("%f\n",y[i]);

}

return 0;

I'm just a beginner, so any ideas at all would be greatly appreciated.

Integration.

Write a program to integrate an arbitrary time-‐domain signal, with a variable sample interval and variable limits of integration. Test your program on a simulated time-‐domain signal.

So far, I have this for my code:

#include <stdio.h>

#include <math.h>

float integrate(float,float);

int main(void)

{

int i;

int imax=100;

float result, x,y[imax];

float xscale=2;

for(i=0;i<imax; i++)

{

x=xscale*i;

y[i]=sin(x);

result= integrate(x,y[i]);

printf("%f\n",y[i]);

}

return 0;

I'm just a beginner, so any ideas at all would be greatly appreciated.

What are you using to code? This hasn't been C++ since 1998.

http://rosettacode.org/wiki/Numerical_integration

http://rosettacode.org/wiki/Numerical_integration

Remember the trapezoid rule is written as follows

"((Left(n)+right(n))/2)" Where the left and right are both upper and lower estimates of the area under a curve via riemann sums.

You must incorporate the information points including a data value "x,y" and need to have a set table of values for x,y. After that you can plug it in then work it through c++. Try to take what I just wrote and do it out regularly, then try to figure it's code. Hopefully this helps.

"((Left(n)+right(n))/2)" Where the left and right are both upper and lower estimates of the area under a curve via riemann sums.

You must incorporate the information points including a data value "x,y" and need to have a set table of values for x,y. After that you can plug it in then work it through c++. Try to take what I just wrote and do it out regularly, then try to figure it's code. Hopefully this helps.

Topic archived. No new replies allowed.