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
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
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