SlideShare a Scribd company logo
1 of 16
Download to read offline
22M:	
  170	
  
Programming	
  Assignment	
  
Prof.	
  David	
  Steward	
  
Lingwen	
  He	
  
Friday,	
  December	
  12	
  	
  
	
  
Introduction:	
  the	
  Hydrogen	
  molecule	
  
The	
  quantum	
  mechanics	
  of	
  multielectron	
  atoms	
  and	
  of	
  molecules	
  is	
  rather	
  complicated,	
  but	
  it	
  is	
  
possible	
  to	
  obtain	
  information	
  about	
  chemistry	
  of	
  molecules	
  starting	
  just	
  from	
  the	
  basic	
  
physical	
  theories	
  of	
  quantum	
  mechanics.	
  
	
  
To	
  simplify	
  the	
  problem,	
  I	
  will	
  consider	
  the	
  following	
  three-­‐dimensional	
  integral:	
  
𝛹! 𝑥 𝛹!(𝑥)𝑑𝑥
!!
	
  
Where	
   𝛹!and	
   𝛹!are	
  quantum	
  wavefunctions.	
  For	
  my	
  case	
  study	
  I	
  will	
  consider𝛹! 𝑥   =  𝑐!exp	
  (-­‐
𝑥 − 𝑥! )	
  where	
   𝑥!	
  is	
  the	
  nucleus	
  of	
  one	
  hydrogen	
  atom,	
  and	
   𝛹!(𝑥)=  𝑐!  exp	
  (-­‐ 𝑥 − 𝑥! )	
  where	
  
𝑥!	
  is	
  the	
  nucleus	
  of	
  the	
  other	
  hydrogen	
  atom.	
  I	
  will	
  be	
  able	
  to	
  avoid	
  using	
  complex	
  arithmetic	
  
by	
  supposing	
  that	
   𝑐!	
  and	
   𝑐!	
  are	
  real.	
  
	
  
The	
  wavefunctions	
  need	
  to	
  be	
  normalized;	
  that	
  is,	
  they	
  must	
  have	
  magnitude	
  one	
  in	
  the	
   𝐿!
(𝑅!
)	
  
norm:	
  
[ 𝛹(𝑥) !
𝑑𝑥
!!
]!/!
= 1	
  
Here	
  I	
  introduce	
  spherical	
  polar	
  coordinates	
  to	
  calculate	
   𝑐!and𝑐!:	
  
𝛸 =
𝑥
𝑦
𝑧
=
𝑟 sin 𝜃 cos 𝜑
𝑟 sin 𝜃 sin 𝜑
𝑟 cos 𝜃
	
  
	
  
Note	
  that	
   𝜃is	
  the	
  colatitude	
  (π/2	
  radians	
  minus	
  the	
  latitude),	
  φ	
  is	
  the	
  longitude	
  or	
  azimuth,	
  and	
  r	
  
is	
  the	
  radius	
  from	
  the	
  center	
  of	
  the	
  coordinate	
  system.	
  I	
  restrict	
  the	
  variables	
  so	
  that	
  r≥0,	
  0≤θ≤π	
  
and	
  0≤φ≤2π.	
  Then	
  the	
  volume	
  could	
  be	
  computed	
  using	
  “d  𝛸 = 𝑑𝑥𝑑𝑦𝑑𝑧 = 𝑟!
sin 𝜃 𝑑𝑟𝑑𝜃𝑑𝜑”	
  
	
  
If	
  I	
  take	
   𝑥!	
  as	
  the	
  center	
  of	
  spherical	
  polar	
  coordinates,	
  which	
  means	
  that	
  
𝛸 − 𝑥!=
𝑟 sin 𝜃 cos 𝜑
𝑟 sin 𝜃 sin 𝜑
𝑟 cos 𝜃
	
  
Then	
  with	
  “d  𝛸 = 𝑑𝑥𝑑𝑦𝑑𝑧 = 𝑟!
sin 𝜃 𝑑𝑟𝑑𝜃𝑑𝜑”,	
  I	
  get	
  
	
  
𝛹! 𝑥 !
𝑑𝑥!! = 𝑐!
!
exp −𝑟 !
𝑟!
sin 𝜃 𝑑𝜑𝑑𝜃
!!
!
!
!
!
!
𝑑𝑟	
  
	
   	
   = 𝑐!
!
𝑒!!!!!
!
!
!
!
!
𝑟!
sin 𝜃 𝑑𝜑𝑑𝜃𝑑𝑟	
  
	
   	
   = 𝑐!
!
(2𝜋)
!
!
!
!
𝑒!!!
𝑟!
sin 𝜃 𝑑𝜃𝑑𝑟	
  
	
   	
   = 𝑐!
!
(4𝜋)
!
!
𝑒!!!
𝑟!
  𝑑𝑟	
  
  	
   =	
   𝑐!
!
(4𝜋)(1/4)	
  
	
   	
   =	
  1	
  
	
  
Here	
  I	
  get	
   𝑐!
!
=
!
!
	
  
And	
  similarly,	
   𝑐!
!
= 𝑐!
!
=
!
!
	
  
	
  
Then,	
  to	
  deal	
  with	
  iterated	
  integrals	
  of	
  this	
  sort,	
  I	
  write	
  them	
  as	
  nested	
  one-­‐variable	
  integrals	
  
and	
  apply	
  standard	
  numerical	
  methods	
  for	
  each	
  one-­‐variable	
  integral.	
  	
  
The	
  integral	
  over	
  r	
  is	
  over	
  the	
  interval	
  [0,	
  ∞),	
  and	
  f(r,	
  θ,	
  φ)	
  typically	
  decays	
  exponentially.	
  This	
  
motivates	
  the	
  use	
  of	
  Gauss-­‐Laguerre	
  integration	
  over	
  r.	
  
	
  Gauss-­‐Laguerre	
  integration:	
  
𝑒!!
𝑓(𝑥)𝑑𝑥 ≈ 𝑤! 𝑓(𝑥!)
!
!!!
!
!
	
  
The	
  integral	
  over	
  θ	
  is	
  over	
  [0,	
  π]	
  and	
  there	
  is	
  no	
  particular	
  structure	
  of	
  dependence	
  of	
  f(r,	
  θ,	
  φ)	
  
on	
  θ.	
  This	
  motivates	
  the	
  use	
  of	
  Gauss-­‐Legendre	
  integration	
  over	
  θ.	
  
Gauss-­‐Legendre	
  integration:	
  
𝑓(𝑥)𝑑𝑥 ≈ 𝑤! 𝑓(𝑥!)
!
!!!
!
!!
	
  
Notice	
  that	
  the	
  integral	
  is	
  from	
  -­‐1	
  to	
  1	
  and	
  in	
  my	
  case	
  the	
  integral	
  is	
  from	
  0	
  to	
  pi	
  and	
  therefore	
  I	
  
need	
  transformation.	
  
	
  
The	
  integral	
  over	
  φ	
  is	
  over	
  [0,	
  2π]	
  and	
  f(r,	
  θ,	
  φ)	
  is	
  periodic	
  in	
  φ.	
  This	
  motivates	
  the	
  use	
  of	
  
(periodic)	
  Trapezoidal	
  rule.	
  
(Periodic)	
  Trapezoidal	
  rule:  
𝑓(𝑥)𝑑𝑥 ≈ 𝑤! 𝑓(𝑥!)
!
!!!
!
!
	
  
	
  
Combining	
  these	
  rules	
  gives	
  a	
  formula	
  
𝑔(𝑟, 𝜃, 𝜑)𝑒!!
sin 𝜃 𝑑𝜑𝑑𝜗𝑑𝑟 ≈ 𝑤!
!"
𝑤!
!"
𝑤!
!"
𝑔(𝑟!
!"
, 𝜃!
!"
, 𝜑!
!"
)
!,!,!
!!
!
!
!
!
!
	
  
Where	
   𝑤!
!"
	
  and	
   𝑟!
!"
	
  are	
  weights	
  and	
  nodes	
  for	
  the	
  modified	
  Gauss-­‐Laguerre	
  quadrature	
  
formula,	
   𝑤!
!"
	
  and	
   𝜃!
!"
	
  are	
  the	
  weights	
  and	
  nodes	
  for	
  Gauss-­‐Legendre	
  quadrature	
  on	
  [0,	
  π]	
  and	
  
𝑤!
!"
	
  and	
   𝜑!
!"
	
  are	
  the	
  weights	
  and	
  nodes	
  for	
  the	
  (periodic)	
  trapezoidal	
  rule	
  on	
  [0,	
  2π].	
  
	
  
Task1:	
  use	
  the	
  above	
  formula	
  to	
  numerically	
  compute	
   𝛹(𝑥) !
𝑑𝑥!! 	
  using	
  N	
  =	
  2,	
  4,	
  …,	
  32	
  nodes	
  
in	
  each	
  one-­‐variable	
  rule	
  (at	
  least	
  12	
  or	
  13	
  digits).	
  I	
  calculate	
  the	
  exact	
  value	
  of	
   𝑐!
!
	
  to	
  
satisfy 𝛹(𝑥) !
𝑑𝑥!! = 1,	
  and	
  therefore	
  I	
  can	
  calculate	
  errors	
  from	
  the	
  numerical	
  method.	
  Plot	
  
errors	
  against	
  N	
  using	
  log-­‐log	
  or	
  semi-­‐log.	
  Choose	
  the	
  plot	
  that	
  best	
  show	
  the	
  behavior	
  of	
  the	
  
error	
  as	
  a	
  function	
  of	
  N.	
  
 
First	
  of	
  all,	
  by	
  comparing	
  the	
  formulas,	
  I	
  can	
  get	
   𝑔(𝑟, 𝜃, 𝜑)=𝑒!!
𝑟!
sin 𝜃.	
  
Since	
  I	
  know	
  the	
  value	
  of	
   𝑐!
!
	
  that	
  sets	
  the	
  equation	
  to	
  be	
  1,	
  I	
  know	
  that	
  the	
  true	
  value	
  of	
  the	
  
integral	
  is	
  1/ 𝑐!
!
=	
  π.	
  
N	
   Approximation	
   Error	
  
2	
   2.666299698360362e+00	
   4.752929552294316e-­‐01	
  
4	
   3.067694205166275e+00	
   7.389844842351767e-­‐02	
  
6	
   3.138543286202643e+00	
   3.049367387149893e-­‐03	
  
8	
   3.141508554739558e+00	
   8.409885023485941e-­‐05	
  
10	
   3.141590751423614e+00	
   1.902166179235110e-­‐06	
  
12	
   3.141592615396657e+00	
   3.819313576514105e-­‐08	
  
14	
   3.141592652881650e+00	
   7.081428776700705e-­‐10	
  
16	
   3.141592653577389e+00	
   1.240429980953195e-­‐11	
  
18	
   3.141592653589601e+00	
   1.918465386552271e-­‐13	
  
20	
   3.141592653589866e+00	
   7.283063041541027e-­‐14	
  
22	
   3.141592653589710e+00	
   8.348877145181177e-­‐14	
  
24	
   3.141592653589723e+00	
   6.972200594645983e-­‐14	
  
26	
   3.141592653589877e+00	
   8.393286066166183e-­‐14	
  
28	
   3.141592653589813e+00	
   1.953992523340276e-­‐14	
  
30	
   3.141592653589794e+00	
   1.332267629550188e-­‐15	
  
32	
   3.141592653589771e+00	
   2.176037128265307e-­‐14	
  
	
  
The	
  semi-­‐log	
  plot	
  is	
  shown	
  as	
  below.	
  By	
  using	
  this	
  procedure,	
  I	
  can	
  get	
  a	
  minimum	
  error	
  to	
  be	
  
around  10!!"
.	
  
	
  
But	
  as	
  a	
  matter	
  of	
  fact,	
  the	
  nuclei	
  are	
  not	
  centered	
  at	
  the	
  same	
  point.	
  Suppose	
  that	
  the	
  nuclei	
  
are	
  centered	
  at	
   𝑥!!  !(!/!)!!  and	
   𝑥! = +(𝑎/2)𝑒!	
  where	
  a	
  >0	
  is	
  the	
  inter-­‐nucleus	
  distance	
  (in	
  
suitable	
  units).	
  Start	
  with	
  a	
  =	
  1.i	
  want	
  to	
  accurately	
  compute	
  the	
  integral 𝜓!(𝑥)𝜓!(𝑥)𝑑𝑥!! 	
  
where	
   𝜓!and	
   𝜓!are	
  given	
  by	
  the	
  formulas	
  above.	
  I	
  can	
  use	
  polar	
  coordinates	
  centered	
  on	
  	
   𝑥!	
  or	
  	
  
𝑥!	
  or	
  on	
  the	
  origin	
  (x=0).	
  
Task2:	
  Compute	
  the	
  integral	
   𝛹! 𝑥 𝛹!(𝑥)𝑑𝑥!! 	
  using	
  polar	
  coordinates	
  centered	
  at	
   𝑥!	
  for	
  N	
  =	
  2,	
  
4,	
  …,	
  32	
  as	
  was	
  done	
  for	
  the	
  previous	
  task.	
  Plot	
  the	
  errors	
  against	
  N;	
  from	
  the	
  plot	
  estimate	
  α	
  
where	
  error	
  ≈const*𝑁!!
	
  	
  
	
  
Here	
  I	
  start	
  with 𝛹! 𝑥 𝛹!(𝑥)𝑑𝑥!! .	
   𝛹! 𝑥 = 𝑐! 𝑒! !!!! = 𝑐! 𝑒!!
	
  (Where	
   𝑥 − 𝑥!	
  
=
𝑟 sin 𝜃 cos 𝜑
𝑟 sin 𝜃 sin 𝜑
𝑟 cos 𝜃
).	
   𝛹! 𝑥 = 𝑐! 𝑒! !!!! = 𝑐! 𝑒! !!!!! !"# ! !"# !!!!
(Where	
   𝑥 − 𝑥! = 𝑥 − 𝑥!	
  
+𝑥!-­‐𝑥!=	
  
𝑟 sin 𝜃 cos 𝜑
𝑟 sin 𝜃 sin 𝜑
𝑟 cos 𝜃
	
  +	
  [ −
!
!
𝑒! −
!
!
𝑒!]=
𝑟 sin 𝜃 cos 𝜑 − 𝑎
𝑟 sin 𝜃 sin 𝜑
𝑟 cos 𝜃
)	
  
	
  
Hence,	
   𝛹! 𝑥 𝛹! 𝑥 𝑑𝑥!! 	
  
= 𝑐!
!
𝑒!!
𝑒! !!!!! !"# ! !"# !!!!
𝑑𝑥!! 	
  
= 𝑐!
!
𝑒!!
𝑒! !!!!! !"# ! !"# !!!!
𝑟!
sin 𝜃 𝑑𝜑𝑑𝜃
!!
!
!
!
!
!
𝑑𝑟	
  
	
  
Use	
  similar	
  procedures	
  as	
  I	
  do	
  in	
  Task	
  1,	
  	
  
𝑔(𝑟, 𝜃, 𝜑)𝑒!!
sin 𝜃 𝑑𝜑𝑑𝜗𝑑𝑟 ≈ 𝑤!
!"
𝑤!
!"
𝑤!
!"
𝑔(𝑟!
!"
, 𝜃!
!"
, 𝜑!
!"
)
!,!,!
!!
!
!
!
!
!
	
  
I	
  set	
  my	
   𝑔(𝑟, 𝜃, 𝜑)= 𝑐!
!
𝑒! !!!!! !"# ! !"# !!!!
𝑟!
sin 𝜃	
  
Notice	
  that	
  I	
  start	
  with	
  a	
  =	
  1.	
  And	
  as	
  to	
  approach	
  error,	
  I	
  can’t	
  possibly	
  get	
  the	
  true	
  value	
  of	
  the	
  
integral	
  since	
  I	
  have	
  no	
  previous	
  information	
  about	
  it.	
  In	
  this	
  case,	
  I	
  use	
  a	
  quite	
  large	
  n	
  to	
  
estimate	
  the	
  integral	
  and	
  use	
  this	
  value	
  as	
  “true”	
  value	
  b.	
  Hence	
  the	
  error	
  is	
  approximately	
  
absolute	
  value	
  of	
  (b-­‐approximation).	
  
	
  
N	
   Approximation	
   Error	
  
2	
   6.275397375557281e-­‐01	
   2.308269611957977e-­‐01	
  
4	
   8.685938120755217e-­‐01	
   1.022711332399584e-­‐02	
  
6	
   8.766068263788301e-­‐01	
   1.824012762730431e-­‐02	
  
8	
   8.596630442183523e-­‐01	
   1.296345466826443e-­‐03	
  
10	
   8.543290409209439e-­‐01	
   4.037657830581964e-­‐03	
  
12	
   8.561946702267949e-­‐01	
   2.172028524730973e-­‐03	
  
14	
   8.586705405645276e-­‐01	
   3.038418130018039e-­‐04	
  
16	
   8.598648511824449e-­‐01	
   1.498152430919109e-­‐03	
  
18	
   8.596488591619377e-­‐01	
   1.282160410411848e-­‐03	
  
20	
   8.586152984830179e-­‐01	
   2.485997314920496e-­‐04	
  
22	
   8.578802245327801e-­‐01	
   4.864742187457027e-­‐04	
  
24	
   8.577243480976197e-­‐01	
   6.423506539061652e-­‐04	
  
26	
   8.579340865310428e-­‐01	
   4.326122204830751e-­‐04	
  
28	
   8.582733013873762e-­‐01	
   9.339736414959443e-­‐05	
  
30	
   8.585758492146289e-­‐01	
   2.091504631031027e-­‐04	
  
32	
   8.587457745141339e-­‐01	
   3.790757626080943e-­‐04	
  
	
  
b	
  =	
  
	
  	
  	
  	
  	
  8.583666987515258e-­‐01	
  
The	
  log-­‐log	
  plot	
  is	
  shown	
  as	
  below.	
  By	
  using	
  procedures	
  through	
  task	
  2,	
  I	
  can	
  get	
  a	
  minimum	
  
error	
  around  10!!
.	
  
	
  
log 𝑒𝑟𝑟𝑜𝑟 ≈ alog 𝑁 + 𝑏	
  
𝑒𝑟𝑟𝑜𝑟 ≈   𝑁!
𝑒!
= 𝑐𝑜𝑛𝑠𝑡 ∗ 𝑁!!
	
  
	
  
From	
  the	
  basic	
  fitting	
  tool	
  I	
  have	
  the	
  following	
  information:	
  
 
Hence,	
  α	
  =	
  -­‐a	
  =	
  -­‐p1	
  =	
  2.3201	
  
Compared	
  with	
  task	
  1,	
  which	
  has	
  a	
  minimum	
  error	
  around  10!!"
,	
  this	
  error	
  is	
  somehow	
  too	
  
large.	
  The	
  reason	
  for	
  large	
  error	
  is	
  that	
  when	
  I	
  use	
   𝑥!	
  as	
  the	
  center,	
  the	
  function	
  at	
  point	
   𝑥!	
  is	
  
not	
  smooth.	
  Another	
  reason	
  is	
  that	
  I	
  don’t	
  have	
  the	
  true	
  value	
  for	
  the	
  integral	
  but	
  only	
  can	
  
estimate	
  it	
  by	
  choosing	
  a	
  fairly	
  large	
  number	
  n.	
  To	
  deal	
  with	
  this	
  problem,	
  I	
  use	
  techniques	
  
shown	
  in	
  task	
  3.	
  
	
  
As	
  the	
  problem	
  arises	
  in	
  task	
  2,	
  I	
  need	
  to	
  find	
  a	
  way	
  to	
  deal	
  with	
  the	
  non-­‐smoothness	
  of	
   𝛹!(𝑥)	
  
at  𝑥 = 𝑥!.	
  To	
  do	
  this,	
  I	
  consider	
  splitting	
  the	
  integral	
  into	
  two	
  parts:	
   𝛹! 𝑥 = 𝛹!
!
𝑥 +
𝛹!
!
(𝑥)	
  where	
   𝛹!
!
𝑥 is	
  smooth	
  (or	
  at	
  least	
  smoother)	
  at  𝑥 = 𝑥!,	
  and	
   𝛹!
!
𝑥   still	
  has	
  the	
  
cusp	
  at	
   𝑥 = 𝑥!,	
  but	
  is	
  smooth	
  elsewhere	
  and	
  zero	
  outside	
  a	
  ball	
  centered	
  on	
   𝑥!  with	
  radius	
  
substantially	
  less	
  than	
  a	
  (say,	
  radius	
  is	
  a/2).	
  In	
  this	
  way,	
  
𝛹! 𝑥 𝛹! 𝑥 𝑑𝑥!! 	
  =	
   𝛹! 𝑥 𝛹!
!
𝑥 𝑑𝑥!!   +   𝛹! 𝑥 𝛹!
!
𝑥 𝑑𝑥!! 	
  
	
  
𝛹! 𝑥 𝛹!
!
𝑥 𝑑𝑥!! 	
  Can	
  be	
  computed	
  using	
  polar	
  coordinates	
  centered	
  on	
   𝑥!	
  and	
  
𝛹! 𝑥 𝛹!
!
𝑥 𝑑𝑥!! 	
  can	
  be	
  computed	
  using	
  polar	
  coordinates	
  centered	
  on  𝑥!.	
  Let	
   𝑟∗
  be	
  the	
  
“cutoff	
  radius”	
  of	
   𝛹!
!
,  and	
  take	
  	
  
𝛹!
!
𝑥 = exp  (−  𝑟∗
𝑝( 𝑥 − 𝑥! /  𝑟∗
))	
  
With	
  p(s)	
  given	
  by	
  
𝑝! 𝑠 =
!
!
1 + 𝑠!
  𝑓𝑜𝑟   𝑠 ≤ 1𝑎𝑛𝑑   𝑠 𝑓𝑜𝑟   𝑠 ≥ 1, 𝑜𝑟	
  	
  
𝑝! 𝑠 =
!
!
3 + 6𝑠!
− 𝑠!
  𝑓𝑜𝑟   𝑠 ≤ 1𝑎𝑛𝑑   𝑠 𝑓𝑜𝑟   𝑠 ≥ 1, 𝑜𝑟	
  	
  
𝑝! 𝑠 =
!
!"
5 + 15𝑠!
− 5𝑠!
+ 𝑠!
  𝑓𝑜𝑟   𝑠 ≤ 1𝑎𝑛𝑑   𝑠 𝑓𝑜𝑟   𝑠 ≥ 1, 𝑜𝑟	
  	
  
𝑝! 𝑠 =
!
!"#
35 + 140𝑠!
− 70𝑠!
+ 28𝑠!
− 5𝑠!
  𝑓𝑜𝑟   𝑠 ≤ 1𝑎𝑛𝑑   𝑠 𝑓𝑜𝑟   𝑠 ≥ 1.	
  	
  
The	
  function	
   𝑝! 𝑠 	
  matches	
  |s|	
  and	
  its	
  derivatives	
  up	
  to	
  the	
  kth	
  derivative	
  at	
  s	
  =1.	
  Whatever	
  
p(s)	
  is,	
  I	
  let  𝛹!
!
𝑥 = 𝛹! 𝑥 − 𝛹!
!
𝑥 .	
  
Task	
  3:	
  implement	
  this	
  splitting	
  of	
  the	
  integral	
  and	
  evaluating	
  the	
  integral	
  using	
  polar	
  
coordinates	
  centered	
  first	
  at	
   𝑥!  and	
  then	
  at	
   𝑥!.	
  Repeat	
  using	
   𝑝 𝑠 = 𝑝! 𝑠   for	
  a	
  few	
  values	
  of	
  k.	
  
Again,	
  use	
  the	
  same	
  values	
  of	
  N	
  as	
  for	
  Task	
  2,	
  and	
  plot	
  the	
  errors.	
  Compare	
  the	
  two	
  methods	
  
and	
  comment	
  on	
  the	
  accuracy	
  of	
  this	
  splitting	
  approach.	
  
Here	
  I	
  approach	
  the	
  integral	
  by	
  splitting	
  it	
  into	
  two	
  parts.	
  For	
  the	
  first	
  part,   𝛹! 𝑥 𝛹!
!
𝑥 𝑑𝑥!! 	
  
I	
  choose	
  to	
  compute	
  this	
  by	
  using	
  polar	
  coordinates	
  centered	
  on  𝑥!	
  because	
  when	
  centered	
  
on  𝑥!  this	
  integral	
  part	
  doesn’t	
  have	
  to	
  deal	
  with	
  non-­‐smoothness	
  on  𝑥!.	
  Similarly,	
  I	
  approach	
  
𝛹! 𝑥 𝛹!
!
𝑥 𝑑𝑥!!   centered	
  on  𝑥!.	
  
𝛹! 𝑥 𝛹!
!
𝑥 𝑑𝑥!! 	
  	
  	
  =	
   𝑐! exp  (− 𝑥 − 𝑥! )exp  (−  𝑟∗
𝑝( 𝑥 − 𝑥! /  𝑟∗
))!! 𝑑𝑥	
  
	
   	
   	
   =	
   𝑐! exp −𝑟 exp −  𝑟∗
𝑝
!!!!!" !"# ! !"# !!!!
!∗
𝑑𝑥!! 	
  
= 𝑐! 𝑒!!
𝑒
!  !∗!
!!!!!" !"# ! !"# !!!!
!∗
𝑟!
sin 𝜃 𝑑𝜑𝑑𝜃
!!
!
!
!
!
!
𝑑𝑟	
  
Use	
  similar	
  procedures	
  as	
  I	
  do	
  in	
  previous	
  tasks,	
  	
  
𝑔(𝑟, 𝜃, 𝜑)𝑒!!
sin 𝜃 𝑑𝜑𝑑𝜗𝑑𝑟 ≈ 𝑤!
!"
𝑤!
!"
𝑤!
!"
𝑔(𝑟!
!"
, 𝜃!
!"
, 𝜑!
!"
)
!,!,!
!!
!
!
!
!
!
	
  
I	
  set	
   𝑔! 𝑟, 𝜃, 𝜑 = 𝑐! 𝑒
!  !∗!
!!!!!" !"# ! !"# !!!!
!∗
𝑟!
	
  
For	
  the	
  second	
  integral	
  part:	
  
𝛹! 𝑥 𝛹!
!
𝑥 𝑑𝑥!! 	
  	
  	
  =	
   𝑐! exp  (− 𝑥 − 𝑥! )(exp − 𝑥 − 𝑥! − exp −  𝑟∗
𝑝
!!!!
!∗
)!! 𝑑𝑥	
  
	
   	
   	
   =	
   𝑐! 𝑒! !!!!!" !"# ! !"# !!!!
(𝑒!!
− 𝑒!  !∗!
!
!∗
!! )𝑑𝑥	
  
	
   	
   	
   =	
   𝑐! 𝑒! !!!!!" !"# ! !"# !!!!
(𝑒!!
)(1 − 𝑒!  !∗!
!
!∗ !!
!! )𝑑𝑥	
  
I	
  set	
   𝑔! 𝑟, 𝜃, 𝜑 = 𝑐! 𝑒! !!!!!" !"# ! !"# !!!!
(1 − 𝑒!  !∗!
!
!∗ !!
)𝑟!
	
  
Notice	
  that	
  since	
  I	
  still	
  don’t	
  have	
  a	
  true	
  value	
  for	
  the	
  whole	
  integral,	
  I	
  will	
  set	
  a	
  large	
  N=100	
  
and	
  use	
   𝑝!  to	
  be	
  the	
  substitute	
  true	
  value	
  of	
  the	
  integral.	
  Start	
  with	
  a	
  =	
  1.	
  
N	
   𝑝!	
   𝑝!	
   𝑝!	
   𝑝!	
  
2	
   6.275397375
557281e-­‐01	
  
6.275397375
557281e-­‐01	
  
6.275397375
557281e-­‐01	
  
6.275397375
557281e-­‐01	
  
4	
   8.714064363
563853e-­‐01	
  
8.695131656
705224e-­‐01	
  
8.689528215
010126e-­‐01	
  
8.687474782
715300e-­‐01	
  
6	
   8.786039083
504553e-­‐01	
  
8.777578511
187618e-­‐01	
  
8.772790065
266729e-­‐01	
  
8.770205550
555248e-­‐01	
  
8	
   8.582456023
965205e-­‐01	
  
8.594157947
776662e-­‐01	
  
8.597281088
424541e-­‐01	
  
8.598124641
876246e-­‐01	
  
10	
   8.546542404
576916e-­‐01	
  
8.547500837
948759e-­‐01	
  
8.546928931
430776e-­‐01	
  
8.546246304
921056e-­‐01	
  
12	
   8.568284926
509197e-­‐01	
  
8.566378751
172376e-­‐01	
  
8.565206960
438592e-­‐01	
  
8.564456266
684295e-­‐01	
  
14	
   8.585848586
528182e-­‐01	
  
8.588443780
747900e-­‐01	
  
8.588647350
691916e-­‐01	
  
8.588446135
333351e-­‐01	
  
16	
   8.586998622
324101e-­‐01	
  
8.592990627
975690e-­‐01	
  
8.595740788
534714e-­‐01	
  
8.597135679
661798e-­‐01	
  
18	
   8.582761953
050426e-­‐01	
  
8.587474246
676631e-­‐01	
  
8.590316188
214573e-­‐01	
  
8.592037171
988656e-­‐01	
  
20	
   8.580378222
387637e-­‐01	
  
8.581338006
410553e-­‐01	
  
8.582671303
241453e-­‐01	
  
8.583647262
947616e-­‐01	
  
22	
   8.581736560
077830e-­‐01	
  
8.579082022
441408e-­‐01	
  
8.578644682
949865e-­‐01	
  
8.578652136
394707e-­‐01	
  
24	
   8.585531645
857941e-­‐01	
  
8.580621676
261577e-­‐01	
  
8.578930720
771248e-­‐01	
  
8.578234749
559234e-­‐01	
  
26	
   8.588273369
374346e-­‐01	
  
8.583704725
317424e-­‐01	
  
8.581722771
241345e-­‐01	
  
8.580768453
772285e-­‐01	
  
28	
   8.588106011
214202e-­‐01	
  
8.585870703
748407e-­‐01	
  
8.584600822
899386e-­‐01	
  
8.583909018
200789e-­‐01	
  
30	
   8.586446546
515094e-­‐01	
  
8.586374722
505155e-­‐01	
  
8.586087722
162836e-­‐01	
  
8.585910134
739473e-­‐01	
  
32	
   8.584236385
569799e-­‐01	
  
8.585691973
184119e-­‐01	
  
8.586093620
024660e-­‐01	
  
8.586307147
994179e-­‐01	
  
	
  
true_p_4	
  =	
  
	
  	
  	
  	
  	
  8.586307147994179e-­‐01	
  
N	
   𝐸𝑟𝑟𝑜𝑟(𝑝!)	
   𝐸𝑟𝑟𝑜𝑟(𝑝!)	
   𝐸𝑟𝑟𝑜𝑟(𝑝!)	
   𝐸𝑟𝑟𝑜𝑟(𝑝!)	
  
2	
   2.310909772
436898e-­‐01	
  
2.310909772
436898e-­‐01	
  
2.310909772
436898e-­‐01	
  
2.310909772
436898e-­‐01	
  
4	
   1.277572155
696738e-­‐02	
  
1.088245087
110451e-­‐02	
  
1.032210670
159472e-­‐02	
  
1.011676347
211210e-­‐02	
  
6	
   1.997319355
103744e-­‐02	
  
1.912713631
934393e-­‐02	
  
1.864829172
725502e-­‐02	
  
1.838984025
610690e-­‐02	
  
8	
   3.851124028
974029e-­‐04	
  
7.850799782
482820e-­‐04	
  
1.097394043
036215e-­‐03	
  
1.181749388
206699e-­‐03	
  
10	
   3.976474341
726322e-­‐03	
  
3.880631004
541946e-­‐03	
  
3.937821656
340268e-­‐03	
  
4.006084307
312308e-­‐03	
  
12	
   1.802222148
498234e-­‐03	
  
1.992839682
180336e-­‐03	
  
2.110018755
558718e-­‐03	
  
2.185088130
988389e-­‐03	
  
14	
   4.585614659
968762e-­‐05	
  
2.136632753
720891e-­‐04	
  
2.340202697
737048e-­‐04	
  
2.138987339
171949e-­‐04	
  
16	
   6.914743299
224480e-­‐05	
  
6.683479981
510754e-­‐04	
  
9.433640540
534860e-­‐04	
  
1.082853166
761932e-­‐03	
  	
  	
  	
  	
  	
  
18	
   3.545194943
752605e-­‐04	
  
1.167098682
451906e-­‐04	
  
4.009040220
394056e-­‐04	
  
5.730023994
476863e-­‐04	
  
20	
   5.928925606
542013e-­‐04	
  
4.969141583
626158e-­‐04	
  
3.635844752
726269e-­‐04	
  
2.659885046
563115e-­‐04	
  
22	
   4.570587916
349345e-­‐04	
  
7.225125552
771106e-­‐04	
  
7.662465044
313560e-­‐04	
  
7.655011599
472239e-­‐04	
  
24	
   7.755021362
376713e-­‐05	
  
5.685471732
601588e-­‐04	
  
7.376427222
930415e-­‐04	
  	
  	
  	
  	
  	
  
8.072398434
945116e-­‐04	
  	
  	
  	
  	
  	
  
26	
   1.966221380
167443e-­‐04	
  
2.602422676
755145e-­‐04	
  
4.584376752
834185e-­‐04	
  
5.538694221
893792e-­‐04	
  
28	
   1.798863220
022762e-­‐04	
  
4.364442457
716056e-­‐05	
  
1.706325094
792405e-­‐04	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
2.398129793
389492e-­‐04	
  
30	
   1.393985209
152682e-­‐05	
  
6.757451097
572087e-­‐06	
  
2.194258313
426012e-­‐05	
  
3.970132547
059802e-­‐05	
  
32	
   2.070762424
379868e-­‐04	
  
6.151748100
602372e-­‐05	
  
2.135279695
192338e-­‐05	
  
0	
  
	
  
A	
  log-­‐log	
  plot	
  is	
  shown	
  as	
  below.	
  	
  
	
  
	
  
	
  
By	
  using	
  basic	
  fitting,	
  I	
  have	
  my	
  best	
  linear	
  fit	
  for	
  these	
  4	
  lines:	
  
Error	
  in	
     𝑝!	
   Error	
  in	
     𝑝!	
   Error	
  in	
     𝑝!	
   Error	
  in	
     𝑝!	
  
	
   	
   	
   	
  
	
  
Note	
  that	
  the	
  fitting	
  of	
  line	
  is	
  similar	
  as	
  in	
  Task	
  2:	
  
log 𝑒𝑟𝑟𝑜𝑟 ≈ alog 𝑁 + 𝑏	
  
Where	
  p1	
  stands	
  for	
  a	
  and	
  p2	
  stands	
  for	
  b	
  here.	
  Compared	
  with	
  Task	
  2,	
  here	
  α	
  is	
  larger,	
  which	
  is	
  
what	
  I	
  want.	
  However,	
  error	
  actually	
  doesn’t	
  improve	
  much	
  as	
  I	
  previously	
  imagine.	
  This	
  is	
  
because	
  in	
  my	
  calculation,	
  I	
  don’t	
  have	
  the	
  true	
  value	
  of	
  the	
  integral	
  but	
  use	
  a	
  large	
  N	
  to	
  
estimate	
  a	
  value.	
  Notice	
  the	
  error	
  in  𝑝!  when	
  n	
  =	
  32	
  drops	
  down	
  to	
  0.	
  Hence	
  the	
  error	
  is	
  far	
  
large	
  than	
  it	
  should	
  be.	
  
𝑒𝑟𝑟𝑜𝑟 ≈   𝑁!
𝑒!
= 𝑐𝑜𝑛𝑠𝑡 ∗ 𝑁!!
	
  
	
  
To	
  better	
  deal	
  with	
  the	
  accuracy,	
  I	
  have	
  some	
  options	
  to	
  continue	
  with:	
  
1) Have	
  more	
  information	
  about	
  the	
  true	
  value	
  (or	
  at	
  least	
  approximate	
  enough)	
  	
  
2) Better	
  approach	
  the	
  integral	
  with	
  smoother	
  functions	
  
	
  	
  
	
  
	
  
Appendix	
  
Codes	
  for	
  Gauss-­‐Laguerre	
  
function	
  [x,w]	
  =	
  gaussla(n)	
  
%	
  function	
  [x,w]	
  =	
  gaussla(n)	
  
%	
  
%	
  Generates	
  points	
  and	
  weights	
  for	
  Gauss-­‐Laguerre	
  quadrature	
  
%	
  Uses	
  the	
  tridiagonal	
  eigenvalue/eigenvector	
  approach	
  
%	
  of	
  Golub	
  and	
  Welsch	
  (Stanford	
  CS	
  TR-­‐81	
  (1967)	
  
	
  	
  a(1:n+1)	
  =	
  -­‐1./(1:n+1);	
  
	
  	
  b(1:n+1)	
  =	
  (2*(1:n+1)-­‐1)./(1:n+1);	
  
	
  	
  c(1:n+1)	
  =	
  (0:n)./(1:n+1);	
  
	
  	
  alpha	
  =	
  -­‐b	
  ./	
  a;	
  
	
  	
  beta	
  	
  =	
  sqrt(c(2:n+1)./(a(1:n).*a(2:n+1)));	
  
	
  	
  J	
  =	
  diag(alpha)	
  +	
  diag(beta,1)	
  +	
  diag(beta,-­‐1);	
  
	
  	
  [V,D]	
  =	
  eig(J);	
  
	
  	
  x	
  =	
  diag(D)';	
  
	
  	
  w	
  =	
  V(1,:).^2;	
  
	
  	
  w	
  =	
  w	
  /	
  sum(w);	
  
	
  	
  	
  
Code	
  for	
  Gauss-­‐Legendre	
  
function	
  [x,w]	
  =	
  gaussle(n)	
  
%	
  function	
  [x,w]	
  =	
  gaussle(n)	
  
%	
  
%	
  Generates	
  points	
  and	
  weights	
  for	
  Gauss-­‐Legendre	
  quadrature	
  
%	
  Uses	
  the	
  tridiagonal	
  eigenvalue/eigenvector	
  approach	
  
%	
  of	
  Golub	
  and	
  Welsch	
  (Stanford	
  CS	
  TR-­‐81	
  (1967)	
  
	
  	
  a(1:n+1)	
  =	
  (2*(1:n+1)-­‐1)./(1:n+1);	
  
	
  	
  b(1:n+1)	
  =	
  0;	
  
	
  	
  c(1:n+1)	
  =	
  (0:n)./(1:n+1);	
  
	
  	
  alpha	
  =	
  -­‐b	
  ./	
  a;	
  
	
  	
  beta	
  	
  =	
  sqrt(c(2:n+1)./(a(1:n).*a(2:n+1)));	
  
	
  	
  J	
  =	
  diag(alpha)	
  +	
  diag(beta,1)	
  +	
  diag(beta,-­‐1);	
  
	
  	
  [V,D]	
  =	
  eig(J);	
  
	
  	
  x	
  =	
  diag(D)';	
  
	
  	
  x	
  =	
  (x+1)*pi/2;	
  
	
  	
  w	
  =	
  V(1,:).^2;	
  
	
  	
  w	
  =	
  pi*w	
  /	
  sum(w);	
  
	
  	
  	
  
Code	
  for	
  (periodic)	
  Trapezoidal	
  Rule:	
  
function	
  [x,	
  w]	
  =	
  periodictrape(n)	
  
x	
  =	
  zeros([1,n]);	
  
w	
  =	
  zeros([1,n]);	
  
for	
  i	
  =	
  1:n	
  
	
  	
  	
  	
  x(i)	
  =	
  2*pi*i/n;	
  
	
  	
  	
  	
  w(i)	
  =	
  2*pi/n;	
  
end	
  
	
  
Code	
  for	
  Task	
  1:	
  
estimation	
  =	
  zeros([16,1]);	
  
errors	
  =	
  zeros([16,1]);	
  
for	
  n	
  =	
  2:2:32	
  
	
  	
  	
  	
  [r,	
  wla]	
  =	
  gaussla(n-­‐1);	
  
	
  	
  	
  	
  [theta,	
  wle]	
  =	
  gaussle(n-­‐1);	
  
	
  	
  	
  	
  [fi,	
  wtr]	
  =	
  periodictrape(n);	
  
	
  	
  	
  	
  g=@(i,j,k)(exp(-­‐r(i))*(r(i)^2)*sin(theta(j)));	
  
	
  	
  	
  	
  a	
  =	
  0;	
  
	
  	
  	
  	
  for	
  i	
  =	
  1:n	
  
	
  	
  	
  	
  	
  	
  	
  	
  for	
  j	
  =	
  1:n	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  for	
  k	
  =	
  1:n	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  a	
  =	
  a	
  +	
  wla(i)*wle(j)*wtr(k)*g(i,j,k);	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  estimation(n/2)=a;	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  errors(n/2)=a	
  -­‐	
  pi;	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  end	
  
	
  	
  	
  	
  	
  	
  	
  	
  end	
  
	
  	
  	
  	
  end	
  
end	
  
	
  
Code	
  for	
  Task	
  2	
  -­‐	
  estimation:	
  
estimation_task2	
  =	
  zeros([16,1]);	
  
for	
  n	
  =	
  2:2:32	
  
	
  	
  	
  	
  [r,	
  wla]	
  =	
  gaussla(n-­‐1);	
  
	
  	
  	
  	
  [theta,	
  wle]	
  =	
  gaussle(n-­‐1);	
  
	
  	
  	
  	
  [fi,	
  wtr]	
  =	
  periodictrape(n);	
  
	
  	
  	
  	
  g=@(i,j,k)(exp(-­‐sqrt(r(i)^2-­‐2*r(i)*sin(theta(j))*cos(fi(k))+1))*(r(i)^2)*sin(theta(j))*(1/pi));	
  
	
  	
  	
  	
  a2	
  =	
  0;	
  
	
  	
  	
  	
  for	
  i	
  =	
  1:n	
  
	
  	
  	
  	
  	
  	
  	
  	
  for	
  j	
  =	
  1:n	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  for	
  k	
  =	
  1:n	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  a2	
  =	
  a2	
  +	
  wla(i)*wle(j)*wtr(k)*g(i,j,k);	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  estimation_task2(n/2)=a2;	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  end	
  
	
  	
  	
  	
  	
  	
  	
  	
  end	
  
	
  	
  	
  	
  end	
  
end	
  
	
  
Code	
  for	
  Task	
  2	
  –	
  set	
  a	
  true	
  value:	
  
for	
  n	
  =	
  100	
  
	
  	
  	
  	
  [r,	
  wla]	
  =	
  gaussla(n-­‐1);	
  
	
  	
  	
  	
  [theta,	
  wle]	
  =	
  gaussle(n-­‐1);	
  
	
  	
  	
  	
  [fi,	
  wtr]	
  =	
  periodictrape(n);	
  
	
  	
  	
  	
  g=@(i,j,k)(exp(-­‐sqrt(r(i)^2-­‐2*r(i)*sin(theta(j))*cos(fi(k))+1))*(r(i)^2)*sin(theta(j))*(1/pi));	
  
	
  	
  	
  	
  b	
  =	
  0;	
  
	
  	
  	
  	
  for	
  i	
  =	
  1:n	
  
	
  	
  	
  	
  	
  	
  	
  	
  for	
  j	
  =	
  1:n	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  for	
  k	
  =	
  1:n	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  b	
  =	
  b	
  +	
  wla(i)*wle(j)*wtr(k)*g(i,j,k);	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  end	
  
	
  	
  	
  	
  	
  	
  	
  	
  end	
  
	
  	
  	
  	
  end	
  
end	
  
	
  	
  
	
  
Code	
  for	
  Task	
  2	
  –	
  errors	
  and	
  plot:	
  
errors_task2	
  =	
  zeros([16,1]);	
  
for	
  n	
  =	
  2:2:32	
  
	
  	
  	
  	
  errors_task2(n/2)	
  =	
  abs(estimation_task2(n/2)-­‐b);	
  
end	
  
	
  	
  
loglog(2:2:32,errors_task2)	
  
	
  
Code	
  for	
  Task	
  3	
  –	
  estimation:	
  
est_g_1_1 = zeros([16,1]);
est_g_1_2 = zeros([16,1]);
est_g_1_3 = zeros([16,1]);
est_g_1_4 = zeros([16,1]);
est_g_2_1 = zeros([16,1]);
est_g_2_2 = zeros([16,1]);
est_g_2_3 = zeros([16,1]);
est_g_2_4 = zeros([16,1]);
for n = 2:2:32
[r, wla] = gaussla(n-1);
[theta, wle] = gaussle(n-1);
[fi, wtr] = periodictrape(n);
g_1_1 = @(i,j,k)((1/pi)*exp(-0.5*
p_1(sqrt((r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))/0.5))*r(i)^2*sin(theta(j
)));
g_1_2 = @(i,j,k)((1/pi)*exp(-0.5*
p_2(sqrt((r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))/0.5))*r(i)^2*sin(theta(j
)));
g_1_3 = @(i,j,k)(((1/pi))*exp(-0.5*
p_3(sqrt((r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))/0.5))*r(i)^2*sin(theta(j
)));
g_1_4 = @(i,j,k)(((1/pi))*exp(-0.5*
p_4(sqrt((r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))/0.5))*r(i)^2*sin(theta(j
)));
g_2_1 = @(i,j,k)(((1/pi))*exp(-
sqrt(r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))*(1-exp(-
0.5*p_1(r(i)/0.5)+r(i)))*r(i)^2*sin(theta(j)));
g_2_2 = @(i,j,k)(((1/pi))*exp(-
sqrt(r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))*(1-exp(-
0.5*p_2(r(i)/0.5)+r(i)))*r(i)^2*sin(theta(j)));
g_2_3 = @(i,j,k)(((1/pi))*exp(-
sqrt(r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))*(1-exp(-
0.5*p_3(r(i)/0.5)+r(i)))*r(i)^2*sin(theta(j)));
g_2_4 = @(i,j,k)(((1/pi))*exp(-
sqrt(r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))*(1-exp(-
0.5*p_4(r(i)/0.5)+r(i)))*r(i)^2*sin(theta(j)));
a3_1_1 = 0;
a3_1_2 = 0;
a3_1_3 = 0;
a3_1_4 = 0;
a3_2_1 = 0;
a3_2_2 = 0;
a3_2_3 = 0;
a3_2_4 = 0;
for i = 1:n
for j = 1:n
for k = 1:n
a3_1_1 = a3_1_1 + wla(i)*wle(j)*wtr(k)*g_1_1(i,j,k);
est_g_1_1(n/2) = a3_1_1;
a3_1_2 = a3_1_2 + wla(i)*wle(j)*wtr(k)*g_1_2(i,j,k);
est_g_1_2(n/2) = a3_1_2;
a3_1_3 = a3_1_3 + wla(i)*wle(j)*wtr(k)*g_1_3(i,j,k);
est_g_1_3(n/2) = a3_1_3;
a3_1_4 = a3_1_4 + wla(i)*wle(j)*wtr(k)*g_1_4(i,j,k);
est_g_1_4(n/2) = a3_1_4;
a3_2_1 = a3_2_1 + wla(i)*wle(j)*wtr(k)*g_2_1(i,j,k);
est_g_2_1(n/2) = a3_2_1;
a3_2_2 = a3_2_2 + wla(i)*wle(j)*wtr(k)*g_2_2(i,j,k);
est_g_2_2(n/2) = a3_2_2;
a3_2_3 = a3_2_3 + wla(i)*wle(j)*wtr(k)*g_2_3(i,j,k);
est_g_2_3(n/2) = a3_2_3;
a3_2_4 = a3_2_4 + wla(i)*wle(j)*wtr(k)*g_2_4(i,j,k);
est_g_2_4(n/2) = a3_2_4;
end
end
end
est_p_1(n/2) = est_g_1_1(n/2)+ est_g_2_1(n/2);
est_p_2(n/2) = est_g_1_2(n/2)+ est_g_2_2(n/2);
est_p_3(n/2) = est_g_1_3(n/2)+ est_g_2_3(n/2);
est_p_4(n/2) = est_g_1_4(n/2)+ est_g_2_4(n/2);
end
	
  
Code	
  for	
  Task	
  3	
  –	
  true	
  value:	
  
for n = 100
[r, wla] = gaussla(n-1);
[theta, wle] = gaussle(n-1);
[fi, wtr] = periodictrape(n);
g_1_4 = @(i,j,k)(((1/pi))*exp(-0.5*
p_4(sqrt((r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))/0.5))*r(i)^2*sin(theta(j
)));
g_2_4 = @(i,j,k)(((1/pi))*exp(-
sqrt(r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))*(1-exp(-
0.5*p_4(r(i)/0.5)+r(i)))*r(i)^2*sin(theta(j)));
a3_1_4_t = 0;
a3_2_4_t = 0;
for i = 1:n
for j = 1:n
for k = 1:n
a3_1_4_t = a3_1_4 + wla(i)*wle(j)*wtr(k)*g_1_4(i,j,k);
a3_2_4_t = a3_2_4 + wla(i)*wle(j)*wtr(k)*g_2_4(i,j,k);
end
end
end
end
true_p_4 = a3_1_4_t+ a3_2_4_t;
	
  
Code	
  for	
  Task	
  3	
  –	
  error	
  and	
  plot:	
  
errors_p_1 = zeros([16,1]);
errors_p_2 = zeros([16,1]);
errors_p_3 = zeros([16,1]);
errors_p_4 = zeros([16,1]);
for n = 2:2:32
errors_p_1(n/2) = abs(est_p_1(n/2)-true_p_4);
errors_p_2(n/2) = abs(est_p_2(n/2)-true_p_4);
errors_p_3(n/2) = abs(est_p_3(n/2)-true_p_4);
errors_p_4(n/2) = abs(est_p_4(n/2)-true_p_4);
A = log10(2:2:32);
B = log10(errors_p_1);
plot(A,B);
% loglog(2:2:32,errors_p_1)
% loglog(2:2:32,errors_p_2,2:2:32,errors_p_3,2:2:32,errors_p_4)
end
Code	
  for	
  Task	
  3	
  –	
  p1:	
  
function y = p_1(s)
if abs(s) <= 1
y = (1/2)*(1+s^2);
else
y = abs(s);
end
Code	
  for	
  Task	
  3	
  –	
  p2:	
  
function z = p_2(s)
if abs(s) <= 1
z = (1/8)*(3+6*s^2-s^4);
else
z = abs(s);
end
Code	
  for	
  Task	
  3	
  –	
  p3:	
  
function z = p_3(s)
if abs(s) <= 1
z = ((1/16)*(5+15*s^2-5*s^4+s^6));
else
z = abs(s);
end
Code	
  for	
  Task	
  3	
  –	
  p4:	
  
function z = p_4(s)
if abs(s) <= 1
z = ((1/128)*(35+140*s^2-70*s^4+28*s^6-5*s^8));
else
z = abs(s);
end
	
  
	
  
	
  

More Related Content

What's hot

REU Research Project_Final
REU Research Project_FinalREU Research Project_Final
REU Research Project_FinalJongyoon Sohn
 
Operators n dirac in qm
Operators n dirac in qmOperators n dirac in qm
Operators n dirac in qmAnda Tywabi
 
Hawkinrad a source_notes ii _secured
Hawkinrad a source_notes ii _securedHawkinrad a source_notes ii _secured
Hawkinrad a source_notes ii _securedfoxtrot jp R
 
Generalized Laplace - Mellin Integral Transformation
Generalized Laplace - Mellin Integral TransformationGeneralized Laplace - Mellin Integral Transformation
Generalized Laplace - Mellin Integral TransformationIJERA Editor
 
A Coupled Thermoelastic Problem of A Half – Space Due To Thermal Shock on the...
A Coupled Thermoelastic Problem of A Half – Space Due To Thermal Shock on the...A Coupled Thermoelastic Problem of A Half – Space Due To Thermal Shock on the...
A Coupled Thermoelastic Problem of A Half – Space Due To Thermal Shock on the...iosrjce
 
Stabilization of linear time invariant systems, Factorization Approach
Stabilization of linear time invariant systems, Factorization ApproachStabilization of linear time invariant systems, Factorization Approach
Stabilization of linear time invariant systems, Factorization ApproachSolo Hermelin
 
Effect of Longitudinal Velocity of the Particle of the Dusty Fluid with Volum...
Effect of Longitudinal Velocity of the Particle of the Dusty Fluid with Volum...Effect of Longitudinal Velocity of the Particle of the Dusty Fluid with Volum...
Effect of Longitudinal Velocity of the Particle of the Dusty Fluid with Volum...inventionjournals
 

What's hot (10)

Ladder operator
Ladder operatorLadder operator
Ladder operator
 
REU Research Project_Final
REU Research Project_FinalREU Research Project_Final
REU Research Project_Final
 
Operators n dirac in qm
Operators n dirac in qmOperators n dirac in qm
Operators n dirac in qm
 
Hawkinrad a source_notes ii _secured
Hawkinrad a source_notes ii _securedHawkinrad a source_notes ii _secured
Hawkinrad a source_notes ii _secured
 
Generalized Laplace - Mellin Integral Transformation
Generalized Laplace - Mellin Integral TransformationGeneralized Laplace - Mellin Integral Transformation
Generalized Laplace - Mellin Integral Transformation
 
A Coupled Thermoelastic Problem of A Half – Space Due To Thermal Shock on the...
A Coupled Thermoelastic Problem of A Half – Space Due To Thermal Shock on the...A Coupled Thermoelastic Problem of A Half – Space Due To Thermal Shock on the...
A Coupled Thermoelastic Problem of A Half – Space Due To Thermal Shock on the...
 
Stabilization of linear time invariant systems, Factorization Approach
Stabilization of linear time invariant systems, Factorization ApproachStabilization of linear time invariant systems, Factorization Approach
Stabilization of linear time invariant systems, Factorization Approach
 
Fluid dynamics
Fluid dynamicsFluid dynamics
Fluid dynamics
 
Derivadas
DerivadasDerivadas
Derivadas
 
Effect of Longitudinal Velocity of the Particle of the Dusty Fluid with Volum...
Effect of Longitudinal Velocity of the Particle of the Dusty Fluid with Volum...Effect of Longitudinal Velocity of the Particle of the Dusty Fluid with Volum...
Effect of Longitudinal Velocity of the Particle of the Dusty Fluid with Volum...
 

Similar to programming project

SRE poster final Joseph Solving Linear Equations Over p-adic Integers
SRE poster final Joseph Solving Linear Equations Over p-adic IntegersSRE poster final Joseph Solving Linear Equations Over p-adic Integers
SRE poster final Joseph Solving Linear Equations Over p-adic IntegersJoseph Molina
 
01. integral fungsi aljabar
01. integral fungsi aljabar01. integral fungsi aljabar
01. integral fungsi aljabarHirwanto Iwan
 
Differential Geometry for Machine Learning
Differential Geometry for Machine LearningDifferential Geometry for Machine Learning
Differential Geometry for Machine LearningSEMINARGROOT
 
Metal-Insulator Transitions I.pdf
Metal-Insulator Transitions I.pdfMetal-Insulator Transitions I.pdf
Metal-Insulator Transitions I.pdfTheAnalyzed
 
Variational Autoencoder Tutorial
Variational Autoencoder Tutorial Variational Autoencoder Tutorial
Variational Autoencoder Tutorial Hojin Yang
 
Dual Spaces of Generalized Cesaro Sequence Space and Related Matrix Mapping
Dual Spaces of Generalized Cesaro Sequence Space and Related Matrix MappingDual Spaces of Generalized Cesaro Sequence Space and Related Matrix Mapping
Dual Spaces of Generalized Cesaro Sequence Space and Related Matrix Mappinginventionjournals
 
Analysis of a self-sustained vibration of mass-spring oscillator on moving belt
Analysis of a self-sustained vibration of mass-spring oscillator on moving beltAnalysis of a self-sustained vibration of mass-spring oscillator on moving belt
Analysis of a self-sustained vibration of mass-spring oscillator on moving beltVarun Jadhav
 
Solving Poisson Equation using Conjugate Gradient Method and its implementation
Solving Poisson Equation using Conjugate Gradient Methodand its implementationSolving Poisson Equation using Conjugate Gradient Methodand its implementation
Solving Poisson Equation using Conjugate Gradient Method and its implementationJongsu "Liam" Kim
 
Schwarzchild solution derivation
Schwarzchild solution derivationSchwarzchild solution derivation
Schwarzchild solution derivationHassaan Saleem
 
g_9 - L_1 Solving Quadratic Equations.pptx
g_9 - L_1 Solving Quadratic Equations.pptxg_9 - L_1 Solving Quadratic Equations.pptx
g_9 - L_1 Solving Quadratic Equations.pptxMichelleMatriano
 
Numerical Analysis and Its application to Boundary Value Problems
Numerical Analysis and Its application to Boundary Value ProblemsNumerical Analysis and Its application to Boundary Value Problems
Numerical Analysis and Its application to Boundary Value ProblemsGobinda Debnath
 
Differential Calculus- differentiation
Differential Calculus- differentiationDifferential Calculus- differentiation
Differential Calculus- differentiationSanthanam Krishnan
 
RADIAL HEAT CONDUCTION SOLVED USING THE INTEGRAL EQUATION .pdf
RADIAL HEAT CONDUCTION SOLVED USING THE INTEGRAL EQUATION .pdfRADIAL HEAT CONDUCTION SOLVED USING THE INTEGRAL EQUATION .pdf
RADIAL HEAT CONDUCTION SOLVED USING THE INTEGRAL EQUATION .pdfWasswaderrick3
 

Similar to programming project (20)

SRE poster final Joseph Solving Linear Equations Over p-adic Integers
SRE poster final Joseph Solving Linear Equations Over p-adic IntegersSRE poster final Joseph Solving Linear Equations Over p-adic Integers
SRE poster final Joseph Solving Linear Equations Over p-adic Integers
 
01. integral fungsi aljabar
01. integral fungsi aljabar01. integral fungsi aljabar
01. integral fungsi aljabar
 
Differential Geometry for Machine Learning
Differential Geometry for Machine LearningDifferential Geometry for Machine Learning
Differential Geometry for Machine Learning
 
Solution problem2 eduardoenriqueescamillasaldana
Solution problem2 eduardoenriqueescamillasaldanaSolution problem2 eduardoenriqueescamillasaldana
Solution problem2 eduardoenriqueescamillasaldana
 
Metal-Insulator Transitions I.pdf
Metal-Insulator Transitions I.pdfMetal-Insulator Transitions I.pdf
Metal-Insulator Transitions I.pdf
 
purdue week4 Solution eduardoenriqueescamillasaldana
purdue week4 Solution eduardoenriqueescamillasaldanapurdue week4 Solution eduardoenriqueescamillasaldana
purdue week4 Solution eduardoenriqueescamillasaldana
 
Variational Autoencoder Tutorial
Variational Autoencoder Tutorial Variational Autoencoder Tutorial
Variational Autoencoder Tutorial
 
Hidden Markov Model
Hidden Markov ModelHidden Markov Model
Hidden Markov Model
 
Dual Spaces of Generalized Cesaro Sequence Space and Related Matrix Mapping
Dual Spaces of Generalized Cesaro Sequence Space and Related Matrix MappingDual Spaces of Generalized Cesaro Sequence Space and Related Matrix Mapping
Dual Spaces of Generalized Cesaro Sequence Space and Related Matrix Mapping
 
Numerical Solution of the Nonlocal Singularly Perturbed Problem
Numerical Solution of the Nonlocal Singularly Perturbed ProblemNumerical Solution of the Nonlocal Singularly Perturbed Problem
Numerical Solution of the Nonlocal Singularly Perturbed Problem
 
Analysis of a self-sustained vibration of mass-spring oscillator on moving belt
Analysis of a self-sustained vibration of mass-spring oscillator on moving beltAnalysis of a self-sustained vibration of mass-spring oscillator on moving belt
Analysis of a self-sustained vibration of mass-spring oscillator on moving belt
 
Solving Poisson Equation using Conjugate Gradient Method and its implementation
Solving Poisson Equation using Conjugate Gradient Methodand its implementationSolving Poisson Equation using Conjugate Gradient Methodand its implementation
Solving Poisson Equation using Conjugate Gradient Method and its implementation
 
AJMS_482_23.pdf
AJMS_482_23.pdfAJMS_482_23.pdf
AJMS_482_23.pdf
 
Schwarzchild solution derivation
Schwarzchild solution derivationSchwarzchild solution derivation
Schwarzchild solution derivation
 
Fourier series
Fourier series Fourier series
Fourier series
 
g_9 - L_1 Solving Quadratic Equations.pptx
g_9 - L_1 Solving Quadratic Equations.pptxg_9 - L_1 Solving Quadratic Equations.pptx
g_9 - L_1 Solving Quadratic Equations.pptx
 
Numerical Analysis and Its application to Boundary Value Problems
Numerical Analysis and Its application to Boundary Value ProblemsNumerical Analysis and Its application to Boundary Value Problems
Numerical Analysis and Its application to Boundary Value Problems
 
Differential Calculus- differentiation
Differential Calculus- differentiationDifferential Calculus- differentiation
Differential Calculus- differentiation
 
Basic calculus (ii) recap
Basic calculus (ii) recapBasic calculus (ii) recap
Basic calculus (ii) recap
 
RADIAL HEAT CONDUCTION SOLVED USING THE INTEGRAL EQUATION .pdf
RADIAL HEAT CONDUCTION SOLVED USING THE INTEGRAL EQUATION .pdfRADIAL HEAT CONDUCTION SOLVED USING THE INTEGRAL EQUATION .pdf
RADIAL HEAT CONDUCTION SOLVED USING THE INTEGRAL EQUATION .pdf
 

programming project

  • 1. 22M:  170   Programming  Assignment   Prof.  David  Steward   Lingwen  He   Friday,  December  12       Introduction:  the  Hydrogen  molecule   The  quantum  mechanics  of  multielectron  atoms  and  of  molecules  is  rather  complicated,  but  it  is   possible  to  obtain  information  about  chemistry  of  molecules  starting  just  from  the  basic   physical  theories  of  quantum  mechanics.     To  simplify  the  problem,  I  will  consider  the  following  three-­‐dimensional  integral:   𝛹! 𝑥 𝛹!(𝑥)𝑑𝑥 !!   Where   𝛹!and   𝛹!are  quantum  wavefunctions.  For  my  case  study  I  will  consider𝛹! 𝑥  =  𝑐!exp  (-­‐ 𝑥 − 𝑥! )  where   𝑥!  is  the  nucleus  of  one  hydrogen  atom,  and   𝛹!(𝑥)=  𝑐!  exp  (-­‐ 𝑥 − 𝑥! )  where   𝑥!  is  the  nucleus  of  the  other  hydrogen  atom.  I  will  be  able  to  avoid  using  complex  arithmetic   by  supposing  that   𝑐!  and   𝑐!  are  real.     The  wavefunctions  need  to  be  normalized;  that  is,  they  must  have  magnitude  one  in  the   𝐿! (𝑅! )   norm:   [ 𝛹(𝑥) ! 𝑑𝑥 !! ]!/! = 1   Here  I  introduce  spherical  polar  coordinates  to  calculate   𝑐!and𝑐!:   𝛸 = 𝑥 𝑦 𝑧 = 𝑟 sin 𝜃 cos 𝜑 𝑟 sin 𝜃 sin 𝜑 𝑟 cos 𝜃     Note  that   𝜃is  the  colatitude  (π/2  radians  minus  the  latitude),  φ  is  the  longitude  or  azimuth,  and  r   is  the  radius  from  the  center  of  the  coordinate  system.  I  restrict  the  variables  so  that  r≥0,  0≤θ≤π   and  0≤φ≤2π.  Then  the  volume  could  be  computed  using  “d  𝛸 = 𝑑𝑥𝑑𝑦𝑑𝑧 = 𝑟! sin 𝜃 𝑑𝑟𝑑𝜃𝑑𝜑”     If  I  take   𝑥!  as  the  center  of  spherical  polar  coordinates,  which  means  that   𝛸 − 𝑥!= 𝑟 sin 𝜃 cos 𝜑 𝑟 sin 𝜃 sin 𝜑 𝑟 cos 𝜃   Then  with  “d  𝛸 = 𝑑𝑥𝑑𝑦𝑑𝑧 = 𝑟! sin 𝜃 𝑑𝑟𝑑𝜃𝑑𝜑”,  I  get     𝛹! 𝑥 ! 𝑑𝑥!! = 𝑐! ! exp −𝑟 ! 𝑟! sin 𝜃 𝑑𝜑𝑑𝜃 !! ! ! ! ! ! 𝑑𝑟       = 𝑐! ! 𝑒!!!!! ! ! ! ! ! 𝑟! sin 𝜃 𝑑𝜑𝑑𝜃𝑑𝑟       = 𝑐! ! (2𝜋) ! ! ! ! 𝑒!!! 𝑟! sin 𝜃 𝑑𝜃𝑑𝑟       = 𝑐! ! (4𝜋) ! ! 𝑒!!! 𝑟!  𝑑𝑟  
  • 2.     =   𝑐! ! (4𝜋)(1/4)       =  1     Here  I  get   𝑐! ! = ! !   And  similarly,   𝑐! ! = 𝑐! ! = ! !     Then,  to  deal  with  iterated  integrals  of  this  sort,  I  write  them  as  nested  one-­‐variable  integrals   and  apply  standard  numerical  methods  for  each  one-­‐variable  integral.     The  integral  over  r  is  over  the  interval  [0,  ∞),  and  f(r,  θ,  φ)  typically  decays  exponentially.  This   motivates  the  use  of  Gauss-­‐Laguerre  integration  over  r.    Gauss-­‐Laguerre  integration:   𝑒!! 𝑓(𝑥)𝑑𝑥 ≈ 𝑤! 𝑓(𝑥!) ! !!! ! !   The  integral  over  θ  is  over  [0,  π]  and  there  is  no  particular  structure  of  dependence  of  f(r,  θ,  φ)   on  θ.  This  motivates  the  use  of  Gauss-­‐Legendre  integration  over  θ.   Gauss-­‐Legendre  integration:   𝑓(𝑥)𝑑𝑥 ≈ 𝑤! 𝑓(𝑥!) ! !!! ! !!   Notice  that  the  integral  is  from  -­‐1  to  1  and  in  my  case  the  integral  is  from  0  to  pi  and  therefore  I   need  transformation.     The  integral  over  φ  is  over  [0,  2π]  and  f(r,  θ,  φ)  is  periodic  in  φ.  This  motivates  the  use  of   (periodic)  Trapezoidal  rule.   (Periodic)  Trapezoidal  rule:   𝑓(𝑥)𝑑𝑥 ≈ 𝑤! 𝑓(𝑥!) ! !!! ! !     Combining  these  rules  gives  a  formula   𝑔(𝑟, 𝜃, 𝜑)𝑒!! sin 𝜃 𝑑𝜑𝑑𝜗𝑑𝑟 ≈ 𝑤! !" 𝑤! !" 𝑤! !" 𝑔(𝑟! !" , 𝜃! !" , 𝜑! !" ) !,!,! !! ! ! ! ! !   Where   𝑤! !"  and   𝑟! !"  are  weights  and  nodes  for  the  modified  Gauss-­‐Laguerre  quadrature   formula,   𝑤! !"  and   𝜃! !"  are  the  weights  and  nodes  for  Gauss-­‐Legendre  quadrature  on  [0,  π]  and   𝑤! !"  and   𝜑! !"  are  the  weights  and  nodes  for  the  (periodic)  trapezoidal  rule  on  [0,  2π].     Task1:  use  the  above  formula  to  numerically  compute   𝛹(𝑥) ! 𝑑𝑥!!  using  N  =  2,  4,  …,  32  nodes   in  each  one-­‐variable  rule  (at  least  12  or  13  digits).  I  calculate  the  exact  value  of   𝑐! !  to   satisfy 𝛹(𝑥) ! 𝑑𝑥!! = 1,  and  therefore  I  can  calculate  errors  from  the  numerical  method.  Plot   errors  against  N  using  log-­‐log  or  semi-­‐log.  Choose  the  plot  that  best  show  the  behavior  of  the   error  as  a  function  of  N.  
  • 3.   First  of  all,  by  comparing  the  formulas,  I  can  get   𝑔(𝑟, 𝜃, 𝜑)=𝑒!! 𝑟! sin 𝜃.   Since  I  know  the  value  of   𝑐! !  that  sets  the  equation  to  be  1,  I  know  that  the  true  value  of  the   integral  is  1/ 𝑐! ! =  π.   N   Approximation   Error   2   2.666299698360362e+00   4.752929552294316e-­‐01   4   3.067694205166275e+00   7.389844842351767e-­‐02   6   3.138543286202643e+00   3.049367387149893e-­‐03   8   3.141508554739558e+00   8.409885023485941e-­‐05   10   3.141590751423614e+00   1.902166179235110e-­‐06   12   3.141592615396657e+00   3.819313576514105e-­‐08   14   3.141592652881650e+00   7.081428776700705e-­‐10   16   3.141592653577389e+00   1.240429980953195e-­‐11   18   3.141592653589601e+00   1.918465386552271e-­‐13   20   3.141592653589866e+00   7.283063041541027e-­‐14   22   3.141592653589710e+00   8.348877145181177e-­‐14   24   3.141592653589723e+00   6.972200594645983e-­‐14   26   3.141592653589877e+00   8.393286066166183e-­‐14   28   3.141592653589813e+00   1.953992523340276e-­‐14   30   3.141592653589794e+00   1.332267629550188e-­‐15   32   3.141592653589771e+00   2.176037128265307e-­‐14     The  semi-­‐log  plot  is  shown  as  below.  By  using  this  procedure,  I  can  get  a  minimum  error  to  be   around  10!!" .    
  • 4. But  as  a  matter  of  fact,  the  nuclei  are  not  centered  at  the  same  point.  Suppose  that  the  nuclei   are  centered  at   𝑥!!  !(!/!)!!  and   𝑥! = +(𝑎/2)𝑒!  where  a  >0  is  the  inter-­‐nucleus  distance  (in   suitable  units).  Start  with  a  =  1.i  want  to  accurately  compute  the  integral 𝜓!(𝑥)𝜓!(𝑥)𝑑𝑥!!   where   𝜓!and   𝜓!are  given  by  the  formulas  above.  I  can  use  polar  coordinates  centered  on     𝑥!  or     𝑥!  or  on  the  origin  (x=0).   Task2:  Compute  the  integral   𝛹! 𝑥 𝛹!(𝑥)𝑑𝑥!!  using  polar  coordinates  centered  at   𝑥!  for  N  =  2,   4,  …,  32  as  was  done  for  the  previous  task.  Plot  the  errors  against  N;  from  the  plot  estimate  α   where  error  ≈const*𝑁!!       Here  I  start  with 𝛹! 𝑥 𝛹!(𝑥)𝑑𝑥!! .   𝛹! 𝑥 = 𝑐! 𝑒! !!!! = 𝑐! 𝑒!!  (Where   𝑥 − 𝑥!   = 𝑟 sin 𝜃 cos 𝜑 𝑟 sin 𝜃 sin 𝜑 𝑟 cos 𝜃 ).   𝛹! 𝑥 = 𝑐! 𝑒! !!!! = 𝑐! 𝑒! !!!!! !"# ! !"# !!!! (Where   𝑥 − 𝑥! = 𝑥 − 𝑥!   +𝑥!-­‐𝑥!=   𝑟 sin 𝜃 cos 𝜑 𝑟 sin 𝜃 sin 𝜑 𝑟 cos 𝜃  +  [ − ! ! 𝑒! − ! ! 𝑒!]= 𝑟 sin 𝜃 cos 𝜑 − 𝑎 𝑟 sin 𝜃 sin 𝜑 𝑟 cos 𝜃 )     Hence,   𝛹! 𝑥 𝛹! 𝑥 𝑑𝑥!!   = 𝑐! ! 𝑒!! 𝑒! !!!!! !"# ! !"# !!!! 𝑑𝑥!!   = 𝑐! ! 𝑒!! 𝑒! !!!!! !"# ! !"# !!!! 𝑟! sin 𝜃 𝑑𝜑𝑑𝜃 !! ! ! ! ! ! 𝑑𝑟     Use  similar  procedures  as  I  do  in  Task  1,     𝑔(𝑟, 𝜃, 𝜑)𝑒!! sin 𝜃 𝑑𝜑𝑑𝜗𝑑𝑟 ≈ 𝑤! !" 𝑤! !" 𝑤! !" 𝑔(𝑟! !" , 𝜃! !" , 𝜑! !" ) !,!,! !! ! ! ! ! !   I  set  my   𝑔(𝑟, 𝜃, 𝜑)= 𝑐! ! 𝑒! !!!!! !"# ! !"# !!!! 𝑟! sin 𝜃   Notice  that  I  start  with  a  =  1.  And  as  to  approach  error,  I  can’t  possibly  get  the  true  value  of  the   integral  since  I  have  no  previous  information  about  it.  In  this  case,  I  use  a  quite  large  n  to   estimate  the  integral  and  use  this  value  as  “true”  value  b.  Hence  the  error  is  approximately   absolute  value  of  (b-­‐approximation).     N   Approximation   Error   2   6.275397375557281e-­‐01   2.308269611957977e-­‐01   4   8.685938120755217e-­‐01   1.022711332399584e-­‐02   6   8.766068263788301e-­‐01   1.824012762730431e-­‐02   8   8.596630442183523e-­‐01   1.296345466826443e-­‐03   10   8.543290409209439e-­‐01   4.037657830581964e-­‐03   12   8.561946702267949e-­‐01   2.172028524730973e-­‐03   14   8.586705405645276e-­‐01   3.038418130018039e-­‐04   16   8.598648511824449e-­‐01   1.498152430919109e-­‐03   18   8.596488591619377e-­‐01   1.282160410411848e-­‐03  
  • 5. 20   8.586152984830179e-­‐01   2.485997314920496e-­‐04   22   8.578802245327801e-­‐01   4.864742187457027e-­‐04   24   8.577243480976197e-­‐01   6.423506539061652e-­‐04   26   8.579340865310428e-­‐01   4.326122204830751e-­‐04   28   8.582733013873762e-­‐01   9.339736414959443e-­‐05   30   8.585758492146289e-­‐01   2.091504631031027e-­‐04   32   8.587457745141339e-­‐01   3.790757626080943e-­‐04     b  =            8.583666987515258e-­‐01   The  log-­‐log  plot  is  shown  as  below.  By  using  procedures  through  task  2,  I  can  get  a  minimum   error  around  10!! .     log 𝑒𝑟𝑟𝑜𝑟 ≈ alog 𝑁 + 𝑏   𝑒𝑟𝑟𝑜𝑟 ≈   𝑁! 𝑒! = 𝑐𝑜𝑛𝑠𝑡 ∗ 𝑁!!     From  the  basic  fitting  tool  I  have  the  following  information:  
  • 6.   Hence,  α  =  -­‐a  =  -­‐p1  =  2.3201   Compared  with  task  1,  which  has  a  minimum  error  around  10!!" ,  this  error  is  somehow  too   large.  The  reason  for  large  error  is  that  when  I  use   𝑥!  as  the  center,  the  function  at  point   𝑥!  is   not  smooth.  Another  reason  is  that  I  don’t  have  the  true  value  for  the  integral  but  only  can   estimate  it  by  choosing  a  fairly  large  number  n.  To  deal  with  this  problem,  I  use  techniques   shown  in  task  3.     As  the  problem  arises  in  task  2,  I  need  to  find  a  way  to  deal  with  the  non-­‐smoothness  of   𝛹!(𝑥)   at  𝑥 = 𝑥!.  To  do  this,  I  consider  splitting  the  integral  into  two  parts:   𝛹! 𝑥 = 𝛹! ! 𝑥 + 𝛹! ! (𝑥)  where   𝛹! ! 𝑥 is  smooth  (or  at  least  smoother)  at  𝑥 = 𝑥!,  and   𝛹! ! 𝑥  still  has  the   cusp  at   𝑥 = 𝑥!,  but  is  smooth  elsewhere  and  zero  outside  a  ball  centered  on   𝑥!  with  radius   substantially  less  than  a  (say,  radius  is  a/2).  In  this  way,   𝛹! 𝑥 𝛹! 𝑥 𝑑𝑥!!  =   𝛹! 𝑥 𝛹! ! 𝑥 𝑑𝑥!!  +   𝛹! 𝑥 𝛹! ! 𝑥 𝑑𝑥!!     𝛹! 𝑥 𝛹! ! 𝑥 𝑑𝑥!!  Can  be  computed  using  polar  coordinates  centered  on   𝑥!  and   𝛹! 𝑥 𝛹! ! 𝑥 𝑑𝑥!!  can  be  computed  using  polar  coordinates  centered  on  𝑥!.  Let   𝑟∗  be  the   “cutoff  radius”  of   𝛹! ! ,  and  take     𝛹! ! 𝑥 = exp  (−  𝑟∗ 𝑝( 𝑥 − 𝑥! /  𝑟∗ ))   With  p(s)  given  by   𝑝! 𝑠 = ! ! 1 + 𝑠!  𝑓𝑜𝑟   𝑠 ≤ 1𝑎𝑛𝑑   𝑠 𝑓𝑜𝑟   𝑠 ≥ 1, 𝑜𝑟     𝑝! 𝑠 = ! ! 3 + 6𝑠! − 𝑠!  𝑓𝑜𝑟   𝑠 ≤ 1𝑎𝑛𝑑   𝑠 𝑓𝑜𝑟   𝑠 ≥ 1, 𝑜𝑟     𝑝! 𝑠 = ! !" 5 + 15𝑠! − 5𝑠! + 𝑠!  𝑓𝑜𝑟   𝑠 ≤ 1𝑎𝑛𝑑   𝑠 𝑓𝑜𝑟   𝑠 ≥ 1, 𝑜𝑟     𝑝! 𝑠 = ! !"# 35 + 140𝑠! − 70𝑠! + 28𝑠! − 5𝑠!  𝑓𝑜𝑟   𝑠 ≤ 1𝑎𝑛𝑑   𝑠 𝑓𝑜𝑟   𝑠 ≥ 1.     The  function   𝑝! 𝑠  matches  |s|  and  its  derivatives  up  to  the  kth  derivative  at  s  =1.  Whatever   p(s)  is,  I  let  𝛹! ! 𝑥 = 𝛹! 𝑥 − 𝛹! ! 𝑥 .  
  • 7. Task  3:  implement  this  splitting  of  the  integral  and  evaluating  the  integral  using  polar   coordinates  centered  first  at   𝑥!  and  then  at   𝑥!.  Repeat  using   𝑝 𝑠 = 𝑝! 𝑠  for  a  few  values  of  k.   Again,  use  the  same  values  of  N  as  for  Task  2,  and  plot  the  errors.  Compare  the  two  methods   and  comment  on  the  accuracy  of  this  splitting  approach.   Here  I  approach  the  integral  by  splitting  it  into  two  parts.  For  the  first  part,   𝛹! 𝑥 𝛹! ! 𝑥 𝑑𝑥!!   I  choose  to  compute  this  by  using  polar  coordinates  centered  on  𝑥!  because  when  centered   on  𝑥!  this  integral  part  doesn’t  have  to  deal  with  non-­‐smoothness  on  𝑥!.  Similarly,  I  approach   𝛹! 𝑥 𝛹! ! 𝑥 𝑑𝑥!!  centered  on  𝑥!.   𝛹! 𝑥 𝛹! ! 𝑥 𝑑𝑥!!      =   𝑐! exp  (− 𝑥 − 𝑥! )exp  (−  𝑟∗ 𝑝( 𝑥 − 𝑥! /  𝑟∗ ))!! 𝑑𝑥         =   𝑐! exp −𝑟 exp −  𝑟∗ 𝑝 !!!!!" !"# ! !"# !!!! !∗ 𝑑𝑥!!   = 𝑐! 𝑒!! 𝑒 !  !∗! !!!!!" !"# ! !"# !!!! !∗ 𝑟! sin 𝜃 𝑑𝜑𝑑𝜃 !! ! ! ! ! ! 𝑑𝑟   Use  similar  procedures  as  I  do  in  previous  tasks,     𝑔(𝑟, 𝜃, 𝜑)𝑒!! sin 𝜃 𝑑𝜑𝑑𝜗𝑑𝑟 ≈ 𝑤! !" 𝑤! !" 𝑤! !" 𝑔(𝑟! !" , 𝜃! !" , 𝜑! !" ) !,!,! !! ! ! ! ! !   I  set   𝑔! 𝑟, 𝜃, 𝜑 = 𝑐! 𝑒 !  !∗! !!!!!" !"# ! !"# !!!! !∗ 𝑟!   For  the  second  integral  part:   𝛹! 𝑥 𝛹! ! 𝑥 𝑑𝑥!!      =   𝑐! exp  (− 𝑥 − 𝑥! )(exp − 𝑥 − 𝑥! − exp −  𝑟∗ 𝑝 !!!! !∗ )!! 𝑑𝑥         =   𝑐! 𝑒! !!!!!" !"# ! !"# !!!! (𝑒!! − 𝑒!  !∗! ! !∗ !! )𝑑𝑥         =   𝑐! 𝑒! !!!!!" !"# ! !"# !!!! (𝑒!! )(1 − 𝑒!  !∗! ! !∗ !! !! )𝑑𝑥   I  set   𝑔! 𝑟, 𝜃, 𝜑 = 𝑐! 𝑒! !!!!!" !"# ! !"# !!!! (1 − 𝑒!  !∗! ! !∗ !! )𝑟!   Notice  that  since  I  still  don’t  have  a  true  value  for  the  whole  integral,  I  will  set  a  large  N=100   and  use   𝑝!  to  be  the  substitute  true  value  of  the  integral.  Start  with  a  =  1.   N   𝑝!   𝑝!   𝑝!   𝑝!   2   6.275397375 557281e-­‐01   6.275397375 557281e-­‐01   6.275397375 557281e-­‐01   6.275397375 557281e-­‐01   4   8.714064363 563853e-­‐01   8.695131656 705224e-­‐01   8.689528215 010126e-­‐01   8.687474782 715300e-­‐01  
  • 8. 6   8.786039083 504553e-­‐01   8.777578511 187618e-­‐01   8.772790065 266729e-­‐01   8.770205550 555248e-­‐01   8   8.582456023 965205e-­‐01   8.594157947 776662e-­‐01   8.597281088 424541e-­‐01   8.598124641 876246e-­‐01   10   8.546542404 576916e-­‐01   8.547500837 948759e-­‐01   8.546928931 430776e-­‐01   8.546246304 921056e-­‐01   12   8.568284926 509197e-­‐01   8.566378751 172376e-­‐01   8.565206960 438592e-­‐01   8.564456266 684295e-­‐01   14   8.585848586 528182e-­‐01   8.588443780 747900e-­‐01   8.588647350 691916e-­‐01   8.588446135 333351e-­‐01   16   8.586998622 324101e-­‐01   8.592990627 975690e-­‐01   8.595740788 534714e-­‐01   8.597135679 661798e-­‐01   18   8.582761953 050426e-­‐01   8.587474246 676631e-­‐01   8.590316188 214573e-­‐01   8.592037171 988656e-­‐01   20   8.580378222 387637e-­‐01   8.581338006 410553e-­‐01   8.582671303 241453e-­‐01   8.583647262 947616e-­‐01   22   8.581736560 077830e-­‐01   8.579082022 441408e-­‐01   8.578644682 949865e-­‐01   8.578652136 394707e-­‐01   24   8.585531645 857941e-­‐01   8.580621676 261577e-­‐01   8.578930720 771248e-­‐01   8.578234749 559234e-­‐01   26   8.588273369 374346e-­‐01   8.583704725 317424e-­‐01   8.581722771 241345e-­‐01   8.580768453 772285e-­‐01   28   8.588106011 214202e-­‐01   8.585870703 748407e-­‐01   8.584600822 899386e-­‐01   8.583909018 200789e-­‐01   30   8.586446546 515094e-­‐01   8.586374722 505155e-­‐01   8.586087722 162836e-­‐01   8.585910134 739473e-­‐01   32   8.584236385 569799e-­‐01   8.585691973 184119e-­‐01   8.586093620 024660e-­‐01   8.586307147 994179e-­‐01     true_p_4  =            8.586307147994179e-­‐01   N   𝐸𝑟𝑟𝑜𝑟(𝑝!)   𝐸𝑟𝑟𝑜𝑟(𝑝!)   𝐸𝑟𝑟𝑜𝑟(𝑝!)   𝐸𝑟𝑟𝑜𝑟(𝑝!)   2   2.310909772 436898e-­‐01   2.310909772 436898e-­‐01   2.310909772 436898e-­‐01   2.310909772 436898e-­‐01   4   1.277572155 696738e-­‐02   1.088245087 110451e-­‐02   1.032210670 159472e-­‐02   1.011676347 211210e-­‐02   6   1.997319355 103744e-­‐02   1.912713631 934393e-­‐02   1.864829172 725502e-­‐02   1.838984025 610690e-­‐02   8   3.851124028 974029e-­‐04   7.850799782 482820e-­‐04   1.097394043 036215e-­‐03   1.181749388 206699e-­‐03   10   3.976474341 726322e-­‐03   3.880631004 541946e-­‐03   3.937821656 340268e-­‐03   4.006084307 312308e-­‐03   12   1.802222148 498234e-­‐03   1.992839682 180336e-­‐03   2.110018755 558718e-­‐03   2.185088130 988389e-­‐03   14   4.585614659 968762e-­‐05   2.136632753 720891e-­‐04   2.340202697 737048e-­‐04   2.138987339 171949e-­‐04   16   6.914743299 224480e-­‐05   6.683479981 510754e-­‐04   9.433640540 534860e-­‐04   1.082853166 761932e-­‐03            
  • 9. 18   3.545194943 752605e-­‐04   1.167098682 451906e-­‐04   4.009040220 394056e-­‐04   5.730023994 476863e-­‐04   20   5.928925606 542013e-­‐04   4.969141583 626158e-­‐04   3.635844752 726269e-­‐04   2.659885046 563115e-­‐04   22   4.570587916 349345e-­‐04   7.225125552 771106e-­‐04   7.662465044 313560e-­‐04   7.655011599 472239e-­‐04   24   7.755021362 376713e-­‐05   5.685471732 601588e-­‐04   7.376427222 930415e-­‐04             8.072398434 945116e-­‐04             26   1.966221380 167443e-­‐04   2.602422676 755145e-­‐04   4.584376752 834185e-­‐04   5.538694221 893792e-­‐04   28   1.798863220 022762e-­‐04   4.364442457 716056e-­‐05   1.706325094 792405e-­‐04                       2.398129793 389492e-­‐04   30   1.393985209 152682e-­‐05   6.757451097 572087e-­‐06   2.194258313 426012e-­‐05   3.970132547 059802e-­‐05   32   2.070762424 379868e-­‐04   6.151748100 602372e-­‐05   2.135279695 192338e-­‐05   0     A  log-­‐log  plot  is  shown  as  below.          
  • 10. By  using  basic  fitting,  I  have  my  best  linear  fit  for  these  4  lines:   Error  in     𝑝!   Error  in     𝑝!   Error  in     𝑝!   Error  in     𝑝!             Note  that  the  fitting  of  line  is  similar  as  in  Task  2:   log 𝑒𝑟𝑟𝑜𝑟 ≈ alog 𝑁 + 𝑏   Where  p1  stands  for  a  and  p2  stands  for  b  here.  Compared  with  Task  2,  here  α  is  larger,  which  is   what  I  want.  However,  error  actually  doesn’t  improve  much  as  I  previously  imagine.  This  is   because  in  my  calculation,  I  don’t  have  the  true  value  of  the  integral  but  use  a  large  N  to   estimate  a  value.  Notice  the  error  in  𝑝!  when  n  =  32  drops  down  to  0.  Hence  the  error  is  far   large  than  it  should  be.   𝑒𝑟𝑟𝑜𝑟 ≈   𝑁! 𝑒! = 𝑐𝑜𝑛𝑠𝑡 ∗ 𝑁!!     To  better  deal  with  the  accuracy,  I  have  some  options  to  continue  with:   1) Have  more  information  about  the  true  value  (or  at  least  approximate  enough)     2) Better  approach  the  integral  with  smoother  functions          
  • 11. Appendix   Codes  for  Gauss-­‐Laguerre   function  [x,w]  =  gaussla(n)   %  function  [x,w]  =  gaussla(n)   %   %  Generates  points  and  weights  for  Gauss-­‐Laguerre  quadrature   %  Uses  the  tridiagonal  eigenvalue/eigenvector  approach   %  of  Golub  and  Welsch  (Stanford  CS  TR-­‐81  (1967)      a(1:n+1)  =  -­‐1./(1:n+1);      b(1:n+1)  =  (2*(1:n+1)-­‐1)./(1:n+1);      c(1:n+1)  =  (0:n)./(1:n+1);      alpha  =  -­‐b  ./  a;      beta    =  sqrt(c(2:n+1)./(a(1:n).*a(2:n+1)));      J  =  diag(alpha)  +  diag(beta,1)  +  diag(beta,-­‐1);      [V,D]  =  eig(J);      x  =  diag(D)';      w  =  V(1,:).^2;      w  =  w  /  sum(w);         Code  for  Gauss-­‐Legendre   function  [x,w]  =  gaussle(n)   %  function  [x,w]  =  gaussle(n)   %   %  Generates  points  and  weights  for  Gauss-­‐Legendre  quadrature   %  Uses  the  tridiagonal  eigenvalue/eigenvector  approach   %  of  Golub  and  Welsch  (Stanford  CS  TR-­‐81  (1967)      a(1:n+1)  =  (2*(1:n+1)-­‐1)./(1:n+1);      b(1:n+1)  =  0;      c(1:n+1)  =  (0:n)./(1:n+1);      alpha  =  -­‐b  ./  a;      beta    =  sqrt(c(2:n+1)./(a(1:n).*a(2:n+1)));      J  =  diag(alpha)  +  diag(beta,1)  +  diag(beta,-­‐1);      [V,D]  =  eig(J);      x  =  diag(D)';      x  =  (x+1)*pi/2;      w  =  V(1,:).^2;      w  =  pi*w  /  sum(w);         Code  for  (periodic)  Trapezoidal  Rule:   function  [x,  w]  =  periodictrape(n)   x  =  zeros([1,n]);   w  =  zeros([1,n]);   for  i  =  1:n          x(i)  =  2*pi*i/n;          w(i)  =  2*pi/n;   end     Code  for  Task  1:   estimation  =  zeros([16,1]);  
  • 12. errors  =  zeros([16,1]);   for  n  =  2:2:32          [r,  wla]  =  gaussla(n-­‐1);          [theta,  wle]  =  gaussle(n-­‐1);          [fi,  wtr]  =  periodictrape(n);          g=@(i,j,k)(exp(-­‐r(i))*(r(i)^2)*sin(theta(j)));          a  =  0;          for  i  =  1:n                  for  j  =  1:n                          for  k  =  1:n                                  a  =  a  +  wla(i)*wle(j)*wtr(k)*g(i,j,k);                                  estimation(n/2)=a;                                  errors(n/2)=a  -­‐  pi;                          end                  end          end   end     Code  for  Task  2  -­‐  estimation:   estimation_task2  =  zeros([16,1]);   for  n  =  2:2:32          [r,  wla]  =  gaussla(n-­‐1);          [theta,  wle]  =  gaussle(n-­‐1);          [fi,  wtr]  =  periodictrape(n);          g=@(i,j,k)(exp(-­‐sqrt(r(i)^2-­‐2*r(i)*sin(theta(j))*cos(fi(k))+1))*(r(i)^2)*sin(theta(j))*(1/pi));          a2  =  0;          for  i  =  1:n                  for  j  =  1:n                          for  k  =  1:n                                  a2  =  a2  +  wla(i)*wle(j)*wtr(k)*g(i,j,k);                                  estimation_task2(n/2)=a2;                          end                  end          end   end     Code  for  Task  2  –  set  a  true  value:   for  n  =  100          [r,  wla]  =  gaussla(n-­‐1);          [theta,  wle]  =  gaussle(n-­‐1);          [fi,  wtr]  =  periodictrape(n);          g=@(i,j,k)(exp(-­‐sqrt(r(i)^2-­‐2*r(i)*sin(theta(j))*cos(fi(k))+1))*(r(i)^2)*sin(theta(j))*(1/pi));          b  =  0;          for  i  =  1:n                  for  j  =  1:n                          for  k  =  1:n                                  b  =  b  +  wla(i)*wle(j)*wtr(k)*g(i,j,k);                                        end                  end          end  
  • 13. end         Code  for  Task  2  –  errors  and  plot:   errors_task2  =  zeros([16,1]);   for  n  =  2:2:32          errors_task2(n/2)  =  abs(estimation_task2(n/2)-­‐b);   end       loglog(2:2:32,errors_task2)     Code  for  Task  3  –  estimation:   est_g_1_1 = zeros([16,1]); est_g_1_2 = zeros([16,1]); est_g_1_3 = zeros([16,1]); est_g_1_4 = zeros([16,1]); est_g_2_1 = zeros([16,1]); est_g_2_2 = zeros([16,1]); est_g_2_3 = zeros([16,1]); est_g_2_4 = zeros([16,1]); for n = 2:2:32 [r, wla] = gaussla(n-1); [theta, wle] = gaussle(n-1); [fi, wtr] = periodictrape(n); g_1_1 = @(i,j,k)((1/pi)*exp(-0.5* p_1(sqrt((r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))/0.5))*r(i)^2*sin(theta(j ))); g_1_2 = @(i,j,k)((1/pi)*exp(-0.5* p_2(sqrt((r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))/0.5))*r(i)^2*sin(theta(j ))); g_1_3 = @(i,j,k)(((1/pi))*exp(-0.5* p_3(sqrt((r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))/0.5))*r(i)^2*sin(theta(j ))); g_1_4 = @(i,j,k)(((1/pi))*exp(-0.5* p_4(sqrt((r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))/0.5))*r(i)^2*sin(theta(j ))); g_2_1 = @(i,j,k)(((1/pi))*exp(- sqrt(r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))*(1-exp(- 0.5*p_1(r(i)/0.5)+r(i)))*r(i)^2*sin(theta(j))); g_2_2 = @(i,j,k)(((1/pi))*exp(- sqrt(r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))*(1-exp(- 0.5*p_2(r(i)/0.5)+r(i)))*r(i)^2*sin(theta(j))); g_2_3 = @(i,j,k)(((1/pi))*exp(- sqrt(r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))*(1-exp(- 0.5*p_3(r(i)/0.5)+r(i)))*r(i)^2*sin(theta(j))); g_2_4 = @(i,j,k)(((1/pi))*exp(- sqrt(r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))*(1-exp(- 0.5*p_4(r(i)/0.5)+r(i)))*r(i)^2*sin(theta(j))); a3_1_1 = 0; a3_1_2 = 0; a3_1_3 = 0; a3_1_4 = 0;
  • 14. a3_2_1 = 0; a3_2_2 = 0; a3_2_3 = 0; a3_2_4 = 0; for i = 1:n for j = 1:n for k = 1:n a3_1_1 = a3_1_1 + wla(i)*wle(j)*wtr(k)*g_1_1(i,j,k); est_g_1_1(n/2) = a3_1_1; a3_1_2 = a3_1_2 + wla(i)*wle(j)*wtr(k)*g_1_2(i,j,k); est_g_1_2(n/2) = a3_1_2; a3_1_3 = a3_1_3 + wla(i)*wle(j)*wtr(k)*g_1_3(i,j,k); est_g_1_3(n/2) = a3_1_3; a3_1_4 = a3_1_4 + wla(i)*wle(j)*wtr(k)*g_1_4(i,j,k); est_g_1_4(n/2) = a3_1_4; a3_2_1 = a3_2_1 + wla(i)*wle(j)*wtr(k)*g_2_1(i,j,k); est_g_2_1(n/2) = a3_2_1; a3_2_2 = a3_2_2 + wla(i)*wle(j)*wtr(k)*g_2_2(i,j,k); est_g_2_2(n/2) = a3_2_2; a3_2_3 = a3_2_3 + wla(i)*wle(j)*wtr(k)*g_2_3(i,j,k); est_g_2_3(n/2) = a3_2_3; a3_2_4 = a3_2_4 + wla(i)*wle(j)*wtr(k)*g_2_4(i,j,k); est_g_2_4(n/2) = a3_2_4; end end end est_p_1(n/2) = est_g_1_1(n/2)+ est_g_2_1(n/2); est_p_2(n/2) = est_g_1_2(n/2)+ est_g_2_2(n/2); est_p_3(n/2) = est_g_1_3(n/2)+ est_g_2_3(n/2); est_p_4(n/2) = est_g_1_4(n/2)+ est_g_2_4(n/2); end   Code  for  Task  3  –  true  value:   for n = 100 [r, wla] = gaussla(n-1); [theta, wle] = gaussle(n-1); [fi, wtr] = periodictrape(n); g_1_4 = @(i,j,k)(((1/pi))*exp(-0.5* p_4(sqrt((r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))/0.5))*r(i)^2*sin(theta(j ))); g_2_4 = @(i,j,k)(((1/pi))*exp(- sqrt(r(i)^2+2*r(i)*sin(theta(j))*cos(fi(k))+1))*(1-exp(- 0.5*p_4(r(i)/0.5)+r(i)))*r(i)^2*sin(theta(j))); a3_1_4_t = 0; a3_2_4_t = 0; for i = 1:n for j = 1:n for k = 1:n a3_1_4_t = a3_1_4 + wla(i)*wle(j)*wtr(k)*g_1_4(i,j,k); a3_2_4_t = a3_2_4 + wla(i)*wle(j)*wtr(k)*g_2_4(i,j,k); end end
  • 15. end end true_p_4 = a3_1_4_t+ a3_2_4_t;   Code  for  Task  3  –  error  and  plot:   errors_p_1 = zeros([16,1]); errors_p_2 = zeros([16,1]); errors_p_3 = zeros([16,1]); errors_p_4 = zeros([16,1]); for n = 2:2:32 errors_p_1(n/2) = abs(est_p_1(n/2)-true_p_4); errors_p_2(n/2) = abs(est_p_2(n/2)-true_p_4); errors_p_3(n/2) = abs(est_p_3(n/2)-true_p_4); errors_p_4(n/2) = abs(est_p_4(n/2)-true_p_4); A = log10(2:2:32); B = log10(errors_p_1); plot(A,B); % loglog(2:2:32,errors_p_1) % loglog(2:2:32,errors_p_2,2:2:32,errors_p_3,2:2:32,errors_p_4) end Code  for  Task  3  –  p1:   function y = p_1(s) if abs(s) <= 1 y = (1/2)*(1+s^2); else y = abs(s); end Code  for  Task  3  –  p2:   function z = p_2(s) if abs(s) <= 1 z = (1/8)*(3+6*s^2-s^4); else z = abs(s); end Code  for  Task  3  –  p3:   function z = p_3(s) if abs(s) <= 1 z = ((1/16)*(5+15*s^2-5*s^4+s^6)); else z = abs(s); end Code  for  Task  3  –  p4:  
  • 16. function z = p_4(s) if abs(s) <= 1 z = ((1/128)*(35+140*s^2-70*s^4+28*s^6-5*s^8)); else z = abs(s); end