hello everyone, I am trying to write a program in simpson's 1/3rd rule.The program is not complete but am stuck with some problem.The problem is that the values I printout are somewhat absurd.The code is
Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
double l1,l2,h,*x,*y;
int l,i;
printf("*********************PROGRAM TO IMPLEMENT SIMPSON'S RULE************************");
printf("\nGIVE THE RANGE OF THE VALUE OF INTEGRATION FOR THE INTEGRAND \n\n\t\t\ty=(log (sin x))^2 \n\nlower limit = ");
scanf("%lf",&l1);
printf("upper limit = ");
scanf("%lf",&l2);
printf("\nENTER IN HOW MANY PARTS THE INTERVAL SHOULD BE DIVIDED(ATLEAST GREATER THAN 4)????");
printf("\nno. of intervals = ");
scanf("%d",&l);
while(l<4)
{
printf("\nERROR!!! : no. of intervals should be atleast greater than 4");
printf("\nno. of intervals = ");
scanf("%d",&l);
}
h=(l2-l1)/l;
x=(double *)malloc((l+1) * sizeof(double));
y=(double *)malloc((l+1) * sizeof(double));
for(i=0;i<(l+1);i++)
{
*(x+i)=l1+(i*h);
*(y+i)=pow(log10 (sin ((180.0/3.141593) * (*(x+i)))),2.0);
printf("\n%lg",*(y+i));
}
printf("\nTHE CORRESPONDING TABLE FOR THE DATAS ARE:\n");
printf("x: ");
for(i=0;i<(l+1);i++)
{
printf(" %-7lf ",*(x+i));
}
printf("\ny=(log(sin x))^2");
for(i=0;i<(l+1);i++)
{
printf(" %-7lf ",*(y+i));
}
printf("\n\nTHE LENGTH OF EACH INTERVAL, h = %lg",h);
return 0;
}
When i give the input as 4 and 5.2 for l1 & l2 respectively and no. of parts i.e.,l as 6 the outputs for y are absurd.
Can you find the fault in my code......THANKS