Consider the integral $$ E(x)=\int_{0}^{x} \mathrm{e}^{-t^{2}} \mathrm{~d} t . $$ a) Write a program to calculate \(E(x)\) for values of \(x\) from 0 to 3 in steps of \(0.1 .\) Choose for yourself what method you will use for performing the integral and a suitable number of slices. b) When you are convinced your program is working, extend it further to make a graph of \(E(x)\) as a function of \(x\). If you want to remind yourself of how to make a graph, you should consult Section 3.1, starting on page 88 . Note that there is no known way to perform this particular integral analytically, so numerical approaches are the only way forward.

Short Answer

Expert verified
Use a numerical method like the trapezoidal rule to approximate \(E(x)\). Compute values from 0 to 3 in steps of 0.1 and plot the result.

Step by step solution

01

Choose a Numerical Integration Method

Select a method such as the trapezoidal rule or Simpson's rule for the numerical integration. The trapezoidal rule approximates the area under the curve as a series of trapezoids.
02

Divide the Interval

Divide the interval \([0, 3]\) into smaller intervals (or slices) with a step size of 0.1. This will give you \(\frac{3-0}{0.1}=30\) slices.
03

Implement the Numerical Integration

Write a program using your chosen numerical method. For example, in Python, this could be achieved using the following code for the trapezoidal rule:```pythonimport numpy as np# Define the integrandf = lambda t: np.exp(-t**2)# Define the function to calculate E(x)def E(x, step_size=0.1): n_slices = int(x / step_size) result = 0.5 * f(0) + 0.5 * f(x) for i in range(1, n_slices): result += f(i * step_size) result *= step_size return result# Calculate E(x) for values from 0 to 3 in steps of 0.1x_values = np.arange(0, 3.1, 0.1)E_values = [E(x) for x in x_values]```This code calculates \(E(x)\) using the trapezoidal rule.
04

Verify Your Program

Run your program and verify if the values make sense. You can compare some known values of the error function to see if your results are reasonable.
05

Plot the Graph

Extend your program to plot the graph of \(E(x)\) as a function of \(x\). Here is how you can do it in Python using matplotlib:```pythonimport matplotlib.pyplot as plt# Plot the graphplt.plot(x_values, E_values, label='E(x)')plt.xlabel('x')plt.ylabel('E(x)')plt.title('Graph of E(x) as a function of x')plt.legend()plt.grid(True)plt.show()```This code generates a graph for \(E(x)\) based on the computed values.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

Key Concepts

These are the key concepts you need to understand to accurately answer the question.

trapezoidal rule
The Trapezoidal Rule is a simple method for numerical integration, ideal for approximating the definite integral of a function when an analytical solution is difficult or impossible to achieve.
The basic idea involves breaking the area under the curve into a series of trapezoids rather than rectangles. These trapezoids better approximate the curve, especially for linear or gently curving functions.
To implement the trapezoidal rule, follow these steps:
  • Divide the interval \([a, b]\) into smaller slices of width \(h\).
  • Calculate the area for each trapezoid using the formula: \(\text{Area} = \frac{h}{2} (y_0 + 2y_1 + 2y_2 + ... + 2y_{n-1} + y_n)\).
In our example, for integrating \(E(x) = \int_{0}^{x} e^{-t^2} \mathrm{d} t\), the interval \[0, 3\] is divided into 30 slices as \(h = 0.1\). The integration is then carried out using numpy and Python.
The trapezoidal rule offers a balance between accuracy and computational load, but it may not handle highly nonlinear functions as accurately as other methods like Simpson's rule.
Simpson's rule
Simpson's Rule is another numerical method for integration that generally offers greater accuracy than the Trapezoidal Rule, especially for functions that are quadratic or better approximated by parabolas.
It requires the function values at both the endpoints and the midpoints of the intervals.
This method approximates the area under the curve by fitting a parabola through every three adjacent points, providing a more precise estimate.
Here's how you implement Simpson's Rule:
  • Divide the interval \[a, b\] into an even number of slices, \(n\).
  • Calculate the integral with \(I \approx \frac{h}{3}(y_0 + 4y_1 + 2y_2 + 4y_3 + ... + 2y_{n-2}+4y_{n-1} + y_n)\).
In our integral example, for \(E(x)\), the interval would still be divided, but Simpson's Rule would require calculations for both endpoints and midpoints, enhancing the precision.
Though slightly more complex, Simpson's Rule is particularly valuable for smoother functions and can reduce the error considerably compared to the Trapezoidal Rule.
error function
The Error Function, denoted as \(\text{erf}(x)\), is a special mathematical function that arises in probability, statistics, and partial differential equations related to Gaussian distributions.
It is essentially a scaled integral of the Gaussian function from 0 to a point \(x\).
Mathematically, it can be expressed as: \[ \text{erf}(x) = \frac{2}{\root{\root{}}{\root{}} \root{}} \root{\root{\root{}}}\int_{0}^{x} e^{-t^2} \mathrm{d} t \]Since there's no simple closed form for the integral of \(e^{-t^2}\), which appears in our exercise for computing \(E(x)\), numerical methods like the Trapezoidal and Simpson's Rules are crucial.
These methods allow us to approximate the integral \(E(x)\), giving us a way to compute the error function values iteratively.
By understanding and using the properties of the error function, we can apply these numerical techniques effectively across many fields where Gaussian distributions are common.

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

5.17 The gamma function: A commonly occurring function in physics calculations is the gamma function \(\Gamma(a)\), which is defined by the integral $$ \Gamma(a)=\int_{0}^{\infty} x^{n-1} \mathrm{e}^{-x} \mathrm{~d} x . $$ There is no closed-form expression for the gamma function, but one can calculate its value for given \(a\) by performing the integral above numerically. You have to be careful how you do it, however, if you wish to get an accurate answer. a) Write a program to make a graph of the value of the integrand \(x^{n-1} \mathrm{e}^{-x}\) as a function of \(x\) from \(x=0\) to \(x=5\), with three separate curves for \(a=2,3\), and 4 , all on the same axes. You should find that the integrand starts at zero, rises to a maximum, and then decays again for each curve. b) Show analytically that the maximum falls at \(x=a-1\). c) Most of the area under the integrand falls near the maximum, so to get an accurate value of the gamma function we need to do a good job of this part of the integral. We can change the integral from 0 to \(\infty\) to one over a finite range from 0 to 1 using the change of variables in Eq. (5.67), but this tends to squash the peak towards the edge of the \([0,1]\) range and does a poor job of evaluating the integral accurately. We can do a better job by making a different change of variables that puts the peak in the middle of the integration range, around \(\frac{1}{2}\). We will use the change of variables given in Eq. (5.69), which we repeat here for convenience: $$ z=\frac{x}{c+x} . $$ For what value of \(x\) does this change of variables give \(z=\frac{1}{2}\) ? Hence what is the appropriate choice of the parameter \(c\) that puts the peak of the integrand for the gamma function at \(z=\frac{1}{2}\) ? d) Before we can calculate the gamma function, there is another detail we need to attend to. The integrand \(x^{n-1} \mathrm{e}^{-x}\) can be difficult to evaluate because the factor \(x^{2-1}\) can become very large and the factor \(\mathrm{e}^{-x}\) very small, causing numerical overflow or underflow, or both, for some values of \(x\). Write \(x^{n-1}=\mathrm{e}^{(a-1) \ln x}\) to derive an alternative expression for the integrand that does not suffer from these problems (or at least not so much). Explain why your new expression is better than the old one. e) Now, using the change of variables above and the value of \(c\) you have chosen, write a user-defined function gamma (a) to calculate the gamma function for arbitrary argument \(a\). Use whatever integration method you feel is appropriate. Test your function by using it to calculate and print the value of \(\Gamma\left(\frac{3}{2}\right)\), which is known to be equal to \(\frac{1}{2} \sqrt{\pi} \simeq 0.886\). f) For integer values of \(a\) it can be shown that \(\Gamma(a)\) is equal to the factorial of \(a-\) 1. Use your Python function to calculate \(\Gamma(3), \Gamma(6)\), and \(\Gamma(10)\). You should get answers closely equal to \(2 !=2,5 !=120\), and \(9 !=362880\).

Create a user-defined function \(f(x)\) that returns the value \(1+\frac{1}{2} \tanh 2 x\), then use a central difference to calculate the derivative of the function in the range \(-2 \leq x \leq 2\). Calculate an analytic formula for the derivative and make a graph with your numerical result and the analytic answer on the same plot. It may help to plot the exact answer as lines and the numerical one as dots. (Hint: In Python the tanh function is found in the math package, and it's called simply tanh.)

Diffraction gratings: Light with wavelength \(\lambda\) is incident on a diffraction grating of total width \(w\), gets diffracted, is focused with a lens of focal length \(f\), and falls on a screen: Theory tells us that the intensity of the diffraction pattern on the screen, a distance \(x\) from the central axis of the system, is given by $$ I(x)=\left|\int_{-w / 2}^{w / 2} \sqrt{q(u)} \mathrm{e}^{i 2 \pi x u / \lambda f} \mathrm{~d} u\right|^{2} $$ where \(q(u)\) is the intensity transmission function of the diffraction grating at a distance \(u\) from the central axis, i.e., the fraction of the incident light that the grating lets through. a) Consider a grating with transmission function \(q(u)=\sin ^{2} \alpha u\). What is the separation of the "slits" in this grating, expressed in terms of \(\alpha\) ? b) Write a Python function \(q(u)\) that returns the transmission function \(q(u)=\sin ^{2} \alpha u\) as above at position \(u\) for a grating whose slits have separation \(20 \mu \mathrm{m}\). c) Use your function in a program to calculate and graph the intensity of the diffraction pattern produced by such a grating having ten slits in total, if the incident light has wavelength \(\lambda=500 \mathrm{~nm}\). Assume the lens has a focal length of 1 meter and the screen is \(10 \mathrm{~cm}\) wide. You can use whatever method you think appropriate for doing the integral. Once you've made your choice you'll also need to decide the number of sample points you'll use. What criteria play into this decision? Notice that the integrand in the equation for \(I(x)\) is complex, so you will have to use complex variables in your program. As mentioned in Section 2.2.5, there is a version of the math package for use with complex variables called cmath. In particular you may find the exp function from cmath useful because it can calculate the exponentials of complex arguments. d) Create a visualization of how the diffraction pattern would look on the screen using a density plot (see Section 3.3). Your plot should look something like this: e) Modify your program further to make pictures of the diffraction patterns produced by gratings with the following profiles: i) A transmission profile that obeys \(q(u)=\sin ^{2} \alpha d \sin ^{2} \beta u\), with \(\alpha\) as before and the same total grating width \(w\), and \(\beta=\frac{1}{2} \alpha\). ii) Two "square" slits, meaning slits with \(100 \%\) transmission through the slit and \(0 \%\) transmission everywhere else. Calculate the diffraction pattern for non-identical slits, one \(10 \mu \mathrm{m}\) wide and the other \(20 \mu \mathrm{m}\) wide, with a \(60 \mu \mathrm{m}\) gap between the two.

Gravitational pull of a uniform sheet A uniform square sheet of metal is floating motionless in space: The sheet is \(10 \mathrm{~m}\) on a side and of negligible thickness, and it has a mass of 10 metric tonnes. a) Consider the gravitational force due to the plate felt by a point mass of \(1 \mathrm{~kg}\) a distance \(z\) from the center of the square, in the direction perpendicular to the sheet, as shown above. Show that the component of the force along the \(z\)-axis is $$ F_{z}=G \sigma z \iint_{-L / 2}^{L / 2} \frac{\mathrm{d} x \mathrm{~d} y}{\left(x^{2}+y^{2}+z_{2}^{2}\right)^{3 / 2}}, $$ where \(G=6.674 \times 10^{-11} \mathrm{~m}^{3} \mathrm{~kg}^{-1} \mathrm{~s}^{-2}\) is Newton's gravitational constant and \(\sigma\) is the mass per unit area of the sheet. b) Write a program to calculate and plot the force as a function of \(z\) from \(z=0\) to \(z=10 \mathrm{~m}\). For the double integral use (double) Gaussian quadrature, as in Eq. (5.82), with 100 sample points along each axis. c) You should see a smooth curve, except at very small values of \(z\), where the force should drop off suddenly to zero. This drop is not a real effect, but an artifact of the way we have done the calculation. Explain briefly where this artifact comes from and suggest a strategy to remove it, or at least to decrease its size. This calculation can thought of as a model for the gravitational pull of a galaxy. Most of the mass in a spiral galaxy (such as our own Milky Way) lies in a thin plane or disk passing through the galactic center, and the gravitational pull exerted by that plane on bodies outside the galaxy can be calculated by just the methods we have employed here.

Heat capacity of a solid Debye's theory of solids gives the heat capacity of a solid at temperature \(T\) to be $$ C_{V}=9 V \rho k_{B}\left(\frac{T}{\theta_{D}}\right)^{3} \int_{0}^{\otimes_{D} / T} \frac{x^{4} \mathrm{e}^{x}}{\left(e^{x}-1\right)^{2}} \mathrm{~d} x $$ where \(V\) is the volume of the solid, \(\rho\) is the number density of atoms, \(k_{B}\) is Boltzmann's constant, and \(\theta_{D}\) is the so-called Debye temperature, a property of solids that depends on their density and speed of sound. a) Write a Python function \(\mathrm{cv}(\mathrm{T})\) that calculates \(C_{V}\) for a given value of the temperature, for a sample consisting of 1000 cubic centimeters of solid aluminum, which has a number density of \(\rho=6.022 \times 10^{28} \mathrm{~m}^{-3}\) and a Debye temperature of \(\theta_{D}=428 \mathrm{~K}\). Use Gaussian quadrature to evaluate the integral, with \(N=50\) sample points. b) Use your function to make a graph of the heat capacity as a function of temperature from \(T=5 \mathrm{~K}\) to \(T=500 \mathrm{~K}\).

See all solutions

Recommended explanations on Physics Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free