Upload
others
View
5
Download
0
Embed Size (px)
Citation preview
COMP 605 Introduction to Parallel ComputingHomework 8
rdquoGPUCUDA Waverdquo Generator UsingMatrix-Matrix Multiplication of Airy Disk Function
Mary Thomas
Department of Computer ScienceComputational Science Research Center (CSRC)
San Diego State University (SDSU)
Due 051415Posted 050515
Updated 050515
DRAFT
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 231 Mary Thomas
Table of Contents
1 Homework 8 Instructions2 Matrix-Matrix Multiplication3 rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x4 rdquoSombrerordquo Shaped Functions Bessel Functions5 rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk
Function6 Generating Sombrero using Hadamard Multiplication on Modified
Circle Function7 rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk
Function
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 331 Mary Thomas
Homework 8 Instructions
Comparing CUDA and MPI Matrix-Matrix Mult
Project goal is to compare the efficiencies of an MPI and a CUDAMatrix-Matrix Multiplication implementation for calculating the AiryDisk wave function See Lecture 27CUDA implementation
Your may choose your own CUDA reference codeSome source code will be provided in the COMP605hw8 directoryModified CUDA mat-mul example from the CUDA SDK
httpsdevelopernvidiacomgpu-computing-sdk
SDK examples on tuckoousrlocalcudasamples0S implematrixMulrdquoWorking copy of SDK placed in COMP605hw8gpumatrixMulbased on abovedescribed in Cuda Programming Guide Chapter 3httpdocsnvidiacomcudacuda-c-programming-guideindexhtml
You will need to modify the CUDA code so that is calculates theAiry functions for A and B internally
MPI codeUse HW5 MPI results (yours or a classmate ndash use references)Include summary table ampplot of data used or include on relevantCUDA tables and plots (see below)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 431 Mary Thomas
Homework 8 Instructions
Homework 8 Scaling studies
Matrix Size
Read N from the command lineUse square [NxN] matricesVary the size of matrices
Estimate amp justify an Nmax
Choose 10 measurement points between 1024 and Nmax
For an example see MPI vs CUDA example below
Vary the number of threadsblock for a given N (see rdquoCuda Twallrdquoplot below)Use cuda properties to check that your matrix fits on the device
Performance
Time code runs (use cudaEvent timers)Calculate statistics on the timingsVary number of device blocks and threads
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 531 Mary Thomas
Homework 8 Instructions
Homework 8 Writeup Instructions
Your work should be written up in the same report format andsubmitted materials used all semester
Source Code (reference source)
Write your own codeOnline sourcesModify code to calculate Airy disk function
Key variables should be read from command line or computeddynamically
You can use the samesimilar plotting that you used in hw5 (seeCOMP605hw5)
Teams of up to 4 members allowed
identify team and rolesplace copy of code data etc in each team members directoryremember the bigger the team the more work you should report
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 631 Mary Thomas
Homework 8 Instructions
Suggestions for comparing MPI and CUDA
You cannot directly compare the MPI PEscores against the CUDAnumber of threads
You can compare related run-time characteristics such as Toptimal as a function of the total problem size
Toptimal can be defined as
defined as the point where increasing the number of processors orthe number of threadsblock no longer significantly reduces therun-time (rsquoturnoverrsquo point)See Figure 1 below rdquo
See and figure 2 and Table3 below
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 731 Mary Thomas
Homework 8 Instructions
Figure 1 CUDA Twall for different Nthreadsblock vs Dim
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 831 Mary Thomas
Homework 8 Instructions
Figure 2 Toptimal as a function of matrix size for MPI and CUDAGPU
tests
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 931 Mary Thomas
Homework 8 Instructions
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1031 Mary Thomas
Homework 8 Instructions
Figure 4 runtime as a function of matrix size for
different thread block sizes
Source Fall 2012 K Withers
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1131 Mary Thomas
Homework 8 Instructions
Figure 5
Image Source Fall 2012 S Escobar
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1231 Mary Thomas
Matrix-Matrix Multiplication
Calculating Bessel Functions Using Matrix-Matrix Multiplication
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Plot of a 2D rotationally symmetric Bessel function
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1331 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric phenomena in Nature
Diffraction of light through a smallcircular aperture (top image)
Particle diffraction at small scalesparticles behave like light photons andcan be scattered by nuclei (bottom)
Signal Processing A square wave iscomposed of all frequencies and acylinder is a 2D rotation of a squarewave the Fourier transform of acylinder is the Circ function (bottomimage)
Other phenomena that are wave like
water waves when a rock is droppedsounds waves on a snare drummechanical vibrations
Airy disk pattern made by light passing through a small
apertureElectron Diffraction from Titanium foil)
2D rotationally symmetric Circ function
REFs httpenwikipediaorgwikiSombrero_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1431 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric functions used to represent nature
Geometry amp Trigonometry eg Newtons rings (light wave reflectionpattern)
Wave theory eg the Point spread function and Xernike polynomials
Huyen-Fresnel Principle eg Diffraction of light through a small circularaperture
Bessel Functions solutions y(x) of Besselrsquos differential equation
Fourier transform of a cylinder rarr Circ functionUsing Gaussian profile to approximate the Airy DiskElectromagnetic waves in a waveguidemany other applications
sinc(x) = sin(x)x or rdquoSombrerordquo function ndash approximates some Besselfunctions
httpwwwcitycollegiatecomnewtons_ringshtmhttpenwikipediaorgwikiPoint_spread_functionhttpenwikipediaorgwikiZernike_polynomialshttpenwikipediaorgwikiHuygens-Fresnel_principlehttpenwikipediaorgwikiBessel_functionhttpwwwcisriteduclasssimg716handouts06_notes_2DfunctionspdfhttpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1531 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
rdquoSombrerordquo Shaped Function sinc(x) = sin(x)x
Matlab has a special function for sinc(x)
Works for 1D 2D 3D function
sinc(x) = sin(x)x has special internals to handle singularities atx=0
Can be used to create a sombrero like plot
sinc(x) is difficult to code in C because of divide by zero issuesneed to avoid (x y) = (0 0)
httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
httpwwwmathworkscomhelpsignalrefsinchtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1631 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to used generate 1D sinc(x) function
sinc(x) = sin(x)x works in theexample below for y=0sinc(0)=sin(0)0= NaN but plottingprogram will ignore this
t = linspace(-55)
y = sinc(t)
plot(ty)
title([rsquo1D Sinc(x) Functionrsquo]
xlabel(rsquoXrsquo)
ylabel(rsquoSinc(X)rsquo)
minus5 minus4 minus3 minus2 minus1 0 1 2 3 4 5minus04
minus02
0
02
04
06
08
11D Sinc(x) Function
X
Sinc
(X)
Plot of Matlab 1D sinc(x)function
REF httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1731 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to generate 2D sinc(x) Sombrero
Sombrero Test Case Matlab code
Calculate sinc(x) using cartesian coordinates
By Mary Thomas
updated March 2015
Created March 2014)
note ni does have to equal nj
scaling factors affect max amplitude
number of wavelengths
Sinc Function
httpenwikipediaorgwikiSombrero_function
clear all
fprintf(rsquoBegin calc cartesian jinc(x) sombreronrsquo)
simple plot
t = linspace(-55)
cartesian representation
ni=51
s=8
f=025
g= 25
s=2
x = linspace(-s s ni)
y = linspace(-s s ni)
1D Sinc(x)
sinc1D = sinc(x)
2D Sinc(xy)
for i=1ni
for j=1ni
r=sqrt(x(i)^2 + y(j)^2)
F(ij) = sin(r)r
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
fprintf(rsquoCalc of f(xy) completed nrsquo)
figure
plot(xsinc1D)
title([rsquo1D Sinc(x) Functionrsquo])
xlabel(rsquoXrsquo) ylabel(rsquoSinc(X)rsquo)
break
figure
surf(xptsyptsF)
title([rsquoSombrero Peaks -- Cartesian Sinc Function F Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
fprintf(rsquoPlot of f(xy) completed nrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1831 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
2D Sombrero Function Using Matlab sinc(x)
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1931 Mary Thomas
rdquoSombrerordquo Shaped Functions Bessel Functions
Generating sinc(x) using rdquoJincrdquo Bessel Function
Bessel Functions can be used toapproximate sinc(x)
Often this function is called the bsincor jsinc
Bessel Function Jinc(x) = J1(x)x
httpmathworldwolframcom
JincFunctionhtml
Plot of a 1D Jinc(x) function
2D rotationally symmetric Circfunction
httpenwikipediaorgwikiBessel_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 231 Mary Thomas
Table of Contents
1 Homework 8 Instructions2 Matrix-Matrix Multiplication3 rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x4 rdquoSombrerordquo Shaped Functions Bessel Functions5 rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk
Function6 Generating Sombrero using Hadamard Multiplication on Modified
Circle Function7 rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk
Function
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 331 Mary Thomas
Homework 8 Instructions
Comparing CUDA and MPI Matrix-Matrix Mult
Project goal is to compare the efficiencies of an MPI and a CUDAMatrix-Matrix Multiplication implementation for calculating the AiryDisk wave function See Lecture 27CUDA implementation
Your may choose your own CUDA reference codeSome source code will be provided in the COMP605hw8 directoryModified CUDA mat-mul example from the CUDA SDK
httpsdevelopernvidiacomgpu-computing-sdk
SDK examples on tuckoousrlocalcudasamples0S implematrixMulrdquoWorking copy of SDK placed in COMP605hw8gpumatrixMulbased on abovedescribed in Cuda Programming Guide Chapter 3httpdocsnvidiacomcudacuda-c-programming-guideindexhtml
You will need to modify the CUDA code so that is calculates theAiry functions for A and B internally
MPI codeUse HW5 MPI results (yours or a classmate ndash use references)Include summary table ampplot of data used or include on relevantCUDA tables and plots (see below)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 431 Mary Thomas
Homework 8 Instructions
Homework 8 Scaling studies
Matrix Size
Read N from the command lineUse square [NxN] matricesVary the size of matrices
Estimate amp justify an Nmax
Choose 10 measurement points between 1024 and Nmax
For an example see MPI vs CUDA example below
Vary the number of threadsblock for a given N (see rdquoCuda Twallrdquoplot below)Use cuda properties to check that your matrix fits on the device
Performance
Time code runs (use cudaEvent timers)Calculate statistics on the timingsVary number of device blocks and threads
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 531 Mary Thomas
Homework 8 Instructions
Homework 8 Writeup Instructions
Your work should be written up in the same report format andsubmitted materials used all semester
Source Code (reference source)
Write your own codeOnline sourcesModify code to calculate Airy disk function
Key variables should be read from command line or computeddynamically
You can use the samesimilar plotting that you used in hw5 (seeCOMP605hw5)
Teams of up to 4 members allowed
identify team and rolesplace copy of code data etc in each team members directoryremember the bigger the team the more work you should report
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 631 Mary Thomas
Homework 8 Instructions
Suggestions for comparing MPI and CUDA
You cannot directly compare the MPI PEscores against the CUDAnumber of threads
You can compare related run-time characteristics such as Toptimal as a function of the total problem size
Toptimal can be defined as
defined as the point where increasing the number of processors orthe number of threadsblock no longer significantly reduces therun-time (rsquoturnoverrsquo point)See Figure 1 below rdquo
See and figure 2 and Table3 below
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 731 Mary Thomas
Homework 8 Instructions
Figure 1 CUDA Twall for different Nthreadsblock vs Dim
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 831 Mary Thomas
Homework 8 Instructions
Figure 2 Toptimal as a function of matrix size for MPI and CUDAGPU
tests
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 931 Mary Thomas
Homework 8 Instructions
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1031 Mary Thomas
Homework 8 Instructions
Figure 4 runtime as a function of matrix size for
different thread block sizes
Source Fall 2012 K Withers
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1131 Mary Thomas
Homework 8 Instructions
Figure 5
Image Source Fall 2012 S Escobar
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1231 Mary Thomas
Matrix-Matrix Multiplication
Calculating Bessel Functions Using Matrix-Matrix Multiplication
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Plot of a 2D rotationally symmetric Bessel function
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1331 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric phenomena in Nature
Diffraction of light through a smallcircular aperture (top image)
Particle diffraction at small scalesparticles behave like light photons andcan be scattered by nuclei (bottom)
Signal Processing A square wave iscomposed of all frequencies and acylinder is a 2D rotation of a squarewave the Fourier transform of acylinder is the Circ function (bottomimage)
Other phenomena that are wave like
water waves when a rock is droppedsounds waves on a snare drummechanical vibrations
Airy disk pattern made by light passing through a small
apertureElectron Diffraction from Titanium foil)
2D rotationally symmetric Circ function
REFs httpenwikipediaorgwikiSombrero_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1431 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric functions used to represent nature
Geometry amp Trigonometry eg Newtons rings (light wave reflectionpattern)
Wave theory eg the Point spread function and Xernike polynomials
Huyen-Fresnel Principle eg Diffraction of light through a small circularaperture
Bessel Functions solutions y(x) of Besselrsquos differential equation
Fourier transform of a cylinder rarr Circ functionUsing Gaussian profile to approximate the Airy DiskElectromagnetic waves in a waveguidemany other applications
sinc(x) = sin(x)x or rdquoSombrerordquo function ndash approximates some Besselfunctions
httpwwwcitycollegiatecomnewtons_ringshtmhttpenwikipediaorgwikiPoint_spread_functionhttpenwikipediaorgwikiZernike_polynomialshttpenwikipediaorgwikiHuygens-Fresnel_principlehttpenwikipediaorgwikiBessel_functionhttpwwwcisriteduclasssimg716handouts06_notes_2DfunctionspdfhttpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1531 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
rdquoSombrerordquo Shaped Function sinc(x) = sin(x)x
Matlab has a special function for sinc(x)
Works for 1D 2D 3D function
sinc(x) = sin(x)x has special internals to handle singularities atx=0
Can be used to create a sombrero like plot
sinc(x) is difficult to code in C because of divide by zero issuesneed to avoid (x y) = (0 0)
httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
httpwwwmathworkscomhelpsignalrefsinchtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1631 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to used generate 1D sinc(x) function
sinc(x) = sin(x)x works in theexample below for y=0sinc(0)=sin(0)0= NaN but plottingprogram will ignore this
t = linspace(-55)
y = sinc(t)
plot(ty)
title([rsquo1D Sinc(x) Functionrsquo]
xlabel(rsquoXrsquo)
ylabel(rsquoSinc(X)rsquo)
minus5 minus4 minus3 minus2 minus1 0 1 2 3 4 5minus04
minus02
0
02
04
06
08
11D Sinc(x) Function
X
Sinc
(X)
Plot of Matlab 1D sinc(x)function
REF httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1731 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to generate 2D sinc(x) Sombrero
Sombrero Test Case Matlab code
Calculate sinc(x) using cartesian coordinates
By Mary Thomas
updated March 2015
Created March 2014)
note ni does have to equal nj
scaling factors affect max amplitude
number of wavelengths
Sinc Function
httpenwikipediaorgwikiSombrero_function
clear all
fprintf(rsquoBegin calc cartesian jinc(x) sombreronrsquo)
simple plot
t = linspace(-55)
cartesian representation
ni=51
s=8
f=025
g= 25
s=2
x = linspace(-s s ni)
y = linspace(-s s ni)
1D Sinc(x)
sinc1D = sinc(x)
2D Sinc(xy)
for i=1ni
for j=1ni
r=sqrt(x(i)^2 + y(j)^2)
F(ij) = sin(r)r
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
fprintf(rsquoCalc of f(xy) completed nrsquo)
figure
plot(xsinc1D)
title([rsquo1D Sinc(x) Functionrsquo])
xlabel(rsquoXrsquo) ylabel(rsquoSinc(X)rsquo)
break
figure
surf(xptsyptsF)
title([rsquoSombrero Peaks -- Cartesian Sinc Function F Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
fprintf(rsquoPlot of f(xy) completed nrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1831 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
2D Sombrero Function Using Matlab sinc(x)
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1931 Mary Thomas
rdquoSombrerordquo Shaped Functions Bessel Functions
Generating sinc(x) using rdquoJincrdquo Bessel Function
Bessel Functions can be used toapproximate sinc(x)
Often this function is called the bsincor jsinc
Bessel Function Jinc(x) = J1(x)x
httpmathworldwolframcom
JincFunctionhtml
Plot of a 1D Jinc(x) function
2D rotationally symmetric Circfunction
httpenwikipediaorgwikiBessel_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 331 Mary Thomas
Homework 8 Instructions
Comparing CUDA and MPI Matrix-Matrix Mult
Project goal is to compare the efficiencies of an MPI and a CUDAMatrix-Matrix Multiplication implementation for calculating the AiryDisk wave function See Lecture 27CUDA implementation
Your may choose your own CUDA reference codeSome source code will be provided in the COMP605hw8 directoryModified CUDA mat-mul example from the CUDA SDK
httpsdevelopernvidiacomgpu-computing-sdk
SDK examples on tuckoousrlocalcudasamples0S implematrixMulrdquoWorking copy of SDK placed in COMP605hw8gpumatrixMulbased on abovedescribed in Cuda Programming Guide Chapter 3httpdocsnvidiacomcudacuda-c-programming-guideindexhtml
You will need to modify the CUDA code so that is calculates theAiry functions for A and B internally
MPI codeUse HW5 MPI results (yours or a classmate ndash use references)Include summary table ampplot of data used or include on relevantCUDA tables and plots (see below)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 431 Mary Thomas
Homework 8 Instructions
Homework 8 Scaling studies
Matrix Size
Read N from the command lineUse square [NxN] matricesVary the size of matrices
Estimate amp justify an Nmax
Choose 10 measurement points between 1024 and Nmax
For an example see MPI vs CUDA example below
Vary the number of threadsblock for a given N (see rdquoCuda Twallrdquoplot below)Use cuda properties to check that your matrix fits on the device
Performance
Time code runs (use cudaEvent timers)Calculate statistics on the timingsVary number of device blocks and threads
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 531 Mary Thomas
Homework 8 Instructions
Homework 8 Writeup Instructions
Your work should be written up in the same report format andsubmitted materials used all semester
Source Code (reference source)
Write your own codeOnline sourcesModify code to calculate Airy disk function
Key variables should be read from command line or computeddynamically
You can use the samesimilar plotting that you used in hw5 (seeCOMP605hw5)
Teams of up to 4 members allowed
identify team and rolesplace copy of code data etc in each team members directoryremember the bigger the team the more work you should report
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 631 Mary Thomas
Homework 8 Instructions
Suggestions for comparing MPI and CUDA
You cannot directly compare the MPI PEscores against the CUDAnumber of threads
You can compare related run-time characteristics such as Toptimal as a function of the total problem size
Toptimal can be defined as
defined as the point where increasing the number of processors orthe number of threadsblock no longer significantly reduces therun-time (rsquoturnoverrsquo point)See Figure 1 below rdquo
See and figure 2 and Table3 below
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 731 Mary Thomas
Homework 8 Instructions
Figure 1 CUDA Twall for different Nthreadsblock vs Dim
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 831 Mary Thomas
Homework 8 Instructions
Figure 2 Toptimal as a function of matrix size for MPI and CUDAGPU
tests
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 931 Mary Thomas
Homework 8 Instructions
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1031 Mary Thomas
Homework 8 Instructions
Figure 4 runtime as a function of matrix size for
different thread block sizes
Source Fall 2012 K Withers
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1131 Mary Thomas
Homework 8 Instructions
Figure 5
Image Source Fall 2012 S Escobar
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1231 Mary Thomas
Matrix-Matrix Multiplication
Calculating Bessel Functions Using Matrix-Matrix Multiplication
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Plot of a 2D rotationally symmetric Bessel function
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1331 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric phenomena in Nature
Diffraction of light through a smallcircular aperture (top image)
Particle diffraction at small scalesparticles behave like light photons andcan be scattered by nuclei (bottom)
Signal Processing A square wave iscomposed of all frequencies and acylinder is a 2D rotation of a squarewave the Fourier transform of acylinder is the Circ function (bottomimage)
Other phenomena that are wave like
water waves when a rock is droppedsounds waves on a snare drummechanical vibrations
Airy disk pattern made by light passing through a small
apertureElectron Diffraction from Titanium foil)
2D rotationally symmetric Circ function
REFs httpenwikipediaorgwikiSombrero_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1431 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric functions used to represent nature
Geometry amp Trigonometry eg Newtons rings (light wave reflectionpattern)
Wave theory eg the Point spread function and Xernike polynomials
Huyen-Fresnel Principle eg Diffraction of light through a small circularaperture
Bessel Functions solutions y(x) of Besselrsquos differential equation
Fourier transform of a cylinder rarr Circ functionUsing Gaussian profile to approximate the Airy DiskElectromagnetic waves in a waveguidemany other applications
sinc(x) = sin(x)x or rdquoSombrerordquo function ndash approximates some Besselfunctions
httpwwwcitycollegiatecomnewtons_ringshtmhttpenwikipediaorgwikiPoint_spread_functionhttpenwikipediaorgwikiZernike_polynomialshttpenwikipediaorgwikiHuygens-Fresnel_principlehttpenwikipediaorgwikiBessel_functionhttpwwwcisriteduclasssimg716handouts06_notes_2DfunctionspdfhttpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1531 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
rdquoSombrerordquo Shaped Function sinc(x) = sin(x)x
Matlab has a special function for sinc(x)
Works for 1D 2D 3D function
sinc(x) = sin(x)x has special internals to handle singularities atx=0
Can be used to create a sombrero like plot
sinc(x) is difficult to code in C because of divide by zero issuesneed to avoid (x y) = (0 0)
httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
httpwwwmathworkscomhelpsignalrefsinchtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1631 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to used generate 1D sinc(x) function
sinc(x) = sin(x)x works in theexample below for y=0sinc(0)=sin(0)0= NaN but plottingprogram will ignore this
t = linspace(-55)
y = sinc(t)
plot(ty)
title([rsquo1D Sinc(x) Functionrsquo]
xlabel(rsquoXrsquo)
ylabel(rsquoSinc(X)rsquo)
minus5 minus4 minus3 minus2 minus1 0 1 2 3 4 5minus04
minus02
0
02
04
06
08
11D Sinc(x) Function
X
Sinc
(X)
Plot of Matlab 1D sinc(x)function
REF httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1731 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to generate 2D sinc(x) Sombrero
Sombrero Test Case Matlab code
Calculate sinc(x) using cartesian coordinates
By Mary Thomas
updated March 2015
Created March 2014)
note ni does have to equal nj
scaling factors affect max amplitude
number of wavelengths
Sinc Function
httpenwikipediaorgwikiSombrero_function
clear all
fprintf(rsquoBegin calc cartesian jinc(x) sombreronrsquo)
simple plot
t = linspace(-55)
cartesian representation
ni=51
s=8
f=025
g= 25
s=2
x = linspace(-s s ni)
y = linspace(-s s ni)
1D Sinc(x)
sinc1D = sinc(x)
2D Sinc(xy)
for i=1ni
for j=1ni
r=sqrt(x(i)^2 + y(j)^2)
F(ij) = sin(r)r
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
fprintf(rsquoCalc of f(xy) completed nrsquo)
figure
plot(xsinc1D)
title([rsquo1D Sinc(x) Functionrsquo])
xlabel(rsquoXrsquo) ylabel(rsquoSinc(X)rsquo)
break
figure
surf(xptsyptsF)
title([rsquoSombrero Peaks -- Cartesian Sinc Function F Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
fprintf(rsquoPlot of f(xy) completed nrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1831 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
2D Sombrero Function Using Matlab sinc(x)
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1931 Mary Thomas
rdquoSombrerordquo Shaped Functions Bessel Functions
Generating sinc(x) using rdquoJincrdquo Bessel Function
Bessel Functions can be used toapproximate sinc(x)
Often this function is called the bsincor jsinc
Bessel Function Jinc(x) = J1(x)x
httpmathworldwolframcom
JincFunctionhtml
Plot of a 1D Jinc(x) function
2D rotationally symmetric Circfunction
httpenwikipediaorgwikiBessel_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 431 Mary Thomas
Homework 8 Instructions
Homework 8 Scaling studies
Matrix Size
Read N from the command lineUse square [NxN] matricesVary the size of matrices
Estimate amp justify an Nmax
Choose 10 measurement points between 1024 and Nmax
For an example see MPI vs CUDA example below
Vary the number of threadsblock for a given N (see rdquoCuda Twallrdquoplot below)Use cuda properties to check that your matrix fits on the device
Performance
Time code runs (use cudaEvent timers)Calculate statistics on the timingsVary number of device blocks and threads
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 531 Mary Thomas
Homework 8 Instructions
Homework 8 Writeup Instructions
Your work should be written up in the same report format andsubmitted materials used all semester
Source Code (reference source)
Write your own codeOnline sourcesModify code to calculate Airy disk function
Key variables should be read from command line or computeddynamically
You can use the samesimilar plotting that you used in hw5 (seeCOMP605hw5)
Teams of up to 4 members allowed
identify team and rolesplace copy of code data etc in each team members directoryremember the bigger the team the more work you should report
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 631 Mary Thomas
Homework 8 Instructions
Suggestions for comparing MPI and CUDA
You cannot directly compare the MPI PEscores against the CUDAnumber of threads
You can compare related run-time characteristics such as Toptimal as a function of the total problem size
Toptimal can be defined as
defined as the point where increasing the number of processors orthe number of threadsblock no longer significantly reduces therun-time (rsquoturnoverrsquo point)See Figure 1 below rdquo
See and figure 2 and Table3 below
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 731 Mary Thomas
Homework 8 Instructions
Figure 1 CUDA Twall for different Nthreadsblock vs Dim
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 831 Mary Thomas
Homework 8 Instructions
Figure 2 Toptimal as a function of matrix size for MPI and CUDAGPU
tests
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 931 Mary Thomas
Homework 8 Instructions
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1031 Mary Thomas
Homework 8 Instructions
Figure 4 runtime as a function of matrix size for
different thread block sizes
Source Fall 2012 K Withers
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1131 Mary Thomas
Homework 8 Instructions
Figure 5
Image Source Fall 2012 S Escobar
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1231 Mary Thomas
Matrix-Matrix Multiplication
Calculating Bessel Functions Using Matrix-Matrix Multiplication
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Plot of a 2D rotationally symmetric Bessel function
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1331 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric phenomena in Nature
Diffraction of light through a smallcircular aperture (top image)
Particle diffraction at small scalesparticles behave like light photons andcan be scattered by nuclei (bottom)
Signal Processing A square wave iscomposed of all frequencies and acylinder is a 2D rotation of a squarewave the Fourier transform of acylinder is the Circ function (bottomimage)
Other phenomena that are wave like
water waves when a rock is droppedsounds waves on a snare drummechanical vibrations
Airy disk pattern made by light passing through a small
apertureElectron Diffraction from Titanium foil)
2D rotationally symmetric Circ function
REFs httpenwikipediaorgwikiSombrero_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1431 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric functions used to represent nature
Geometry amp Trigonometry eg Newtons rings (light wave reflectionpattern)
Wave theory eg the Point spread function and Xernike polynomials
Huyen-Fresnel Principle eg Diffraction of light through a small circularaperture
Bessel Functions solutions y(x) of Besselrsquos differential equation
Fourier transform of a cylinder rarr Circ functionUsing Gaussian profile to approximate the Airy DiskElectromagnetic waves in a waveguidemany other applications
sinc(x) = sin(x)x or rdquoSombrerordquo function ndash approximates some Besselfunctions
httpwwwcitycollegiatecomnewtons_ringshtmhttpenwikipediaorgwikiPoint_spread_functionhttpenwikipediaorgwikiZernike_polynomialshttpenwikipediaorgwikiHuygens-Fresnel_principlehttpenwikipediaorgwikiBessel_functionhttpwwwcisriteduclasssimg716handouts06_notes_2DfunctionspdfhttpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1531 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
rdquoSombrerordquo Shaped Function sinc(x) = sin(x)x
Matlab has a special function for sinc(x)
Works for 1D 2D 3D function
sinc(x) = sin(x)x has special internals to handle singularities atx=0
Can be used to create a sombrero like plot
sinc(x) is difficult to code in C because of divide by zero issuesneed to avoid (x y) = (0 0)
httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
httpwwwmathworkscomhelpsignalrefsinchtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1631 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to used generate 1D sinc(x) function
sinc(x) = sin(x)x works in theexample below for y=0sinc(0)=sin(0)0= NaN but plottingprogram will ignore this
t = linspace(-55)
y = sinc(t)
plot(ty)
title([rsquo1D Sinc(x) Functionrsquo]
xlabel(rsquoXrsquo)
ylabel(rsquoSinc(X)rsquo)
minus5 minus4 minus3 minus2 minus1 0 1 2 3 4 5minus04
minus02
0
02
04
06
08
11D Sinc(x) Function
X
Sinc
(X)
Plot of Matlab 1D sinc(x)function
REF httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1731 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to generate 2D sinc(x) Sombrero
Sombrero Test Case Matlab code
Calculate sinc(x) using cartesian coordinates
By Mary Thomas
updated March 2015
Created March 2014)
note ni does have to equal nj
scaling factors affect max amplitude
number of wavelengths
Sinc Function
httpenwikipediaorgwikiSombrero_function
clear all
fprintf(rsquoBegin calc cartesian jinc(x) sombreronrsquo)
simple plot
t = linspace(-55)
cartesian representation
ni=51
s=8
f=025
g= 25
s=2
x = linspace(-s s ni)
y = linspace(-s s ni)
1D Sinc(x)
sinc1D = sinc(x)
2D Sinc(xy)
for i=1ni
for j=1ni
r=sqrt(x(i)^2 + y(j)^2)
F(ij) = sin(r)r
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
fprintf(rsquoCalc of f(xy) completed nrsquo)
figure
plot(xsinc1D)
title([rsquo1D Sinc(x) Functionrsquo])
xlabel(rsquoXrsquo) ylabel(rsquoSinc(X)rsquo)
break
figure
surf(xptsyptsF)
title([rsquoSombrero Peaks -- Cartesian Sinc Function F Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
fprintf(rsquoPlot of f(xy) completed nrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1831 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
2D Sombrero Function Using Matlab sinc(x)
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1931 Mary Thomas
rdquoSombrerordquo Shaped Functions Bessel Functions
Generating sinc(x) using rdquoJincrdquo Bessel Function
Bessel Functions can be used toapproximate sinc(x)
Often this function is called the bsincor jsinc
Bessel Function Jinc(x) = J1(x)x
httpmathworldwolframcom
JincFunctionhtml
Plot of a 1D Jinc(x) function
2D rotationally symmetric Circfunction
httpenwikipediaorgwikiBessel_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 531 Mary Thomas
Homework 8 Instructions
Homework 8 Writeup Instructions
Your work should be written up in the same report format andsubmitted materials used all semester
Source Code (reference source)
Write your own codeOnline sourcesModify code to calculate Airy disk function
Key variables should be read from command line or computeddynamically
You can use the samesimilar plotting that you used in hw5 (seeCOMP605hw5)
Teams of up to 4 members allowed
identify team and rolesplace copy of code data etc in each team members directoryremember the bigger the team the more work you should report
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 631 Mary Thomas
Homework 8 Instructions
Suggestions for comparing MPI and CUDA
You cannot directly compare the MPI PEscores against the CUDAnumber of threads
You can compare related run-time characteristics such as Toptimal as a function of the total problem size
Toptimal can be defined as
defined as the point where increasing the number of processors orthe number of threadsblock no longer significantly reduces therun-time (rsquoturnoverrsquo point)See Figure 1 below rdquo
See and figure 2 and Table3 below
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 731 Mary Thomas
Homework 8 Instructions
Figure 1 CUDA Twall for different Nthreadsblock vs Dim
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 831 Mary Thomas
Homework 8 Instructions
Figure 2 Toptimal as a function of matrix size for MPI and CUDAGPU
tests
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 931 Mary Thomas
Homework 8 Instructions
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1031 Mary Thomas
Homework 8 Instructions
Figure 4 runtime as a function of matrix size for
different thread block sizes
Source Fall 2012 K Withers
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1131 Mary Thomas
Homework 8 Instructions
Figure 5
Image Source Fall 2012 S Escobar
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1231 Mary Thomas
Matrix-Matrix Multiplication
Calculating Bessel Functions Using Matrix-Matrix Multiplication
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Plot of a 2D rotationally symmetric Bessel function
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1331 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric phenomena in Nature
Diffraction of light through a smallcircular aperture (top image)
Particle diffraction at small scalesparticles behave like light photons andcan be scattered by nuclei (bottom)
Signal Processing A square wave iscomposed of all frequencies and acylinder is a 2D rotation of a squarewave the Fourier transform of acylinder is the Circ function (bottomimage)
Other phenomena that are wave like
water waves when a rock is droppedsounds waves on a snare drummechanical vibrations
Airy disk pattern made by light passing through a small
apertureElectron Diffraction from Titanium foil)
2D rotationally symmetric Circ function
REFs httpenwikipediaorgwikiSombrero_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1431 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric functions used to represent nature
Geometry amp Trigonometry eg Newtons rings (light wave reflectionpattern)
Wave theory eg the Point spread function and Xernike polynomials
Huyen-Fresnel Principle eg Diffraction of light through a small circularaperture
Bessel Functions solutions y(x) of Besselrsquos differential equation
Fourier transform of a cylinder rarr Circ functionUsing Gaussian profile to approximate the Airy DiskElectromagnetic waves in a waveguidemany other applications
sinc(x) = sin(x)x or rdquoSombrerordquo function ndash approximates some Besselfunctions
httpwwwcitycollegiatecomnewtons_ringshtmhttpenwikipediaorgwikiPoint_spread_functionhttpenwikipediaorgwikiZernike_polynomialshttpenwikipediaorgwikiHuygens-Fresnel_principlehttpenwikipediaorgwikiBessel_functionhttpwwwcisriteduclasssimg716handouts06_notes_2DfunctionspdfhttpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1531 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
rdquoSombrerordquo Shaped Function sinc(x) = sin(x)x
Matlab has a special function for sinc(x)
Works for 1D 2D 3D function
sinc(x) = sin(x)x has special internals to handle singularities atx=0
Can be used to create a sombrero like plot
sinc(x) is difficult to code in C because of divide by zero issuesneed to avoid (x y) = (0 0)
httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
httpwwwmathworkscomhelpsignalrefsinchtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1631 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to used generate 1D sinc(x) function
sinc(x) = sin(x)x works in theexample below for y=0sinc(0)=sin(0)0= NaN but plottingprogram will ignore this
t = linspace(-55)
y = sinc(t)
plot(ty)
title([rsquo1D Sinc(x) Functionrsquo]
xlabel(rsquoXrsquo)
ylabel(rsquoSinc(X)rsquo)
minus5 minus4 minus3 minus2 minus1 0 1 2 3 4 5minus04
minus02
0
02
04
06
08
11D Sinc(x) Function
X
Sinc
(X)
Plot of Matlab 1D sinc(x)function
REF httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1731 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to generate 2D sinc(x) Sombrero
Sombrero Test Case Matlab code
Calculate sinc(x) using cartesian coordinates
By Mary Thomas
updated March 2015
Created March 2014)
note ni does have to equal nj
scaling factors affect max amplitude
number of wavelengths
Sinc Function
httpenwikipediaorgwikiSombrero_function
clear all
fprintf(rsquoBegin calc cartesian jinc(x) sombreronrsquo)
simple plot
t = linspace(-55)
cartesian representation
ni=51
s=8
f=025
g= 25
s=2
x = linspace(-s s ni)
y = linspace(-s s ni)
1D Sinc(x)
sinc1D = sinc(x)
2D Sinc(xy)
for i=1ni
for j=1ni
r=sqrt(x(i)^2 + y(j)^2)
F(ij) = sin(r)r
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
fprintf(rsquoCalc of f(xy) completed nrsquo)
figure
plot(xsinc1D)
title([rsquo1D Sinc(x) Functionrsquo])
xlabel(rsquoXrsquo) ylabel(rsquoSinc(X)rsquo)
break
figure
surf(xptsyptsF)
title([rsquoSombrero Peaks -- Cartesian Sinc Function F Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
fprintf(rsquoPlot of f(xy) completed nrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1831 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
2D Sombrero Function Using Matlab sinc(x)
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1931 Mary Thomas
rdquoSombrerordquo Shaped Functions Bessel Functions
Generating sinc(x) using rdquoJincrdquo Bessel Function
Bessel Functions can be used toapproximate sinc(x)
Often this function is called the bsincor jsinc
Bessel Function Jinc(x) = J1(x)x
httpmathworldwolframcom
JincFunctionhtml
Plot of a 1D Jinc(x) function
2D rotationally symmetric Circfunction
httpenwikipediaorgwikiBessel_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 631 Mary Thomas
Homework 8 Instructions
Suggestions for comparing MPI and CUDA
You cannot directly compare the MPI PEscores against the CUDAnumber of threads
You can compare related run-time characteristics such as Toptimal as a function of the total problem size
Toptimal can be defined as
defined as the point where increasing the number of processors orthe number of threadsblock no longer significantly reduces therun-time (rsquoturnoverrsquo point)See Figure 1 below rdquo
See and figure 2 and Table3 below
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 731 Mary Thomas
Homework 8 Instructions
Figure 1 CUDA Twall for different Nthreadsblock vs Dim
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 831 Mary Thomas
Homework 8 Instructions
Figure 2 Toptimal as a function of matrix size for MPI and CUDAGPU
tests
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 931 Mary Thomas
Homework 8 Instructions
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1031 Mary Thomas
Homework 8 Instructions
Figure 4 runtime as a function of matrix size for
different thread block sizes
Source Fall 2012 K Withers
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1131 Mary Thomas
Homework 8 Instructions
Figure 5
Image Source Fall 2012 S Escobar
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1231 Mary Thomas
Matrix-Matrix Multiplication
Calculating Bessel Functions Using Matrix-Matrix Multiplication
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Plot of a 2D rotationally symmetric Bessel function
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1331 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric phenomena in Nature
Diffraction of light through a smallcircular aperture (top image)
Particle diffraction at small scalesparticles behave like light photons andcan be scattered by nuclei (bottom)
Signal Processing A square wave iscomposed of all frequencies and acylinder is a 2D rotation of a squarewave the Fourier transform of acylinder is the Circ function (bottomimage)
Other phenomena that are wave like
water waves when a rock is droppedsounds waves on a snare drummechanical vibrations
Airy disk pattern made by light passing through a small
apertureElectron Diffraction from Titanium foil)
2D rotationally symmetric Circ function
REFs httpenwikipediaorgwikiSombrero_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1431 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric functions used to represent nature
Geometry amp Trigonometry eg Newtons rings (light wave reflectionpattern)
Wave theory eg the Point spread function and Xernike polynomials
Huyen-Fresnel Principle eg Diffraction of light through a small circularaperture
Bessel Functions solutions y(x) of Besselrsquos differential equation
Fourier transform of a cylinder rarr Circ functionUsing Gaussian profile to approximate the Airy DiskElectromagnetic waves in a waveguidemany other applications
sinc(x) = sin(x)x or rdquoSombrerordquo function ndash approximates some Besselfunctions
httpwwwcitycollegiatecomnewtons_ringshtmhttpenwikipediaorgwikiPoint_spread_functionhttpenwikipediaorgwikiZernike_polynomialshttpenwikipediaorgwikiHuygens-Fresnel_principlehttpenwikipediaorgwikiBessel_functionhttpwwwcisriteduclasssimg716handouts06_notes_2DfunctionspdfhttpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1531 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
rdquoSombrerordquo Shaped Function sinc(x) = sin(x)x
Matlab has a special function for sinc(x)
Works for 1D 2D 3D function
sinc(x) = sin(x)x has special internals to handle singularities atx=0
Can be used to create a sombrero like plot
sinc(x) is difficult to code in C because of divide by zero issuesneed to avoid (x y) = (0 0)
httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
httpwwwmathworkscomhelpsignalrefsinchtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1631 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to used generate 1D sinc(x) function
sinc(x) = sin(x)x works in theexample below for y=0sinc(0)=sin(0)0= NaN but plottingprogram will ignore this
t = linspace(-55)
y = sinc(t)
plot(ty)
title([rsquo1D Sinc(x) Functionrsquo]
xlabel(rsquoXrsquo)
ylabel(rsquoSinc(X)rsquo)
minus5 minus4 minus3 minus2 minus1 0 1 2 3 4 5minus04
minus02
0
02
04
06
08
11D Sinc(x) Function
X
Sinc
(X)
Plot of Matlab 1D sinc(x)function
REF httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1731 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to generate 2D sinc(x) Sombrero
Sombrero Test Case Matlab code
Calculate sinc(x) using cartesian coordinates
By Mary Thomas
updated March 2015
Created March 2014)
note ni does have to equal nj
scaling factors affect max amplitude
number of wavelengths
Sinc Function
httpenwikipediaorgwikiSombrero_function
clear all
fprintf(rsquoBegin calc cartesian jinc(x) sombreronrsquo)
simple plot
t = linspace(-55)
cartesian representation
ni=51
s=8
f=025
g= 25
s=2
x = linspace(-s s ni)
y = linspace(-s s ni)
1D Sinc(x)
sinc1D = sinc(x)
2D Sinc(xy)
for i=1ni
for j=1ni
r=sqrt(x(i)^2 + y(j)^2)
F(ij) = sin(r)r
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
fprintf(rsquoCalc of f(xy) completed nrsquo)
figure
plot(xsinc1D)
title([rsquo1D Sinc(x) Functionrsquo])
xlabel(rsquoXrsquo) ylabel(rsquoSinc(X)rsquo)
break
figure
surf(xptsyptsF)
title([rsquoSombrero Peaks -- Cartesian Sinc Function F Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
fprintf(rsquoPlot of f(xy) completed nrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1831 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
2D Sombrero Function Using Matlab sinc(x)
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1931 Mary Thomas
rdquoSombrerordquo Shaped Functions Bessel Functions
Generating sinc(x) using rdquoJincrdquo Bessel Function
Bessel Functions can be used toapproximate sinc(x)
Often this function is called the bsincor jsinc
Bessel Function Jinc(x) = J1(x)x
httpmathworldwolframcom
JincFunctionhtml
Plot of a 1D Jinc(x) function
2D rotationally symmetric Circfunction
httpenwikipediaorgwikiBessel_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 731 Mary Thomas
Homework 8 Instructions
Figure 1 CUDA Twall for different Nthreadsblock vs Dim
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 831 Mary Thomas
Homework 8 Instructions
Figure 2 Toptimal as a function of matrix size for MPI and CUDAGPU
tests
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 931 Mary Thomas
Homework 8 Instructions
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1031 Mary Thomas
Homework 8 Instructions
Figure 4 runtime as a function of matrix size for
different thread block sizes
Source Fall 2012 K Withers
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1131 Mary Thomas
Homework 8 Instructions
Figure 5
Image Source Fall 2012 S Escobar
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1231 Mary Thomas
Matrix-Matrix Multiplication
Calculating Bessel Functions Using Matrix-Matrix Multiplication
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Plot of a 2D rotationally symmetric Bessel function
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1331 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric phenomena in Nature
Diffraction of light through a smallcircular aperture (top image)
Particle diffraction at small scalesparticles behave like light photons andcan be scattered by nuclei (bottom)
Signal Processing A square wave iscomposed of all frequencies and acylinder is a 2D rotation of a squarewave the Fourier transform of acylinder is the Circ function (bottomimage)
Other phenomena that are wave like
water waves when a rock is droppedsounds waves on a snare drummechanical vibrations
Airy disk pattern made by light passing through a small
apertureElectron Diffraction from Titanium foil)
2D rotationally symmetric Circ function
REFs httpenwikipediaorgwikiSombrero_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1431 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric functions used to represent nature
Geometry amp Trigonometry eg Newtons rings (light wave reflectionpattern)
Wave theory eg the Point spread function and Xernike polynomials
Huyen-Fresnel Principle eg Diffraction of light through a small circularaperture
Bessel Functions solutions y(x) of Besselrsquos differential equation
Fourier transform of a cylinder rarr Circ functionUsing Gaussian profile to approximate the Airy DiskElectromagnetic waves in a waveguidemany other applications
sinc(x) = sin(x)x or rdquoSombrerordquo function ndash approximates some Besselfunctions
httpwwwcitycollegiatecomnewtons_ringshtmhttpenwikipediaorgwikiPoint_spread_functionhttpenwikipediaorgwikiZernike_polynomialshttpenwikipediaorgwikiHuygens-Fresnel_principlehttpenwikipediaorgwikiBessel_functionhttpwwwcisriteduclasssimg716handouts06_notes_2DfunctionspdfhttpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1531 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
rdquoSombrerordquo Shaped Function sinc(x) = sin(x)x
Matlab has a special function for sinc(x)
Works for 1D 2D 3D function
sinc(x) = sin(x)x has special internals to handle singularities atx=0
Can be used to create a sombrero like plot
sinc(x) is difficult to code in C because of divide by zero issuesneed to avoid (x y) = (0 0)
httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
httpwwwmathworkscomhelpsignalrefsinchtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1631 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to used generate 1D sinc(x) function
sinc(x) = sin(x)x works in theexample below for y=0sinc(0)=sin(0)0= NaN but plottingprogram will ignore this
t = linspace(-55)
y = sinc(t)
plot(ty)
title([rsquo1D Sinc(x) Functionrsquo]
xlabel(rsquoXrsquo)
ylabel(rsquoSinc(X)rsquo)
minus5 minus4 minus3 minus2 minus1 0 1 2 3 4 5minus04
minus02
0
02
04
06
08
11D Sinc(x) Function
X
Sinc
(X)
Plot of Matlab 1D sinc(x)function
REF httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1731 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to generate 2D sinc(x) Sombrero
Sombrero Test Case Matlab code
Calculate sinc(x) using cartesian coordinates
By Mary Thomas
updated March 2015
Created March 2014)
note ni does have to equal nj
scaling factors affect max amplitude
number of wavelengths
Sinc Function
httpenwikipediaorgwikiSombrero_function
clear all
fprintf(rsquoBegin calc cartesian jinc(x) sombreronrsquo)
simple plot
t = linspace(-55)
cartesian representation
ni=51
s=8
f=025
g= 25
s=2
x = linspace(-s s ni)
y = linspace(-s s ni)
1D Sinc(x)
sinc1D = sinc(x)
2D Sinc(xy)
for i=1ni
for j=1ni
r=sqrt(x(i)^2 + y(j)^2)
F(ij) = sin(r)r
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
fprintf(rsquoCalc of f(xy) completed nrsquo)
figure
plot(xsinc1D)
title([rsquo1D Sinc(x) Functionrsquo])
xlabel(rsquoXrsquo) ylabel(rsquoSinc(X)rsquo)
break
figure
surf(xptsyptsF)
title([rsquoSombrero Peaks -- Cartesian Sinc Function F Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
fprintf(rsquoPlot of f(xy) completed nrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1831 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
2D Sombrero Function Using Matlab sinc(x)
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1931 Mary Thomas
rdquoSombrerordquo Shaped Functions Bessel Functions
Generating sinc(x) using rdquoJincrdquo Bessel Function
Bessel Functions can be used toapproximate sinc(x)
Often this function is called the bsincor jsinc
Bessel Function Jinc(x) = J1(x)x
httpmathworldwolframcom
JincFunctionhtml
Plot of a 1D Jinc(x) function
2D rotationally symmetric Circfunction
httpenwikipediaorgwikiBessel_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 831 Mary Thomas
Homework 8 Instructions
Figure 2 Toptimal as a function of matrix size for MPI and CUDAGPU
tests
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 931 Mary Thomas
Homework 8 Instructions
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1031 Mary Thomas
Homework 8 Instructions
Figure 4 runtime as a function of matrix size for
different thread block sizes
Source Fall 2012 K Withers
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1131 Mary Thomas
Homework 8 Instructions
Figure 5
Image Source Fall 2012 S Escobar
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1231 Mary Thomas
Matrix-Matrix Multiplication
Calculating Bessel Functions Using Matrix-Matrix Multiplication
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Plot of a 2D rotationally symmetric Bessel function
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1331 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric phenomena in Nature
Diffraction of light through a smallcircular aperture (top image)
Particle diffraction at small scalesparticles behave like light photons andcan be scattered by nuclei (bottom)
Signal Processing A square wave iscomposed of all frequencies and acylinder is a 2D rotation of a squarewave the Fourier transform of acylinder is the Circ function (bottomimage)
Other phenomena that are wave like
water waves when a rock is droppedsounds waves on a snare drummechanical vibrations
Airy disk pattern made by light passing through a small
apertureElectron Diffraction from Titanium foil)
2D rotationally symmetric Circ function
REFs httpenwikipediaorgwikiSombrero_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1431 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric functions used to represent nature
Geometry amp Trigonometry eg Newtons rings (light wave reflectionpattern)
Wave theory eg the Point spread function and Xernike polynomials
Huyen-Fresnel Principle eg Diffraction of light through a small circularaperture
Bessel Functions solutions y(x) of Besselrsquos differential equation
Fourier transform of a cylinder rarr Circ functionUsing Gaussian profile to approximate the Airy DiskElectromagnetic waves in a waveguidemany other applications
sinc(x) = sin(x)x or rdquoSombrerordquo function ndash approximates some Besselfunctions
httpwwwcitycollegiatecomnewtons_ringshtmhttpenwikipediaorgwikiPoint_spread_functionhttpenwikipediaorgwikiZernike_polynomialshttpenwikipediaorgwikiHuygens-Fresnel_principlehttpenwikipediaorgwikiBessel_functionhttpwwwcisriteduclasssimg716handouts06_notes_2DfunctionspdfhttpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1531 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
rdquoSombrerordquo Shaped Function sinc(x) = sin(x)x
Matlab has a special function for sinc(x)
Works for 1D 2D 3D function
sinc(x) = sin(x)x has special internals to handle singularities atx=0
Can be used to create a sombrero like plot
sinc(x) is difficult to code in C because of divide by zero issuesneed to avoid (x y) = (0 0)
httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
httpwwwmathworkscomhelpsignalrefsinchtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1631 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to used generate 1D sinc(x) function
sinc(x) = sin(x)x works in theexample below for y=0sinc(0)=sin(0)0= NaN but plottingprogram will ignore this
t = linspace(-55)
y = sinc(t)
plot(ty)
title([rsquo1D Sinc(x) Functionrsquo]
xlabel(rsquoXrsquo)
ylabel(rsquoSinc(X)rsquo)
minus5 minus4 minus3 minus2 minus1 0 1 2 3 4 5minus04
minus02
0
02
04
06
08
11D Sinc(x) Function
X
Sinc
(X)
Plot of Matlab 1D sinc(x)function
REF httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1731 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to generate 2D sinc(x) Sombrero
Sombrero Test Case Matlab code
Calculate sinc(x) using cartesian coordinates
By Mary Thomas
updated March 2015
Created March 2014)
note ni does have to equal nj
scaling factors affect max amplitude
number of wavelengths
Sinc Function
httpenwikipediaorgwikiSombrero_function
clear all
fprintf(rsquoBegin calc cartesian jinc(x) sombreronrsquo)
simple plot
t = linspace(-55)
cartesian representation
ni=51
s=8
f=025
g= 25
s=2
x = linspace(-s s ni)
y = linspace(-s s ni)
1D Sinc(x)
sinc1D = sinc(x)
2D Sinc(xy)
for i=1ni
for j=1ni
r=sqrt(x(i)^2 + y(j)^2)
F(ij) = sin(r)r
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
fprintf(rsquoCalc of f(xy) completed nrsquo)
figure
plot(xsinc1D)
title([rsquo1D Sinc(x) Functionrsquo])
xlabel(rsquoXrsquo) ylabel(rsquoSinc(X)rsquo)
break
figure
surf(xptsyptsF)
title([rsquoSombrero Peaks -- Cartesian Sinc Function F Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
fprintf(rsquoPlot of f(xy) completed nrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1831 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
2D Sombrero Function Using Matlab sinc(x)
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1931 Mary Thomas
rdquoSombrerordquo Shaped Functions Bessel Functions
Generating sinc(x) using rdquoJincrdquo Bessel Function
Bessel Functions can be used toapproximate sinc(x)
Often this function is called the bsincor jsinc
Bessel Function Jinc(x) = J1(x)x
httpmathworldwolframcom
JincFunctionhtml
Plot of a 1D Jinc(x) function
2D rotationally symmetric Circfunction
httpenwikipediaorgwikiBessel_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 931 Mary Thomas
Homework 8 Instructions
Source Fall 2012 G Pham
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1031 Mary Thomas
Homework 8 Instructions
Figure 4 runtime as a function of matrix size for
different thread block sizes
Source Fall 2012 K Withers
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1131 Mary Thomas
Homework 8 Instructions
Figure 5
Image Source Fall 2012 S Escobar
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1231 Mary Thomas
Matrix-Matrix Multiplication
Calculating Bessel Functions Using Matrix-Matrix Multiplication
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Plot of a 2D rotationally symmetric Bessel function
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1331 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric phenomena in Nature
Diffraction of light through a smallcircular aperture (top image)
Particle diffraction at small scalesparticles behave like light photons andcan be scattered by nuclei (bottom)
Signal Processing A square wave iscomposed of all frequencies and acylinder is a 2D rotation of a squarewave the Fourier transform of acylinder is the Circ function (bottomimage)
Other phenomena that are wave like
water waves when a rock is droppedsounds waves on a snare drummechanical vibrations
Airy disk pattern made by light passing through a small
apertureElectron Diffraction from Titanium foil)
2D rotationally symmetric Circ function
REFs httpenwikipediaorgwikiSombrero_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1431 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric functions used to represent nature
Geometry amp Trigonometry eg Newtons rings (light wave reflectionpattern)
Wave theory eg the Point spread function and Xernike polynomials
Huyen-Fresnel Principle eg Diffraction of light through a small circularaperture
Bessel Functions solutions y(x) of Besselrsquos differential equation
Fourier transform of a cylinder rarr Circ functionUsing Gaussian profile to approximate the Airy DiskElectromagnetic waves in a waveguidemany other applications
sinc(x) = sin(x)x or rdquoSombrerordquo function ndash approximates some Besselfunctions
httpwwwcitycollegiatecomnewtons_ringshtmhttpenwikipediaorgwikiPoint_spread_functionhttpenwikipediaorgwikiZernike_polynomialshttpenwikipediaorgwikiHuygens-Fresnel_principlehttpenwikipediaorgwikiBessel_functionhttpwwwcisriteduclasssimg716handouts06_notes_2DfunctionspdfhttpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1531 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
rdquoSombrerordquo Shaped Function sinc(x) = sin(x)x
Matlab has a special function for sinc(x)
Works for 1D 2D 3D function
sinc(x) = sin(x)x has special internals to handle singularities atx=0
Can be used to create a sombrero like plot
sinc(x) is difficult to code in C because of divide by zero issuesneed to avoid (x y) = (0 0)
httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
httpwwwmathworkscomhelpsignalrefsinchtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1631 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to used generate 1D sinc(x) function
sinc(x) = sin(x)x works in theexample below for y=0sinc(0)=sin(0)0= NaN but plottingprogram will ignore this
t = linspace(-55)
y = sinc(t)
plot(ty)
title([rsquo1D Sinc(x) Functionrsquo]
xlabel(rsquoXrsquo)
ylabel(rsquoSinc(X)rsquo)
minus5 minus4 minus3 minus2 minus1 0 1 2 3 4 5minus04
minus02
0
02
04
06
08
11D Sinc(x) Function
X
Sinc
(X)
Plot of Matlab 1D sinc(x)function
REF httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1731 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to generate 2D sinc(x) Sombrero
Sombrero Test Case Matlab code
Calculate sinc(x) using cartesian coordinates
By Mary Thomas
updated March 2015
Created March 2014)
note ni does have to equal nj
scaling factors affect max amplitude
number of wavelengths
Sinc Function
httpenwikipediaorgwikiSombrero_function
clear all
fprintf(rsquoBegin calc cartesian jinc(x) sombreronrsquo)
simple plot
t = linspace(-55)
cartesian representation
ni=51
s=8
f=025
g= 25
s=2
x = linspace(-s s ni)
y = linspace(-s s ni)
1D Sinc(x)
sinc1D = sinc(x)
2D Sinc(xy)
for i=1ni
for j=1ni
r=sqrt(x(i)^2 + y(j)^2)
F(ij) = sin(r)r
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
fprintf(rsquoCalc of f(xy) completed nrsquo)
figure
plot(xsinc1D)
title([rsquo1D Sinc(x) Functionrsquo])
xlabel(rsquoXrsquo) ylabel(rsquoSinc(X)rsquo)
break
figure
surf(xptsyptsF)
title([rsquoSombrero Peaks -- Cartesian Sinc Function F Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
fprintf(rsquoPlot of f(xy) completed nrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1831 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
2D Sombrero Function Using Matlab sinc(x)
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1931 Mary Thomas
rdquoSombrerordquo Shaped Functions Bessel Functions
Generating sinc(x) using rdquoJincrdquo Bessel Function
Bessel Functions can be used toapproximate sinc(x)
Often this function is called the bsincor jsinc
Bessel Function Jinc(x) = J1(x)x
httpmathworldwolframcom
JincFunctionhtml
Plot of a 1D Jinc(x) function
2D rotationally symmetric Circfunction
httpenwikipediaorgwikiBessel_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1031 Mary Thomas
Homework 8 Instructions
Figure 4 runtime as a function of matrix size for
different thread block sizes
Source Fall 2012 K Withers
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1131 Mary Thomas
Homework 8 Instructions
Figure 5
Image Source Fall 2012 S Escobar
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1231 Mary Thomas
Matrix-Matrix Multiplication
Calculating Bessel Functions Using Matrix-Matrix Multiplication
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Plot of a 2D rotationally symmetric Bessel function
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1331 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric phenomena in Nature
Diffraction of light through a smallcircular aperture (top image)
Particle diffraction at small scalesparticles behave like light photons andcan be scattered by nuclei (bottom)
Signal Processing A square wave iscomposed of all frequencies and acylinder is a 2D rotation of a squarewave the Fourier transform of acylinder is the Circ function (bottomimage)
Other phenomena that are wave like
water waves when a rock is droppedsounds waves on a snare drummechanical vibrations
Airy disk pattern made by light passing through a small
apertureElectron Diffraction from Titanium foil)
2D rotationally symmetric Circ function
REFs httpenwikipediaorgwikiSombrero_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1431 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric functions used to represent nature
Geometry amp Trigonometry eg Newtons rings (light wave reflectionpattern)
Wave theory eg the Point spread function and Xernike polynomials
Huyen-Fresnel Principle eg Diffraction of light through a small circularaperture
Bessel Functions solutions y(x) of Besselrsquos differential equation
Fourier transform of a cylinder rarr Circ functionUsing Gaussian profile to approximate the Airy DiskElectromagnetic waves in a waveguidemany other applications
sinc(x) = sin(x)x or rdquoSombrerordquo function ndash approximates some Besselfunctions
httpwwwcitycollegiatecomnewtons_ringshtmhttpenwikipediaorgwikiPoint_spread_functionhttpenwikipediaorgwikiZernike_polynomialshttpenwikipediaorgwikiHuygens-Fresnel_principlehttpenwikipediaorgwikiBessel_functionhttpwwwcisriteduclasssimg716handouts06_notes_2DfunctionspdfhttpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1531 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
rdquoSombrerordquo Shaped Function sinc(x) = sin(x)x
Matlab has a special function for sinc(x)
Works for 1D 2D 3D function
sinc(x) = sin(x)x has special internals to handle singularities atx=0
Can be used to create a sombrero like plot
sinc(x) is difficult to code in C because of divide by zero issuesneed to avoid (x y) = (0 0)
httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
httpwwwmathworkscomhelpsignalrefsinchtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1631 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to used generate 1D sinc(x) function
sinc(x) = sin(x)x works in theexample below for y=0sinc(0)=sin(0)0= NaN but plottingprogram will ignore this
t = linspace(-55)
y = sinc(t)
plot(ty)
title([rsquo1D Sinc(x) Functionrsquo]
xlabel(rsquoXrsquo)
ylabel(rsquoSinc(X)rsquo)
minus5 minus4 minus3 minus2 minus1 0 1 2 3 4 5minus04
minus02
0
02
04
06
08
11D Sinc(x) Function
X
Sinc
(X)
Plot of Matlab 1D sinc(x)function
REF httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1731 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to generate 2D sinc(x) Sombrero
Sombrero Test Case Matlab code
Calculate sinc(x) using cartesian coordinates
By Mary Thomas
updated March 2015
Created March 2014)
note ni does have to equal nj
scaling factors affect max amplitude
number of wavelengths
Sinc Function
httpenwikipediaorgwikiSombrero_function
clear all
fprintf(rsquoBegin calc cartesian jinc(x) sombreronrsquo)
simple plot
t = linspace(-55)
cartesian representation
ni=51
s=8
f=025
g= 25
s=2
x = linspace(-s s ni)
y = linspace(-s s ni)
1D Sinc(x)
sinc1D = sinc(x)
2D Sinc(xy)
for i=1ni
for j=1ni
r=sqrt(x(i)^2 + y(j)^2)
F(ij) = sin(r)r
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
fprintf(rsquoCalc of f(xy) completed nrsquo)
figure
plot(xsinc1D)
title([rsquo1D Sinc(x) Functionrsquo])
xlabel(rsquoXrsquo) ylabel(rsquoSinc(X)rsquo)
break
figure
surf(xptsyptsF)
title([rsquoSombrero Peaks -- Cartesian Sinc Function F Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
fprintf(rsquoPlot of f(xy) completed nrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1831 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
2D Sombrero Function Using Matlab sinc(x)
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1931 Mary Thomas
rdquoSombrerordquo Shaped Functions Bessel Functions
Generating sinc(x) using rdquoJincrdquo Bessel Function
Bessel Functions can be used toapproximate sinc(x)
Often this function is called the bsincor jsinc
Bessel Function Jinc(x) = J1(x)x
httpmathworldwolframcom
JincFunctionhtml
Plot of a 1D Jinc(x) function
2D rotationally symmetric Circfunction
httpenwikipediaorgwikiBessel_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1131 Mary Thomas
Homework 8 Instructions
Figure 5
Image Source Fall 2012 S Escobar
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1231 Mary Thomas
Matrix-Matrix Multiplication
Calculating Bessel Functions Using Matrix-Matrix Multiplication
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Plot of a 2D rotationally symmetric Bessel function
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1331 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric phenomena in Nature
Diffraction of light through a smallcircular aperture (top image)
Particle diffraction at small scalesparticles behave like light photons andcan be scattered by nuclei (bottom)
Signal Processing A square wave iscomposed of all frequencies and acylinder is a 2D rotation of a squarewave the Fourier transform of acylinder is the Circ function (bottomimage)
Other phenomena that are wave like
water waves when a rock is droppedsounds waves on a snare drummechanical vibrations
Airy disk pattern made by light passing through a small
apertureElectron Diffraction from Titanium foil)
2D rotationally symmetric Circ function
REFs httpenwikipediaorgwikiSombrero_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1431 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric functions used to represent nature
Geometry amp Trigonometry eg Newtons rings (light wave reflectionpattern)
Wave theory eg the Point spread function and Xernike polynomials
Huyen-Fresnel Principle eg Diffraction of light through a small circularaperture
Bessel Functions solutions y(x) of Besselrsquos differential equation
Fourier transform of a cylinder rarr Circ functionUsing Gaussian profile to approximate the Airy DiskElectromagnetic waves in a waveguidemany other applications
sinc(x) = sin(x)x or rdquoSombrerordquo function ndash approximates some Besselfunctions
httpwwwcitycollegiatecomnewtons_ringshtmhttpenwikipediaorgwikiPoint_spread_functionhttpenwikipediaorgwikiZernike_polynomialshttpenwikipediaorgwikiHuygens-Fresnel_principlehttpenwikipediaorgwikiBessel_functionhttpwwwcisriteduclasssimg716handouts06_notes_2DfunctionspdfhttpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1531 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
rdquoSombrerordquo Shaped Function sinc(x) = sin(x)x
Matlab has a special function for sinc(x)
Works for 1D 2D 3D function
sinc(x) = sin(x)x has special internals to handle singularities atx=0
Can be used to create a sombrero like plot
sinc(x) is difficult to code in C because of divide by zero issuesneed to avoid (x y) = (0 0)
httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
httpwwwmathworkscomhelpsignalrefsinchtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1631 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to used generate 1D sinc(x) function
sinc(x) = sin(x)x works in theexample below for y=0sinc(0)=sin(0)0= NaN but plottingprogram will ignore this
t = linspace(-55)
y = sinc(t)
plot(ty)
title([rsquo1D Sinc(x) Functionrsquo]
xlabel(rsquoXrsquo)
ylabel(rsquoSinc(X)rsquo)
minus5 minus4 minus3 minus2 minus1 0 1 2 3 4 5minus04
minus02
0
02
04
06
08
11D Sinc(x) Function
X
Sinc
(X)
Plot of Matlab 1D sinc(x)function
REF httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1731 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to generate 2D sinc(x) Sombrero
Sombrero Test Case Matlab code
Calculate sinc(x) using cartesian coordinates
By Mary Thomas
updated March 2015
Created March 2014)
note ni does have to equal nj
scaling factors affect max amplitude
number of wavelengths
Sinc Function
httpenwikipediaorgwikiSombrero_function
clear all
fprintf(rsquoBegin calc cartesian jinc(x) sombreronrsquo)
simple plot
t = linspace(-55)
cartesian representation
ni=51
s=8
f=025
g= 25
s=2
x = linspace(-s s ni)
y = linspace(-s s ni)
1D Sinc(x)
sinc1D = sinc(x)
2D Sinc(xy)
for i=1ni
for j=1ni
r=sqrt(x(i)^2 + y(j)^2)
F(ij) = sin(r)r
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
fprintf(rsquoCalc of f(xy) completed nrsquo)
figure
plot(xsinc1D)
title([rsquo1D Sinc(x) Functionrsquo])
xlabel(rsquoXrsquo) ylabel(rsquoSinc(X)rsquo)
break
figure
surf(xptsyptsF)
title([rsquoSombrero Peaks -- Cartesian Sinc Function F Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
fprintf(rsquoPlot of f(xy) completed nrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1831 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
2D Sombrero Function Using Matlab sinc(x)
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1931 Mary Thomas
rdquoSombrerordquo Shaped Functions Bessel Functions
Generating sinc(x) using rdquoJincrdquo Bessel Function
Bessel Functions can be used toapproximate sinc(x)
Often this function is called the bsincor jsinc
Bessel Function Jinc(x) = J1(x)x
httpmathworldwolframcom
JincFunctionhtml
Plot of a 1D Jinc(x) function
2D rotationally symmetric Circfunction
httpenwikipediaorgwikiBessel_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1231 Mary Thomas
Matrix-Matrix Multiplication
Calculating Bessel Functions Using Matrix-Matrix Multiplication
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Plot of a 2D rotationally symmetric Bessel function
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1331 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric phenomena in Nature
Diffraction of light through a smallcircular aperture (top image)
Particle diffraction at small scalesparticles behave like light photons andcan be scattered by nuclei (bottom)
Signal Processing A square wave iscomposed of all frequencies and acylinder is a 2D rotation of a squarewave the Fourier transform of acylinder is the Circ function (bottomimage)
Other phenomena that are wave like
water waves when a rock is droppedsounds waves on a snare drummechanical vibrations
Airy disk pattern made by light passing through a small
apertureElectron Diffraction from Titanium foil)
2D rotationally symmetric Circ function
REFs httpenwikipediaorgwikiSombrero_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1431 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric functions used to represent nature
Geometry amp Trigonometry eg Newtons rings (light wave reflectionpattern)
Wave theory eg the Point spread function and Xernike polynomials
Huyen-Fresnel Principle eg Diffraction of light through a small circularaperture
Bessel Functions solutions y(x) of Besselrsquos differential equation
Fourier transform of a cylinder rarr Circ functionUsing Gaussian profile to approximate the Airy DiskElectromagnetic waves in a waveguidemany other applications
sinc(x) = sin(x)x or rdquoSombrerordquo function ndash approximates some Besselfunctions
httpwwwcitycollegiatecomnewtons_ringshtmhttpenwikipediaorgwikiPoint_spread_functionhttpenwikipediaorgwikiZernike_polynomialshttpenwikipediaorgwikiHuygens-Fresnel_principlehttpenwikipediaorgwikiBessel_functionhttpwwwcisriteduclasssimg716handouts06_notes_2DfunctionspdfhttpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1531 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
rdquoSombrerordquo Shaped Function sinc(x) = sin(x)x
Matlab has a special function for sinc(x)
Works for 1D 2D 3D function
sinc(x) = sin(x)x has special internals to handle singularities atx=0
Can be used to create a sombrero like plot
sinc(x) is difficult to code in C because of divide by zero issuesneed to avoid (x y) = (0 0)
httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
httpwwwmathworkscomhelpsignalrefsinchtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1631 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to used generate 1D sinc(x) function
sinc(x) = sin(x)x works in theexample below for y=0sinc(0)=sin(0)0= NaN but plottingprogram will ignore this
t = linspace(-55)
y = sinc(t)
plot(ty)
title([rsquo1D Sinc(x) Functionrsquo]
xlabel(rsquoXrsquo)
ylabel(rsquoSinc(X)rsquo)
minus5 minus4 minus3 minus2 minus1 0 1 2 3 4 5minus04
minus02
0
02
04
06
08
11D Sinc(x) Function
X
Sinc
(X)
Plot of Matlab 1D sinc(x)function
REF httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1731 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to generate 2D sinc(x) Sombrero
Sombrero Test Case Matlab code
Calculate sinc(x) using cartesian coordinates
By Mary Thomas
updated March 2015
Created March 2014)
note ni does have to equal nj
scaling factors affect max amplitude
number of wavelengths
Sinc Function
httpenwikipediaorgwikiSombrero_function
clear all
fprintf(rsquoBegin calc cartesian jinc(x) sombreronrsquo)
simple plot
t = linspace(-55)
cartesian representation
ni=51
s=8
f=025
g= 25
s=2
x = linspace(-s s ni)
y = linspace(-s s ni)
1D Sinc(x)
sinc1D = sinc(x)
2D Sinc(xy)
for i=1ni
for j=1ni
r=sqrt(x(i)^2 + y(j)^2)
F(ij) = sin(r)r
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
fprintf(rsquoCalc of f(xy) completed nrsquo)
figure
plot(xsinc1D)
title([rsquo1D Sinc(x) Functionrsquo])
xlabel(rsquoXrsquo) ylabel(rsquoSinc(X)rsquo)
break
figure
surf(xptsyptsF)
title([rsquoSombrero Peaks -- Cartesian Sinc Function F Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
fprintf(rsquoPlot of f(xy) completed nrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1831 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
2D Sombrero Function Using Matlab sinc(x)
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1931 Mary Thomas
rdquoSombrerordquo Shaped Functions Bessel Functions
Generating sinc(x) using rdquoJincrdquo Bessel Function
Bessel Functions can be used toapproximate sinc(x)
Often this function is called the bsincor jsinc
Bessel Function Jinc(x) = J1(x)x
httpmathworldwolframcom
JincFunctionhtml
Plot of a 1D Jinc(x) function
2D rotationally symmetric Circfunction
httpenwikipediaorgwikiBessel_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1331 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric phenomena in Nature
Diffraction of light through a smallcircular aperture (top image)
Particle diffraction at small scalesparticles behave like light photons andcan be scattered by nuclei (bottom)
Signal Processing A square wave iscomposed of all frequencies and acylinder is a 2D rotation of a squarewave the Fourier transform of acylinder is the Circ function (bottomimage)
Other phenomena that are wave like
water waves when a rock is droppedsounds waves on a snare drummechanical vibrations
Airy disk pattern made by light passing through a small
apertureElectron Diffraction from Titanium foil)
2D rotationally symmetric Circ function
REFs httpenwikipediaorgwikiSombrero_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1431 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric functions used to represent nature
Geometry amp Trigonometry eg Newtons rings (light wave reflectionpattern)
Wave theory eg the Point spread function and Xernike polynomials
Huyen-Fresnel Principle eg Diffraction of light through a small circularaperture
Bessel Functions solutions y(x) of Besselrsquos differential equation
Fourier transform of a cylinder rarr Circ functionUsing Gaussian profile to approximate the Airy DiskElectromagnetic waves in a waveguidemany other applications
sinc(x) = sin(x)x or rdquoSombrerordquo function ndash approximates some Besselfunctions
httpwwwcitycollegiatecomnewtons_ringshtmhttpenwikipediaorgwikiPoint_spread_functionhttpenwikipediaorgwikiZernike_polynomialshttpenwikipediaorgwikiHuygens-Fresnel_principlehttpenwikipediaorgwikiBessel_functionhttpwwwcisriteduclasssimg716handouts06_notes_2DfunctionspdfhttpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1531 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
rdquoSombrerordquo Shaped Function sinc(x) = sin(x)x
Matlab has a special function for sinc(x)
Works for 1D 2D 3D function
sinc(x) = sin(x)x has special internals to handle singularities atx=0
Can be used to create a sombrero like plot
sinc(x) is difficult to code in C because of divide by zero issuesneed to avoid (x y) = (0 0)
httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
httpwwwmathworkscomhelpsignalrefsinchtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1631 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to used generate 1D sinc(x) function
sinc(x) = sin(x)x works in theexample below for y=0sinc(0)=sin(0)0= NaN but plottingprogram will ignore this
t = linspace(-55)
y = sinc(t)
plot(ty)
title([rsquo1D Sinc(x) Functionrsquo]
xlabel(rsquoXrsquo)
ylabel(rsquoSinc(X)rsquo)
minus5 minus4 minus3 minus2 minus1 0 1 2 3 4 5minus04
minus02
0
02
04
06
08
11D Sinc(x) Function
X
Sinc
(X)
Plot of Matlab 1D sinc(x)function
REF httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1731 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to generate 2D sinc(x) Sombrero
Sombrero Test Case Matlab code
Calculate sinc(x) using cartesian coordinates
By Mary Thomas
updated March 2015
Created March 2014)
note ni does have to equal nj
scaling factors affect max amplitude
number of wavelengths
Sinc Function
httpenwikipediaorgwikiSombrero_function
clear all
fprintf(rsquoBegin calc cartesian jinc(x) sombreronrsquo)
simple plot
t = linspace(-55)
cartesian representation
ni=51
s=8
f=025
g= 25
s=2
x = linspace(-s s ni)
y = linspace(-s s ni)
1D Sinc(x)
sinc1D = sinc(x)
2D Sinc(xy)
for i=1ni
for j=1ni
r=sqrt(x(i)^2 + y(j)^2)
F(ij) = sin(r)r
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
fprintf(rsquoCalc of f(xy) completed nrsquo)
figure
plot(xsinc1D)
title([rsquo1D Sinc(x) Functionrsquo])
xlabel(rsquoXrsquo) ylabel(rsquoSinc(X)rsquo)
break
figure
surf(xptsyptsF)
title([rsquoSombrero Peaks -- Cartesian Sinc Function F Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
fprintf(rsquoPlot of f(xy) completed nrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1831 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
2D Sombrero Function Using Matlab sinc(x)
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1931 Mary Thomas
rdquoSombrerordquo Shaped Functions Bessel Functions
Generating sinc(x) using rdquoJincrdquo Bessel Function
Bessel Functions can be used toapproximate sinc(x)
Often this function is called the bsincor jsinc
Bessel Function Jinc(x) = J1(x)x
httpmathworldwolframcom
JincFunctionhtml
Plot of a 1D Jinc(x) function
2D rotationally symmetric Circfunction
httpenwikipediaorgwikiBessel_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1431 Mary Thomas
Matrix-Matrix Multiplication
Radially symmetric functions used to represent nature
Geometry amp Trigonometry eg Newtons rings (light wave reflectionpattern)
Wave theory eg the Point spread function and Xernike polynomials
Huyen-Fresnel Principle eg Diffraction of light through a small circularaperture
Bessel Functions solutions y(x) of Besselrsquos differential equation
Fourier transform of a cylinder rarr Circ functionUsing Gaussian profile to approximate the Airy DiskElectromagnetic waves in a waveguidemany other applications
sinc(x) = sin(x)x or rdquoSombrerordquo function ndash approximates some Besselfunctions
httpwwwcitycollegiatecomnewtons_ringshtmhttpenwikipediaorgwikiPoint_spread_functionhttpenwikipediaorgwikiZernike_polynomialshttpenwikipediaorgwikiHuygens-Fresnel_principlehttpenwikipediaorgwikiBessel_functionhttpwwwcisriteduclasssimg716handouts06_notes_2DfunctionspdfhttpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1531 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
rdquoSombrerordquo Shaped Function sinc(x) = sin(x)x
Matlab has a special function for sinc(x)
Works for 1D 2D 3D function
sinc(x) = sin(x)x has special internals to handle singularities atx=0
Can be used to create a sombrero like plot
sinc(x) is difficult to code in C because of divide by zero issuesneed to avoid (x y) = (0 0)
httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
httpwwwmathworkscomhelpsignalrefsinchtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1631 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to used generate 1D sinc(x) function
sinc(x) = sin(x)x works in theexample below for y=0sinc(0)=sin(0)0= NaN but plottingprogram will ignore this
t = linspace(-55)
y = sinc(t)
plot(ty)
title([rsquo1D Sinc(x) Functionrsquo]
xlabel(rsquoXrsquo)
ylabel(rsquoSinc(X)rsquo)
minus5 minus4 minus3 minus2 minus1 0 1 2 3 4 5minus04
minus02
0
02
04
06
08
11D Sinc(x) Function
X
Sinc
(X)
Plot of Matlab 1D sinc(x)function
REF httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1731 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to generate 2D sinc(x) Sombrero
Sombrero Test Case Matlab code
Calculate sinc(x) using cartesian coordinates
By Mary Thomas
updated March 2015
Created March 2014)
note ni does have to equal nj
scaling factors affect max amplitude
number of wavelengths
Sinc Function
httpenwikipediaorgwikiSombrero_function
clear all
fprintf(rsquoBegin calc cartesian jinc(x) sombreronrsquo)
simple plot
t = linspace(-55)
cartesian representation
ni=51
s=8
f=025
g= 25
s=2
x = linspace(-s s ni)
y = linspace(-s s ni)
1D Sinc(x)
sinc1D = sinc(x)
2D Sinc(xy)
for i=1ni
for j=1ni
r=sqrt(x(i)^2 + y(j)^2)
F(ij) = sin(r)r
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
fprintf(rsquoCalc of f(xy) completed nrsquo)
figure
plot(xsinc1D)
title([rsquo1D Sinc(x) Functionrsquo])
xlabel(rsquoXrsquo) ylabel(rsquoSinc(X)rsquo)
break
figure
surf(xptsyptsF)
title([rsquoSombrero Peaks -- Cartesian Sinc Function F Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
fprintf(rsquoPlot of f(xy) completed nrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1831 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
2D Sombrero Function Using Matlab sinc(x)
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1931 Mary Thomas
rdquoSombrerordquo Shaped Functions Bessel Functions
Generating sinc(x) using rdquoJincrdquo Bessel Function
Bessel Functions can be used toapproximate sinc(x)
Often this function is called the bsincor jsinc
Bessel Function Jinc(x) = J1(x)x
httpmathworldwolframcom
JincFunctionhtml
Plot of a 1D Jinc(x) function
2D rotationally symmetric Circfunction
httpenwikipediaorgwikiBessel_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1531 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
rdquoSombrerordquo Shaped Function sinc(x) = sin(x)x
Matlab has a special function for sinc(x)
Works for 1D 2D 3D function
sinc(x) = sin(x)x has special internals to handle singularities atx=0
Can be used to create a sombrero like plot
sinc(x) is difficult to code in C because of divide by zero issuesneed to avoid (x y) = (0 0)
httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
httpwwwmathworkscomhelpsignalrefsinchtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1631 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to used generate 1D sinc(x) function
sinc(x) = sin(x)x works in theexample below for y=0sinc(0)=sin(0)0= NaN but plottingprogram will ignore this
t = linspace(-55)
y = sinc(t)
plot(ty)
title([rsquo1D Sinc(x) Functionrsquo]
xlabel(rsquoXrsquo)
ylabel(rsquoSinc(X)rsquo)
minus5 minus4 minus3 minus2 minus1 0 1 2 3 4 5minus04
minus02
0
02
04
06
08
11D Sinc(x) Function
X
Sinc
(X)
Plot of Matlab 1D sinc(x)function
REF httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1731 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to generate 2D sinc(x) Sombrero
Sombrero Test Case Matlab code
Calculate sinc(x) using cartesian coordinates
By Mary Thomas
updated March 2015
Created March 2014)
note ni does have to equal nj
scaling factors affect max amplitude
number of wavelengths
Sinc Function
httpenwikipediaorgwikiSombrero_function
clear all
fprintf(rsquoBegin calc cartesian jinc(x) sombreronrsquo)
simple plot
t = linspace(-55)
cartesian representation
ni=51
s=8
f=025
g= 25
s=2
x = linspace(-s s ni)
y = linspace(-s s ni)
1D Sinc(x)
sinc1D = sinc(x)
2D Sinc(xy)
for i=1ni
for j=1ni
r=sqrt(x(i)^2 + y(j)^2)
F(ij) = sin(r)r
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
fprintf(rsquoCalc of f(xy) completed nrsquo)
figure
plot(xsinc1D)
title([rsquo1D Sinc(x) Functionrsquo])
xlabel(rsquoXrsquo) ylabel(rsquoSinc(X)rsquo)
break
figure
surf(xptsyptsF)
title([rsquoSombrero Peaks -- Cartesian Sinc Function F Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
fprintf(rsquoPlot of f(xy) completed nrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1831 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
2D Sombrero Function Using Matlab sinc(x)
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1931 Mary Thomas
rdquoSombrerordquo Shaped Functions Bessel Functions
Generating sinc(x) using rdquoJincrdquo Bessel Function
Bessel Functions can be used toapproximate sinc(x)
Often this function is called the bsincor jsinc
Bessel Function Jinc(x) = J1(x)x
httpmathworldwolframcom
JincFunctionhtml
Plot of a 1D Jinc(x) function
2D rotationally symmetric Circfunction
httpenwikipediaorgwikiBessel_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1631 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to used generate 1D sinc(x) function
sinc(x) = sin(x)x works in theexample below for y=0sinc(0)=sin(0)0= NaN but plottingprogram will ignore this
t = linspace(-55)
y = sinc(t)
plot(ty)
title([rsquo1D Sinc(x) Functionrsquo]
xlabel(rsquoXrsquo)
ylabel(rsquoSinc(X)rsquo)
minus5 minus4 minus3 minus2 minus1 0 1 2 3 4 5minus04
minus02
0
02
04
06
08
11D Sinc(x) Function
X
Sinc
(X)
Plot of Matlab 1D sinc(x)function
REF httpwwwmathworkscommatlabcentralcodyproblems
1305-creation-of-2d-sinc-surface
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1731 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to generate 2D sinc(x) Sombrero
Sombrero Test Case Matlab code
Calculate sinc(x) using cartesian coordinates
By Mary Thomas
updated March 2015
Created March 2014)
note ni does have to equal nj
scaling factors affect max amplitude
number of wavelengths
Sinc Function
httpenwikipediaorgwikiSombrero_function
clear all
fprintf(rsquoBegin calc cartesian jinc(x) sombreronrsquo)
simple plot
t = linspace(-55)
cartesian representation
ni=51
s=8
f=025
g= 25
s=2
x = linspace(-s s ni)
y = linspace(-s s ni)
1D Sinc(x)
sinc1D = sinc(x)
2D Sinc(xy)
for i=1ni
for j=1ni
r=sqrt(x(i)^2 + y(j)^2)
F(ij) = sin(r)r
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
fprintf(rsquoCalc of f(xy) completed nrsquo)
figure
plot(xsinc1D)
title([rsquo1D Sinc(x) Functionrsquo])
xlabel(rsquoXrsquo) ylabel(rsquoSinc(X)rsquo)
break
figure
surf(xptsyptsF)
title([rsquoSombrero Peaks -- Cartesian Sinc Function F Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
fprintf(rsquoPlot of f(xy) completed nrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1831 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
2D Sombrero Function Using Matlab sinc(x)
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1931 Mary Thomas
rdquoSombrerordquo Shaped Functions Bessel Functions
Generating sinc(x) using rdquoJincrdquo Bessel Function
Bessel Functions can be used toapproximate sinc(x)
Often this function is called the bsincor jsinc
Bessel Function Jinc(x) = J1(x)x
httpmathworldwolframcom
JincFunctionhtml
Plot of a 1D Jinc(x) function
2D rotationally symmetric Circfunction
httpenwikipediaorgwikiBessel_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1731 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
Matlab code to generate 2D sinc(x) Sombrero
Sombrero Test Case Matlab code
Calculate sinc(x) using cartesian coordinates
By Mary Thomas
updated March 2015
Created March 2014)
note ni does have to equal nj
scaling factors affect max amplitude
number of wavelengths
Sinc Function
httpenwikipediaorgwikiSombrero_function
clear all
fprintf(rsquoBegin calc cartesian jinc(x) sombreronrsquo)
simple plot
t = linspace(-55)
cartesian representation
ni=51
s=8
f=025
g= 25
s=2
x = linspace(-s s ni)
y = linspace(-s s ni)
1D Sinc(x)
sinc1D = sinc(x)
2D Sinc(xy)
for i=1ni
for j=1ni
r=sqrt(x(i)^2 + y(j)^2)
F(ij) = sin(r)r
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
fprintf(rsquoCalc of f(xy) completed nrsquo)
figure
plot(xsinc1D)
title([rsquo1D Sinc(x) Functionrsquo])
xlabel(rsquoXrsquo) ylabel(rsquoSinc(X)rsquo)
break
figure
surf(xptsyptsF)
title([rsquoSombrero Peaks -- Cartesian Sinc Function F Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
fprintf(rsquoPlot of f(xy) completed nrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1831 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
2D Sombrero Function Using Matlab sinc(x)
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1931 Mary Thomas
rdquoSombrerordquo Shaped Functions Bessel Functions
Generating sinc(x) using rdquoJincrdquo Bessel Function
Bessel Functions can be used toapproximate sinc(x)
Often this function is called the bsincor jsinc
Bessel Function Jinc(x) = J1(x)x
httpmathworldwolframcom
JincFunctionhtml
Plot of a 1D Jinc(x) function
2D rotationally symmetric Circfunction
httpenwikipediaorgwikiBessel_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1831 Mary Thomas
rdquoSombrerordquo Shaped Functions sinc(x) = sin(x)x
2D Sombrero Function Using Matlab sinc(x)
minus3
minus2
minus1
0
1
2
minus3
minus2
minus1
0
1
2
X
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 F=05
Y
Sombrero Plt Using Matlab Sinc(x) Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1931 Mary Thomas
rdquoSombrerordquo Shaped Functions Bessel Functions
Generating sinc(x) using rdquoJincrdquo Bessel Function
Bessel Functions can be used toapproximate sinc(x)
Often this function is called the bsincor jsinc
Bessel Function Jinc(x) = J1(x)x
httpmathworldwolframcom
JincFunctionhtml
Plot of a 1D Jinc(x) function
2D rotationally symmetric Circfunction
httpenwikipediaorgwikiBessel_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 1931 Mary Thomas
rdquoSombrerordquo Shaped Functions Bessel Functions
Generating sinc(x) using rdquoJincrdquo Bessel Function
Bessel Functions can be used toapproximate sinc(x)
Often this function is called the bsincor jsinc
Bessel Function Jinc(x) = J1(x)x
httpmathworldwolframcom
JincFunctionhtml
Plot of a 1D Jinc(x) function
2D rotationally symmetric Circfunction
httpenwikipediaorgwikiBessel_function
httpwwwcisriteduclasssimg716handouts06_notes_2Dfunctionspdf
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2031 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
Fraunhofer diffraction pattern of a circular aperture is given by thesquared modulus of the Fourier transform (Bessel function) of thecircular aperture
I (θ) = I0(
2J1(ka sinθ)ka sinθ
)2
= I0J1
(2J1(x)
x
)2
I0 is the maximum intensity of the pattern at the Airy disc center
J1 Bessel function of the first kind of order one
k wavenumber = 2πλ
a is the radius of the aperture
θ the angle of observation
R is the focal length
The Airy pattern falls slowly to zero withincreasing distance from the center whichallows us to use a Gaussian profileapproximation for the intensity distribution
I (r) asymp I prime0exp(minusr2
λN
)asymp(
P0Aλ2R2
)exp
(minusr2
λN
)asymp(
Aλ2R cos
2 (r))exp
(minusr2
λN
) Airy disk pattern made by light passing through a smallaperture
httpenwikipediaorgwikiAiry_disk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2131 Mary Thomas
rdquoSombrerordquo Shaped Functions Fraunhoffer Diffraction Airy Disk Function
Fraunhoffer Diffraction the Airy Disk Function
The intensity pattern can be written using cartesian coordinates as
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radic
x2 + y2 and f and gare constants that control the shape of the waves
This particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
The function is calculated using Hadamard (element-wise) matrixmultiplication RefhttpenwikipediaorgwikiHadamard_product_(matrices)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2231 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Hadamard (element-wise) Matrix Multiplication
The Hadamard (or Schur) product is a binary operator that operates on 2identically-shaped matrices and produces a third matrix of the samedimensions
Definition If A = [aij ] and B = [bij ] are mx n matrices then theHadamard product of A and B is defined to be
(A B)ij = (A)ij middot (B)ij
is an mx n matrix C = [cij ] suchthat
cij = aij lowast bij
The Matlab times operation (C = A ˙B) is a Hadamard product
Refs httpenwikipediaorgwikiHadamard_product_(matrices)httpwwwmathworkscomhelpmatlabreftimeshtml
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2331 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
File sombrero_using_bessel_formulation_hadamardm
Airy discDiffraction pattern Matlab code
By Mary Thomas
updated March 2015
Created March 2014
note ni does have to equal nj but it is for this problem
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
size=nini
fprintf(rsquobegin calc bessel sombreronrsquo)
Tweak control parameters to adjust amplitude
number of peaks and spacingdepth of peaks
f max amplitude
f=1
f=02
f= 025
f=03
f= 04
f=05
f=075
f=09
f=10]
f=famp(5)
g inverse wavelength
g=1
g=025
g=5 g=06
g=75 g=1
s number of wavelengths in hat ~ s+1
s=2
s=3 s=4 s=5
s=8
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xy completenrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2) fpi convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
end
end
for i=1ni
for j=1ni
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-g(r(ij)^2))
end
end
calculate the Hadamard Product
for i=1ni
for j=1ni
C(ij) = A(ij) B(ij)
end
end
fprintf(rsquocalc C completenrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2431 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Matlab code to generate Sombrero using Hadamard Multiplication onModified Circle Function
create 3D surface node mesh surf(c)
figure
surf(xptsyptsC)
title([rsquoSombrero Peaks -- C=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
create 3D surface node mesh surf(c)
D=AB
figure
surf(xptsyptsD)
title([rsquoSombrero Peaks -- D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)
ylabel(rsquoYrsquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2531 Mary Thomas
Generating Sombrero using Hadamard Multiplication on Modified Circle Function
Sombrero Function Using Hadamard Multipilcation ofModified Circle Function
Sombrero Plot Using Bessel Function Ni=64 S=3 Freq=05
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2631 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
For this assignment you will use matrix-matrix multiplication (notthe Hadamard product see above) to calculate a matrix productusing the matrices defined by the Airy discFraunhaufer Diffractionpattern described above
F (x y) = f lowast cos2 (r) lowast e(minusgr2)
where (x y) are cartesian coordinates r =radicx2 + y2 and f and g
are constants that control the shape of the wavesThis particular form allows us to factor the function into a matrixmultiplication equation of the form
F (x y) = A lowast Bwhere
A = f lowast cos2(radic
x2 + y2)
and B = eminusg(x2+y2)
Notes1 (x y) are the grid cartesian coordinates and f and g are constants
that control the shape of the waves2 The results will differ from those obtained using Hadamard matrix
multiplication
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2731 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Serial_matrix_mult for (i = 0 i lt n i++)
for (j = 0 j lt n j++) C[i][j] = 00for (k = 0 k lt n k++)
C[i][j] = C[i][j] + A[i][k]B[k][j]printf( )
Dimensions [ROWS x COLS]A = mx kB = k x nC = mx n
a11 a1j a1k
ai1 aij aik
am1 amj amk
lowast
b11 b1j b1n
bi1 bij bin
bk1 bkj bkn
=
c11 c1j c1k
ci1 cij cik
cm1 cmj cmk
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2831 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
2D Matrix-Matrix Multiplication (Mat-Mat-Mult)
Definition Let A be an [mx k] matrix and B be a be an [k x n]then C will be a matrix with the dimensions [mx n]
ThenAB = bcijc cij =
sumkt=1 aitbtj = ai1b1j + ai2b2j + middot middot middot+ ak1bkj
=
a00 a0j a0kminus1
ai0 aij aikminus1
amminus10 amminus1j amminus1kminus1
bull
b00 b0j b0nminus1
bi0 bij binminus1
bkminus11 bkj bnminus1pminus1
=
c00 c1j c1nminus1
ci0 cij cinminus1
cmminus10 cmj cmminus1nminus1
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 2931 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
Wave Function Test Case Matlab code
Calculates modified bessel function
using mat-mat multiplication C=AB
By Mary Thomas (March 2014)
updated March 2015
Created March 2014
scaling factors affect max amplitude
number of wavelengths
clear all
ni=64
fprintf(rsquoinit wave function test casenrsquo)
f max amplitude
f=10
f=05
f=25
f=1
g inverse wavelength
g=1
g=025
g=5
g=75
g=1
s number of wavelengths in hat ~ s+1
s=1
s=2
s=3
s=4
s=6
x = linspace(-s s ni)
y = linspace(-s s ni)
fprintf(rsquoinit xynrsquo)
serial matrix-matrix multiplication
C=zeros(nini)
A=zeros(nini)
B=zeros(nini)
for i=1ni
for j=1ni
r(ij)=sqrt(x(i)^2 + y(j)^2)pif convert to radians
xpts(ij) = x(i) these are for plotting
ypts(ij) = y(j)
A(ij) = f(cos(r(ij)))^2
B(ij) = exp(-gr(ij)^2)
end
end
fprintf(rsquocalc AB oknrsquo)
using r(ik) produces waves
for i=1ni
for j=1ni
for k=1ni
C(ij) = C(ij) + A(ik) B(kj)
end
end
end
fprintf(rsquocalc C oknrsquo)
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3031 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
Matlab code Mat-Mult to generate Waves
plot 3D surface node mesh -- waves
figure
surf(xptsyptsC)
title([rsquoBessel Waves -- Calc C(ij) Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
plot 3D surface node mesh -- waves
D=AB
figure
surf(xptsyptsD)
title([rsquoBessel Waves -- Calc D=AB Ni=rsquonum2str(ni)rsquo S=rsquonum2str(s)rsquo F=rsquonum2str(f)rsquo G=rsquonum2str(g)])
xlabel(rsquoXrsquo)ylabel(rsquoYrsquo)zlabel(rsquoAmplitudersquo)
grid on
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction
COMP 605 Homework 8 Due 051415 Posted 050515 Updated 050515 3131 Mary Thomas
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplicationof Airy Disk Function
rdquoWaverdquo Generator Using Matrix-Matrix Multiplication of Airy DiskFunction