hi my friend i have problem in my code when i change the function my quastion is
For the function above, f(x)=(e^x )/x^2 "on" [2,3]
Let h=0.1
1- Estimate the integral of f(x)on [2,3] using composite Simpson 1⁄3 with error less than 〖10〗^(-5).
2-Estimate the integral of f(x)=e^(x^2+y^2 )/(x^2+y^2 ) on[1,2]×[2,3] using composite Simpson with error ≤〖10〗^(-5)
this is a good code when i have a function with one variable answer 1
Code:
#include <stdio.h>#include <stdlib.h>
#include <math.h>
#define f(x) (exp(x))/(pow(x,2))
void simpson();
int main()
{
printf("WELCOME TO MY PROGRAM\n");
simpson();
return 0;
}
void simpson()
{
double f[11],sum=0,S,h=0.1;
int k;
for(k=1;k<=5;++k)
{
f[2*k-2]=f((2*k-2)*0.1+2);
f[2*k-1]=f((2*k-1)*0.1+2);
f[2*k]=f((2*k)*0.1+2);
sum+=f[2*k-2]+(4*f[2*k-1])+f[2*k];
}
S=(h/3)*sum;
printf("\nTHE ANSWER USING SIMPSON IS : %.5f\n",S);
}
when i change the function to two variable x, y
i need another loop for y but i dont know how to make this in my code please help me
my loop for x
f[2*k-2]=f((2*k-2)*0.1+1);
f[2*k-1]=f((2*k-1)*0.1+1);
f[2*k]=f((2*k)*0.1+1);
sum+=f[2*k-2]+(4*f[2*k-1])+f[2*k];
my loop for y
f[2*k-2]=f((2*k-2)*0.1+2);
f[2*k-1]=f((2*k-1)*0.1+2);
f[2*k]=f((2*k)*0.1+2);
error code
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define f(x,y) (exp(pow(x,2)+pow(y,2))/(pow(x,2)+pow(y,2))
void simpson();
int main()
{
printf("WELCOME TO MY PROGRAM\n");
simpson();
return 0;
}
void simpson()
{
double f[11],sum=0,S,h=0.1;
int k;
for(k=1;k<=5;++k)
{
f[2*k-2]=f(((2*k-2)*0.1+1),((2*k-2)*0.1+2)));
f[2*k-1]=f(((2*k-1)*0.1+1),((2*k-1)*0.1+2)));
f[2*k]=f(((2*k)*0.1+1),((2*k)*0.1+2);
sum+=f[2*k-2]+(4*f[2*k-1])+f[2*k];
}
S=(h/3)*sum;
printf("\nTHE ANSWER USING SIMPSON IS : %.5f\n",S);
}