#include <stdio.h>
#include <math.h>
double integrateF(double low, double high)
{
double low = 0;
double high = 20;
double delta_x=0;
double x, ans;
double s = 1/2*exp((-x*x)/2);
for(x=low;x<=high;x++)
delta_x = x+delta_x;
ans = delta_x*s;
return ans;
}
It says that low and high are "redeclared as different type of symbol" and I don't know what that means. Basically, all I'm doing here (READ: trying) is integrating from low (which I set to 0) to high (20) to find the Riemann sum. The for loop looks kinda trippy too...I'm so lost.
EDIT:
#include <stdio.h>
#include <math.h>
double integrateF(double low, double high)
{
low = 0;
high = 20;
double delta_x=0;
double ans = 0;
double x;
double s = 1/2*exp((-x*x)/2);
for(x=low;x<=high;x++)
{
delta_x = x+delta_x;
ans = ans+(delta_x*s);
}
return ans;
}
^That still doesn't work, after the braces and all. It says "undefined reference to 'WinMain@16'"...
You are redefinign low and high inside the function which clash with those defined in the parameters.
The for loop is doing
for(x=low;x<=high;x++)
{
delta_x = x+delta_x;
}
did you mean it to do
for(x=low;x<=high;x++)
{
delta_x = x+delta_x;
ans = delta_x*s;
}
However I think you wanted to do ans += delta_x*s;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With