Thread: SImpson's Rule

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    4

    SImpson's Rule

    Hey guys, my instructions are to create a program that approximates the area using Simpson's Rule. I set it up the way my book shows, however it is giving me the following error message:
    'function' cannot convert from 'double *' to 'double'
    and
    a warning that says: different types for formal and actual parameter 1

    What do these mean?

    Here is the part of the code that it applies to:

    Code:
    double f(double *ptr, double x, int degree)
    {
    	double sum = 0;
    	int i;
    	
    		for(i = 0; i <= degree; i++)
    		{	
    			sum = sum + ptr[i] * pow(x,i);
    			return(sum);
    
    		}
    
    
    }
    
    double rectangular(double *ptr, double a, double b, double n,int degree)
    {
    		double area = 0;
    		double totarea = 0;
    		double k = 0;
    		double width = (b - a) / n;
    		double widthplus = (b - a) / n;
    		double height = 0;
    
    		for(k = n; k > 0; k--)
    		{
    				for(degree = degree; degree >= 0; degree--)
    				{
    					if(degree != 0)
    					{
    						height = height + (pow(ptr[degree],degree));
    					}
    					else
    					{
    						height = height + (ptr[degree]);
    					}
    
    				}
    
    				area = height * width;
    				totarea = totarea + area;
    				widthplus = widthplus + width;
    
    		}
    		return(totarea);
    	}
    
    double simpsons(double *ptr, double a, double b, double n, int degree)
    {
    		
    	double answer = 0;
    	double h;
    	double x;
    	int i;
    
    		h = (b - a) / n;
    
    		answer = f(ptr,a,degree);
    			
    			for(i = 1; i <= n; i++)
    			{
    				x = a + i*h;
    				
    				answer = answer + 4 * f(ptr,x - (h/2),degree) + 2 * f(ptr,x,degree);
    				
    			}
    
    			answer = answer - f(ptr,b,degree);
    
    			return(h*answer/6);
    
    
    			
    
    }
    Thanks for the help.
    Last edited by Brent; 03-20-2006 at 08:55 PM.

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. 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
  3. Rule of 72
    By sonict in forum C++ Programming
    Replies: 12
    Last Post: 01-23-2003, 08:31 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