Originally Posted by
tabstop
Yes, log10 means logarithm to the base of 10. Is that what was intended in the problem, instead of natural log? (I'd give even money either way.)
Even WITH conversion to degrees, sin will still go negative. Hence my belief earlier that the sin was squared, not the result of the log.
yeah thats true.....but here i am converting degrees to radians and that shall be correct and so at last I have constructed it in that way
Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
double l1,l2,h,*x,*y,intgn,X,O,E;
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 ((3.141593/180.0) * x[i])),2.0);
//printf("\n%lg",*(y+i));
}
printf("\n\aTHE CORRESPONDING TABLE FOR THE DATAS ARE:\n");
printf("x: ");
for(i=0;i<(l+1);i++)
{
printf("\a %-7lf ",*(x+i));
}
printf("\ny=(log(sin x))^2:");
for(i=0;i<(l+1);i++)
{
printf("\a %-7lf ",*(y+i));
}
printf("\n\n\aTHE LENGTH OF EACH INTERVAL, h = %lg",h);
printf("\n\n\aSO THE INTEGRATION OF THE INTEGRAND USING SIMPSON'S 1/3rd RULE FORMULA IS: ");
X=y[0]+y[l];
O=y[2];
for(i=4;i<l;i++)
{
if(i%2==0)
O=O+y[i];
else
continue;
}
E=y[1];
for(i=3;i<l;i++)
{
if(i%2!=0)
E=E+y[i];
else
continue;
}
printf("\n\a\aX=%lg \aO=%lg \aE=%lg",X,O,E);
intgn=(h/3) * (X + (2*O) + (4*E));
printf("\n\n\aintegrating (log(sin x))^2 = \a(h/3) * (X + (2*O) + (4*E))");
printf("\n \a = \a%lf",intgn);
return 0;
}
.
THANKS EVERYONE FOR ALL YOUR INCREDIBLE HELP AND SUPPORT..............