Thread: simpson's 1/3rd rule

  1. #16
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by rakeshkool27 View Post
    isn't log10 means logarithm to base 10?
    without converting the value of sin shall come negative and negative values aren't expected in log
    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.

  2. #17
    Registered User
    Join Date
    Jan 2010
    Location
    on some of the worst place on earth
    Posts
    105
    Quote Originally Posted by tabstop View Post
    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..............

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Misra Rule 11.2
    By hammer1234 in forum C Programming
    Replies: 1
    Last Post: 04-06-2006, 07:28 AM
  2. SImpson's Rule
    By Brent in forum C Programming
    Replies: 6
    Last Post: 03-20-2006, 09:34 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Who should rule the world?
    By CoderBob in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 02-07-2002, 07:01 AM