Solved

Area under a curve

Posted on 1997-08-05
3
496 Views
Last Modified: 2008-02-26
Area of a region under the curve can be described by taking the integral of the function, given the limits of the curve. My problem is to write a program in C, using "Functions" to calculate the area of the region under the curve. The formula/equation to be used to solve is:
Area=Delta*[ {f(a)/2} + {f(a+delta)} + {f(a+2*delta)} + {f(a+3*delta)} + ............. + {f(a+(n-1)*delta)} + {f(b)/2} ] , where delta=((b-a)/n), a=(-1.0) and b=(1.0) and are REAL.
The equation of the curved line is given by:
y = e^ ((-x^2)/2)

Your quick response will be greatly appreciated. Thank you very much.

Sincerely,
Abdul
<batla@msn.com>
<batla@hotmail.com>
0
Comment
Question by:batla
  • 2
3 Comments
 

Accepted Solution

by:
tomii earned 100 total points
ID: 1252876
I'm assuming that n is the number of points along the curve to take, or in other word, delta = 1-(-1)/n = 2/n....  I'm also assuming that Y=f(x)...  In this case, something like this may work...  (I haven't tested this, so there may be a bug or two)

#include <math.h>
#include <stdio.h>

double f(double);
double Area(int, double, double);

void main()
{
      int num_points = 100;

      printf("Area under the curve is: %lf", Area(num_points. -1.0, 1.0));
}
      

double f(double x)
{
      return(exp((-pow(x,2))/2.0));
}

double Area(int n, double start, double end)
{
      double area = 0.0;
      double delta = 0.0;
      long int count = 0;

      delta = (end - start) / n;

      area = f(start) / 2.0;
      area += f(end) / 2.0;

      for(i=start+delta ; i<end ; i+=delta)
      {
            count++;
            area += f(start + (count * delta));
      }

      return(area);
}
      
0
 

Author Comment

by:batla
ID: 1252877
Thanks Tomii. It was a good try but for some reason, it did not work at all. I fixed all the bugs and made it bug-free but it never returned any values to the main and as a result: there was not output. It seemed that it was stuck in some loop. You might wanna try to run it and if runs, e-mail me again. Thanks again for your efforts.

Abdul

0
 

Expert Comment

by:tomii
ID: 1252878
There were some bugs...  It has been mailed to you personally, to batla@msn.com
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using unmanaged DLL from managed application 14 294
How to organize data in excel ? 2 115
How to align numbers in C using the %d 2 104
How to learn Linux? 10 67
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question