You are on page 1of 8

# ASSIGNMENT 4

Problem: To evaluate the integral

Using trapezoidal rule and simson’s rule. do the integral using N=2,4,8,….2048. and study the convergence of result. Show it graphically. A particle in simple harmonic potential is given if probability density is given: P(x)= exp(-x2)/sqrt(PI) Find probability of finding particle in range from 0 to 1

Method:
INPUT: For number of intervals N=2,4,8,..2048 for the above function we will find the integral using trapezoidal and simsons rule from 0 to 1 OUTPUT: N 2 4 8 trapizoidal simpsons probability density

7.313702e-001 7.471805e-001 4.215514e-001 7.429841e-001 1.006456e+000 5.678318e-001 7.458656e-001 1.193059e+000 6.731114e-001

468205e-001 1. Here are the graphs: DISCUSSION: From the above problem we can clearly understand that the simsons rule will give much accurate results than that of the . Integral value is converging.483608e+000 8.842255e-001 7.488183e+000 8. And we can find out the probability of finding the particle in the range of 0 to 1.390004e+000 7.ASSIGNMENT 4 16 32 64 128 256 512 1024 2048 7.410342e-001 RESULT: From the output we can see that on increasing the no of intervals.468238e-001 1.465846e-001 1.468252e-001 1. It is the integral value divided by the sqrt of PI.468235e-001 1. And we can see that with the help of simsons rule integral value is converging in a faster rate than that with the trapezoidal rule.094436e-001 7.490694e+000 8.323767e-001 7.240625e-001 7.370363e-001 7.434701e+000 8.468091e-001 1.468231e-001 1.418281e-001 7.396172e-001 7.460613e+000 8.475349e+000 8.314856e+000 7.467644e-001 1.

Problem2: Write two functions float trap(float (* func)(float). float a.ASSIGNMENT 4 trapezoidal rule. float b. float b. So Simpsons rule will give much accurate results in this case. we will approximate it by a trapezoid where as in simsons rule we will approximate it by a parabola. int N) which can be used to integrate the function float func(float) from the lower limit a to upper limit b using N intervals and using the Trapezoidal and Simpson rule respectively Use the functions written above to evaluate the following integrals f(x) a b x 0 1 x^2 0 1 Sin (x) 0 π . float a. we can justify this because in trapezoidal rule . int N) float simp(float (* func)(float).

Are these results in keeping with how you expect the error to scale with N? Method: We have to define two functions which should return the value of integral when function. All these integrals can be done analytically. the number of intervals used. so let y_AN be the analytic result. 8. 0 to 1 OUTPUT: for function sinx ..1024. 4. INPUT: Is given for functions 1... Let y_NUM be the numerical result. Show plot of E(N) with varying N for all the integrals. f(x)=x2. f(x)=Sin(x). range is given as input. 0 to 1 3. we define the error as E(N) = (y_NUM .ASSIGNMENT 4 Evaluate each integral using both the trap() and simp() using N=2. 0 to PI 2.y_AN ) / y_AN where the error depends on N. no of intervals. f(x)=x. .

Problem3: 1. from the output we can understand that Simpsons rule is appropriate results for sin curve and x2 curve. We consider the 1-dimensional motion of a particle of mass m in a time independent potential V(x). Whereas for sin curve and x2 they are approximately parabola curves so. Graph of E(N) versus N is plotted below. that is Simpsons rule is appropriate results for sin curve and x2 curve. DISCUSSION: We can explain the observed result. because x is a straight line and approximation trapezoid is correct here. The fact that the energy E will be conserved allows us to . And trapezoidal rule is giving appropriate result for x.ASSIGNMENT 4 RESULT: When the no of intervals is increasing then the value of integral is converging. And trapezoidal rule is giving appropriate result for x. simpsons rule is giving an appropriate answer.

We consider a particular case where the particle is in bound motion between two points a and b where V(a) = E and V(b) = E and V(x) < E for a < x < b.ASSIGNMENT 4 integrate the equation of motion and obtain a solution in a closed form where for the choice C = 0 the particle is at the position xi at the timet = 0 and x refers to its position at any arbitrary time t. Verify . The time period of the of the oscillation T is given by First consider a particle with m = 1 kg in the potential V(x) = (1/2)α x^2 with α = 4 kg/s^2. Numerically calculate the time period of oscillation and check this against the expected value.

INPUT: Here input is the amplitude. The time period is expected to be different for large amplitude oscillations.1. and if we try this for various values of amplitude. Integration of other function will give the time period.ASSIGNMENT 4 that the frequency does not depend on the amplitude of oscillation. we will find that doesn’t . and that will give the integral. and then using trapezoidal or Simpsons rule we can find out the integral. Numerically verify that for small amplitude oscillations you recover the same results as the simple harmonic oscillator. OUTPUT: T is the time period and that is value of integral. How does the time period vary with the amplitude of oscillations? Show this graphically Method: We have been given V as function. so when amplitude is given. Next consider a potential V(x) = exp( (1/2) α x^2 ) . that will calculate energy E=V(a). But in this case it is better to use Simpsons rule.

time period will be similar to the simple harmonic potential. Graph: DISCUSSION: .ASSIGNMENT 4 change the value of time period and hence the frequency doesn’t change RESULT & DISCUSSION: For the second function given we can observe that at small amplitudes. the value of time period is different from that of the expected value. but at large amplitudes .