Numerical Integration Programming

Keeps giving me a bunch of errors. Please help me fix it.

//Matthew Ciublka HW8 Numerical Integration
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;

int main(){
double x1=0;
double xr=0;
int n=10;
ofstream outfile("HW*Results.txt");
if(!outfile){
//if condition is true
cout<<"Error:Can't open file";
return 1;
}
inputValues(x1,xr);
outValues(outfile,x1,xr);
while(n<=60){
//if condition is true
outfile<<n<<""<<integrate(x1,xr,n)<<endl;
n=n*2;
}
cout<<"The area is "<<integrate(x1,xr,n);
outfile.close();
return 0;
}
void outValues(ofstream& outfile,double x1,double xr)
{
inputValues(x1,xr);
cout<<"Please enter the lower limit:";
cin>>x1;
cout<<endl<<"Please enter upper limit:";
cin>>xr;
cout<<endl;
}
double sinc(double y)
{
double y=0;
if(x==0){
y=1;
} else{
y=1.5;
}
return y;
}
double integrate(double x1,double xr,int n)
{
double area=0;
double wn=(xr-x1)/(n);
double xi=0;
double sum=0;
for(int i=1;i<n;i++){
xi=x1+(i*wn);
sum=sum+sinc(xi);
}
area=10;
return area;
what errors?
What is the function you are integrating? Is it sinc? Step functions are not typically used in calc, you CAN take the areas under them easily, but it is unusual. Maybe a sigmoid would be useful here, if you need to do additional calculations on it later.

That aside,

it looks close, but I am having a hard time relating sinc to the code to understand your intentions. It looks like it should be the area calculation, or the function calculation, I can't tell which or if its something else entirely?
Last edited on
Topic archived. No new replies allowed.