To find the area under the curve using C

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

1. anandGuest

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

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.

--

Nuke the unborn gay female whales for Jesus.

Vladimir S. Oka, Feb 27, 2006

3. Keith ThompsonGuest

"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.

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
4. Robert GambleGuest

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
as such discussion is off-topic here.

Robert Gamble

Robert Gamble, Feb 27, 2006
5. osmiumGuest

"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
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
6. CBFalconerGuest

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

CBFalconer, Feb 27, 2006
7. Robert GambleGuest

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.

Robert Gamble

Robert Gamble, Feb 27, 2006
8. osmiumGuest

"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
9. Keith ThompsonGuest

"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
10. Robert GambleGuest

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
11. osmiumGuest

"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
12. Fred KleinschmidtGuest

"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.

problem. Solving the sine integral ( integrating sin(x)/x ) is NOTa trivial
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
13. osmiumGuest

"Fred Kleinschmidt" wrote:

> As many others have said, show what you have tried, then we might offer
> suggestions.
>
> integration problem. Solving the sine integral ( integrating sin(x)/x ) is
> 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
14. Fred KleinschmidtGuest

"osmium" <> wrote in message
news:...
> "Fred Kleinschmidt" wrote:
>
>> As many others have said, show what you have tried, then we might offer
>> suggestions.
>>
>> integration problem. Solving the sine integral ( integrating sin(x)/x )
>> 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
15. =?ISO-8859-1?Q?Martin_J=F8rgensen?=Guest

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
16. Keith ThompsonGuest

"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.
>>>
>>> integration problem. Solving the sine integral ( integrating sin(x)/x )
>>> 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