I am trying to write a function to perform a Simpson’s rule integration of the 1-dimensional Fresnel integral. And am as new as can be to coding. I am struggling to write a code the solves the integral and plots it for all possible values using arrays. More precisely, I am trying to figure out how to describe y where x is the argument and x' is in a loop of x' limits, which are the limits of the integral, as shown in the picture. Any further recommended changes to my code would be very helpful. The format of the question that was given
This is my current effort. Includes and indented block I cannot get rid of.
import math
import cmath
import numpy as np
import matplotlib.pyplot as plt
NumPoints = 100 #Number of areas to be calculated for integration approximation
λ = 1*10**-6 #Wavelength
z = 0.02 #Screen distance
k = (2*math.pi)/λ #wave number
j = j=cmath.sqrt(-1)
xmin = -0.005 #x = screen coordinate
xmax = +0.005
xvals = np.linspace(xmin,xmax,NumPoints) # x intervals between limits
xdmin = 0.0 #xd = aperture coordinate
xdmax = 2*10**-5
dxd = xdmax/NumPoints
xdvals = np.linspace(xdmin,xdmax,Numpoints) # xd intervals between limits
#All figures in SI
def simpson (x, xd ):
for i in range(Numpoints):
while (xdmin<xd<xdmax):
yvals[i] = (k/2(math.pi)z)math.exp((1jk/2z)(xvals[i] - xd)**2)
integral = np.sum(yvals[i])*dxd
return integral
print("The integral =", simpson, "for the given constants." )
plt.plot(xvals,yvals)
Thanks!