To find the area under the curve using C

Discussion in 'C Programming' started by anand, Feb 26, 2006.

  1. anand

    anand Guest

    Dear all,

    I am trying to "find the area under the curve f(x)=sin(x)/x for x=1 to
    3"

    a) Use the trapezoidal rule method. Prove that your trapezoidal rule
    method is second order
    accurate (using he program)
    b) Use the Romberg method. Compare the grid size neccessary to get
    convergence to within 1e-8 using TR (part a) versus the Romberg method.

    It would be of great help if you guys can programm in C and guide me..

    thanks
    Anand
    anand, Feb 26, 2006
    #1
    1. Advertising

  2. anand wrote:

    > Dear all,
    >
    > I am trying to "find the area under the curve f(x)=sin(x)/x for x=1 to
    > 3"
    >
    > a) Use the trapezoidal rule method. Prove that your trapezoidal rule
    > method is second order
    > accurate (using he program)
    > b) Use the Romberg method. Compare the grid size neccessary to get
    > convergence to within 1e-8 using TR (part a) versus the Romberg
    > method.
    >
    > It would be of great help if you guys can programm in C and guide me..


    We can program in C. We can probably guide you as well.

    What we can't and won't do is do your homework for you. Show you've made
    an effort (in C) and we can help you with any problems you encounter.

    To get you going, go through your numerical analysis textbooks to
    identify the methods you mention. Next, revise your C course to date.

    Finally, try to actually implement what you learned.

    Any C language problems along the way, and good people here will likely
    try to help.


    --
    BR, Vladimir

    Nuke the unborn gay female whales for Jesus.
    Vladimir S. Oka, Feb 27, 2006
    #2
    1. Advertising

  3. "anand" <> writes:
    > I am trying to "find the area under the curve f(x)=sin(x)/x for x=1 to
    > 3"
    >
    > a) Use the trapezoidal rule method. Prove that your trapezoidal rule
    > method is second order
    > accurate (using he program)
    > b) Use the Romberg method. Compare the grid size neccessary to get
    > convergence to within 1e-8 using TR (part a) versus the Romberg method.
    >
    > It would be of great help if you guys can programm in C and guide me..


    I'm sure it would.

    Give us your instructor's e-mail address so we can submit our
    solutions directly. For an extra fee, we'll mention your name. (Or
    perhaps we should charge extra for *not* mentioning your name.)

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Feb 27, 2006
    #3
  4. anand wrote:
    > Dear all,
    >
    > I am trying to "find the area under the curve f(x)=sin(x)/x for x=1 to
    > 3"
    >
    > a) Use the trapezoidal rule method. Prove that your trapezoidal rule
    > method is second order
    > accurate (using he program)
    > b) Use the Romberg method. Compare the grid size neccessary to get
    > convergence to within 1e-8 using TR (part a) versus the Romberg method.
    >
    > It would be of great help if you guys can programm in C and guide me..


    As you will likely soon discover, the majority of regulars aren't big
    on doing other peoples' homework for them, especially when you haven't
    even given it a try yourself.

    Give the problem your best shot, if you have a C language question
    along the way feel free to come back with what you have so far. If you
    have an algorithm question, consult your calculus book or ask elsewhere
    as such discussion is off-topic here.

    Robert Gamble
    Robert Gamble, Feb 27, 2006
    #4
  5. anand

    osmium Guest

    "anand" writes:

    > I am trying to "find the area under the curve f(x)=sin(x)/x for x=1 to
    > 3"
    >
    > a) Use the trapezoidal rule method. Prove that your trapezoidal rule
    > method is second order
    > accurate (using he program)
    > b) Use the Romberg method. Compare the grid size neccessary to get
    > convergence to within 1e-8 using TR (part a) versus the Romberg method.
    >
    > It would be of great help if you guys can programm in C and guide me..


    First of all, x is measured in radians, not inches. It looks like you need
    at least three functions plus main. One to compute f(x), one to compute an
    integral using the trapezoidal rule, and one to do the same thing via the
    Romberg method. That will at least get you started. You might end up
    adding some more functions later. Compile often. Start with f(x), it is the
    easiest to do. For early debugging, you can change main to select one of
    the two methods, one at a time.

    I think the problem would be clearer if he had said "slice" size instead of
    "grid" size. Where I come from, grids tend to be square.

    I don't think your program can "prove" anything, it can demonstrate by
    example that something or other might be true.
    osmium, Feb 27, 2006
    #5
  6. anand

    CBFalconer Guest

    anand wrote:
    >
    > I am trying to "find the area under the curve f(x)=sin(x)/x for
    > x=1 to 3"
    >
    > a) Use the trapezoidal rule method. Prove that your trapezoidal
    > rule method is second order accurate (using he program)
    > b) Use the Romberg method. Compare the grid size neccessary to
    > get convergence to within 1e-8 using TR (part a) versus the
    > Romberg method.
    >
    > It would be of great help if you guys can programm in C and
    > guide me..


    We are happy to do homework, with advance payment of at least 1/2
    day at USD 200 per hour. We also require your instructors e-mail
    address for delivery of the result. Certified check or paypal will
    suffice. The advance amount will be 800 USD.

    You will need to also supply the he program with full
    documentation. We only have the she program available.

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
    More details at: <http://cfaj.freeshell.org/google/>
    Also see <http://www.safalra.com/special/googlegroupsreply/>
    CBFalconer, Feb 27, 2006
    #6
  7. osmium wrote:
    > "anand" writes:
    >
    > > I am trying to "find the area under the curve f(x)=sin(x)/x for x=1 to
    > > 3"
    > >
    > > a) Use the trapezoidal rule method. Prove that your trapezoidal rule
    > > method is second order
    > > accurate (using he program)
    > > b) Use the Romberg method. Compare the grid size neccessary to get
    > > convergence to within 1e-8 using TR (part a) versus the Romberg method.
    > >
    > > It would be of great help if you guys can programm in C and guide me..

    >
    > First of all, x is measured in radians, not inches.


    Who said anything about inches?

    Robert Gamble
    Robert Gamble, Feb 27, 2006
    #7
  8. anand

    osmium Guest

    "Robert Gamble" writes:

    > osmium wrote:
    >> "anand" writes:
    >>
    >> > I am trying to "find the area under the curve f(x)=sin(x)/x for x=1 to
    >> > 3"
    >> >
    >> > a) Use the trapezoidal rule method. Prove that your trapezoidal rule
    >> > method is second order
    >> > accurate (using he program)
    >> > b) Use the Romberg method. Compare the grid size neccessary to get
    >> > convergence to within 1e-8 using TR (part a) versus the Romberg method.
    >> >
    >> > It would be of great help if you guys can programm in C and guide me..

    >>
    >> First of all, x is measured in radians, not inches.

    >
    > Who said anything about inches?


    I saw the " and took it to be inches, rather than seconds.
    osmium, Feb 27, 2006
    #8
  9. "osmium" <> writes:
    > "anand" writes:
    >
    >> I am trying to "find the area under the curve f(x)=sin(x)/x for x=1 to
    >> 3"

    [snip]
    > First of all, x is measured in radians, not inches. It looks like you need
    > at least three functions plus main.


    The '"' character was a closing quotation mark, matching the opening
    quotation mark in front of the word "find".

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Feb 27, 2006
    #9
  10. osmium wrote:
    > "Robert Gamble" writes:
    >
    > > osmium wrote:
    > >> "anand" writes:
    > >>
    > >> > I am trying to "find the area under the curve f(x)=sin(x)/x for x=1 to
    > >> > 3"
    > >> >
    > >> > a) Use the trapezoidal rule method. Prove that your trapezoidal rule
    > >> > method is second order
    > >> > accurate (using he program)
    > >> > b) Use the Romberg method. Compare the grid size neccessary to get
    > >> > convergence to within 1e-8 using TR (part a) versus the Romberg method.
    > >> >
    > >> > It would be of great help if you guys can programm in C and guide me..
    > >>
    > >> First of all, x is measured in radians, not inches.

    > >
    > > Who said anything about inches?

    >
    > I saw the " and took it to be inches, rather than seconds.


    He quoted the problem text, that double quote you confused for inches,
    then seconds, is simply the closing quote of that text, I guess you
    missed the opening quote. Twice ;)

    Robert Gamble
    Robert Gamble, Feb 27, 2006
    #10
  11. anand

    osmium Guest

    "Keith Thompson" writes:

    > "osmium" <> writes:
    >> "anand" writes:
    >>
    >>> I am trying to "find the area under the curve f(x)=sin(x)/x for x=1 to
    >>> 3"

    > [snip]
    >> First of all, x is measured in radians, not inches. It looks like you
    >> need
    >> at least three functions plus main.

    >
    > The '"' character was a closing quotation mark, matching the opening
    > quotation mark in front of the word "find".


    Good grief!
    osmium, Feb 27, 2006
    #11
  12. "anand" <> wrote in message
    news:...
    > Dear all,
    >
    > I am trying to "find the area under the curve f(x)=sin(x)/x for x=1 to
    > 3"
    >
    > a) Use the trapezoidal rule method. Prove that your trapezoidal rule
    > method is second order
    > accurate (using he program)
    > b) Use the Romberg method. Compare the grid size neccessary to get
    > convergence to within 1e-8 using TR (part a) versus the Romberg method.
    >
    > It would be of great help if you guys can programm in C and guide me..
    >
    > thanks
    > Anand
    >

    As many others have said, show what you have tried, then we might offer
    suggestions.

    However, your prof should be admonished for even assigning this integration
    problem. Solving the sine integral ( integrating sin(x)/x ) is NOTa trivial
    task, even using Cautious Adaptive Quadrature with Romberg Extrapolation, or
    Legendre-Gauss, or Lagrangian interpolation.
    It is one of the most difficult to solve with any accuracy over its general
    range. I note that the assignmnet was to integrate from 1 to 3. This area is
    reasonabley smooth, so some accuracy can be achieved by the suggested
    methods. But that might give the student the impression that he has created
    an accurate algorithm. The above methods begin to fail miserably for x > 8.
    --
    Fred L. Kleinschmidt
    Boeing Associate Technical Fellow
    Technical Architect, Software Reuse Project
    Fred Kleinschmidt, Feb 27, 2006
    #12
  13. anand

    osmium Guest

    "Fred Kleinschmidt" wrote:

    > As many others have said, show what you have tried, then we might offer
    > suggestions.
    >
    > However, your prof should be admonished for even assigning this
    > integration problem. Solving the sine integral ( integrating sin(x)/x ) is
    > NOTa trivial task, even using Cautious Adaptive Quadrature with Romberg
    > Extrapolation, or Legendre-Gauss, or Lagrangian interpolation.
    > It is one of the most difficult to solve with any accuracy over its
    > general range. I note that the assignmnet was to integrate from 1 to 3.
    > This area is reasonabley smooth, so some accuracy can be achieved by the
    > suggested methods. But that might give the student the impression that he
    > has created an accurate algorithm. The above methods begin to fail
    > miserably for x > 8.


    I assume that the OP is in a numerical analysis class and not a programming
    language class. Kind of like engineering classes that sometimes had an
    offhand assignment that you, of course, knew Fortran. Doesn't everybody?
    osmium, Feb 27, 2006
    #13
  14. "osmium" <> wrote in message
    news:...
    > "Fred Kleinschmidt" wrote:
    >
    >> As many others have said, show what you have tried, then we might offer
    >> suggestions.
    >>
    >> However, your prof should be admonished for even assigning this
    >> integration problem. Solving the sine integral ( integrating sin(x)/x )
    >> is NOTa trivial task, even using Cautious Adaptive Quadrature with
    >> Romberg Extrapolation, or Legendre-Gauss, or Lagrangian interpolation.
    >> It is one of the most difficult to solve with any accuracy over its
    >> general range. I note that the assignmnet was to integrate from 1 to 3.
    >> This area is reasonabley smooth, so some accuracy can be achieved by the
    >> suggested methods. But that might give the student the impression that he
    >> has created an accurate algorithm. The above methods begin to fail
    >> miserably for x > 8.

    >
    > I assume that the OP is in a numerical analysis class and not a
    > programming language class. Kind of like engineering classes that
    > sometimes had an offhand assignment that you, of course, knew Fortran.
    > Doesn't everybody?
    >

    Even worse if this is in a numerical analysis class - these are poor
    algorithms to use for solving this problem.
    --
    Fred L. Kleinschmidt
    Boeing Associate Technical Fellow
    Technical Architect, Software Reuse Project
    Fred Kleinschmidt, Feb 27, 2006
    #14
  15. anand wrote:
    > Dear all,
    >
    > I am trying to "find the area under the curve f(x)=sin(x)/x for x=1 to
    > 3"
    >
    > a) Use the trapezoidal rule method. Prove that your trapezoidal rule
    > method is second order
    > accurate (using he program)
    > b) Use the Romberg method. Compare the grid size neccessary to get
    > convergence to within 1e-8 using TR (part a) versus the Romberg method.
    >
    > It would be of great help if you guys can programm in C and guide me..


    Here's some guidance: Show your program.

    I would actually like to see it very much, because I'm (I could be) also
    a bit interested in that...


    Best regards / Med venlig hilsen
    Martin Jørgensen

    --
    ---------------------------------------------------------------------------
    Home of Martin Jørgensen - http://www.martinjoergensen.dk
    =?ISO-8859-1?Q?Martin_J=F8rgensen?=, Feb 27, 2006
    #15
  16. "Fred Kleinschmidt" <> writes:
    > "osmium" <> wrote in message
    > news:...
    >> "Fred Kleinschmidt" wrote:
    >>> As many others have said, show what you have tried, then we might offer
    >>> suggestions.
    >>>
    >>> However, your prof should be admonished for even assigning this
    >>> integration problem. Solving the sine integral ( integrating sin(x)/x )
    >>> is NOTa trivial task, even using Cautious Adaptive Quadrature with
    >>> Romberg Extrapolation, or Legendre-Gauss, or Lagrangian interpolation.
    >>> It is one of the most difficult to solve with any accuracy over its
    >>> general range. I note that the assignmnet was to integrate from 1 to 3.
    >>> This area is reasonabley smooth, so some accuracy can be achieved by the
    >>> suggested methods. But that might give the student the impression that he
    >>> has created an accurate algorithm. The above methods begin to fail
    >>> miserably for x > 8.

    >>
    >> I assume that the OP is in a numerical analysis class and not a
    >> programming language class. Kind of like engineering classes that
    >> sometimes had an offhand assignment that you, of course, knew Fortran.
    >> Doesn't everybody?
    >>

    > Even worse if this is in a numerical analysis class - these are poor
    > algorithms to use for solving this problem.


    <OT>
    Conceivably the point is to demonstrate that. Perhaps the next
    iteration of the assignment will expand the range to where things fall
    apart, and ask the students to analyze the results.
    </OT>

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Feb 27, 2006
    #16
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    1
    Views:
    574
    Larry Barowski
    Jun 27, 2005
  2. hotadvice
    Replies:
    14
    Views:
    695
    hotadvice
    Oct 2, 2007
  3. Hicham Mouline
    Replies:
    2
    Views:
    358
    Jerry Coffin
    Sep 14, 2009
  4. Andy B.
    Replies:
    0
    Views:
    796
    Andy B.
    Apr 30, 2010
  5. Jim
    Replies:
    0
    Views:
    179
Loading...

Share This Page