Hi
this is pdf :
I have question with problem 1

I solved problem 1 but i am not sure if my answers are right.:(
can you check?? plz!!

my answers

for a) i said,
if applying the composite simpson rule on a uniform mesh subdividing [a,b] into intervals of width h/2, two halves of the interval are [a,c] [c,b]
and d,e are midpoints of these two subintervals
d= (a+c)/2 , e= (c+b)/2

apply Simpson's rule to each subinterval, a quadrature rule on [a,b]
S_2 = h/12 ( f(a)+4f(B)+2f(c)+4f(e)+f(b) )

so, S_2 = I(f)- (1/15) (S_2(f)-S(f))


for a) i said,
The two can be combined to get an even more accurate approximation Q
Both rules are of order 4, but step size for S_2 is half the size for S, so the error in S_2 is roughly 2^4=16 times smaller than that of S.
Thus, a new, more accurate rule Q can be obtained by solving
Q-S=16(Q-S_2)
so, S(f)=S_2(f)+ 1/15 ((S_(f)-S(f))


to compute integral[0, pi/2] cos(x) dx,
code:
f=inline('cos(x)')
Q=quad(f,0,pi/2)


and i have no idea what to do with part (c)

can anyone help me?!!!! plz!!!!

Dani AI

Generated

Good start, — the idea of computing Simpson on a mesh and on the same mesh with half the step, then combining those two results to cancel the leading error, is the right strategy. The algebra in your post got a bit tangled when rearranging; the clean statement is that Richardson extrapolation removes the O(h^4) term and produces an O(h^6) approximation.

The practical formula to use is
Q = (16*S2 - S) / 15
where S is the composite Simpson result with step h and S2 is the Simpson result with step h/2. An easy error estimate for the finer Simpson value is approximately (S2 - S)/15 (signed), and Q will be dramatically more accurate (error drops from O(h^4) to O(h^6)).

For part (c) (f(x)=cos x on [0,pi/2]) note the exact integral equals 1, so you can check convergence directly. Compute S with an even number of subintervals (e.g., n=2), compute S2 with 2n, then form Q. Repeat doubling n to see the error shrink roughly by the expected rate. Keep n even — Simpson requires that.

A short, minimal Python recipe (pure composite Simpson + extrapolation) will get you the numbers and the convergence behavior quickly:

import math

def simpson(f,a,b,n):
    if n%2: raise ValueError('n must be even')
    h=(b-a)/n
    s=f(a)+f(b)
    s+=4*sum(f(a+i*h) for i in range(1,n,2))
    s+=2*sum(f(a+i*h) for i in range(2,n,2))
    return s*h/3

S = simpson(math.cos, 0, math.pi/2, 2)
S2 = simpson(math.cos, 0, math.pi/2, 4)
Q = (16*S2 - S)/15
print(S, S2, Q, 'exact=1')

Troubleshooting: check index ranges in your Simpson sums, ensure n is even, and compare to the exact value 1 to verify correctness. 's reminder about tone is fair; is right to suggest calm, methodical checking.

Recommended Answers

All 3 Replies

NEED NOT TO YELL at people from whom you are asking help!

sorry.............. :(
but i didnt yell at ppl whom im asking help...
I just yelled at me ....cuz i hate myself :'(

hei,there,it is OKay,it was in 911 for u,wasn't it?
in my way,just be in calm,then search yr problem using the keyword ,like the google engine.
thk u!
sage!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.