首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
辅导COMPSCI编程、讲解Java,c++语言程序、讲解Python设计编程 解析R语言编程|辅导R语言程序
项目预算:
开发周期:
发布时间:
要求地区:
COMPSCI 1JC3 C01
Introduction to Computational Thinking
Fall 2020
Assignment 5
The purpose of Assignment 5 is implement a practical higher-order function.
The requirements for Assignment 5 and for Assignment 5 Extra Credit
are given below. You are required to do Assignment 5, but Assignment 5 Extra
Credit is optional. Please submit Assignment 5 as two files, Assign 5.hs
and Assign 5 Test.hs, to the Assignment 5 folder on Avenue under Assessments/Assignments.
If you choose to do Assignment 5 Extra Credit for extra
marks, please submit it also as two files, Assign 5 ExtraCredit.hs and
Assign 5 Test ExtraCredit.hs, to the Assignment 5 Extra Credit folder
on Avenue in the same place. Both Assignment 5 and Assignment 5 Extra
Credit is due December 13, 2020 before midnight. Assignment 5 is
worth 4% of your final grade, while Assignment 5 Extra Credit is worth 2
extra percentage points.
Late submissions will not be accepted! So it is suggested that you
submit preliminary Assign 5.hs and Assign 5 Test.hs files well before the
deadline so that your mark is not zero if, e.g., your computer fails at 11:50
PM on December 13.
Although you are allowed to receive help from the instructional
staff and other students, your submitted program must be your
own work. Copying will be treated as academic dishonesty!
1 Background
Using the trapezoidal rule,
is the area of a trapezoid that approximates the area under the graph of f
from xi−1 to xi
. The approximation becomes more accurate as the parameter
n increases in value.
2 Assignment 5
The purpose of this assignment is to create a Haskell module for approximating
the definite integral of a function f : R → R.
2.1 Requirements
1. Download from Avenue Assign5 Project Template.zip which contains
the Stack project files for this assignment. Modify the
Assign 5.hs file in the src folder so that the following requirements
are satisfied. Also put your testing code for this assignment in the
Assign 5 Test.hs file in the test folder.
2. Your name, the date, and “Assignment 5” are in comments at the top
of your file. macid is defined to be your MacID.
3. The file includes a function definiteIntegral of type
Double -> Double -> (Double -> Double) -> Integer -> Double
4. The file includes a function arcsin1 of type Integer -> Double such
using the definiteIntegral function with n partitions.
2
5. The file includes a function piApprox of type Double -> Double that
uses arcsin1 to approximate π where piApprox tol returns a value
pi’ such that
|pi’ − pi| ≤ tol
for the built-in Haskell approximation pi (this should be manageable
for tol ≥ 10−5
).
6. The file includes a function logApprox of type
Double -> Double -> Double such that logApprox x tol approximates
the value of log x by exploiting its definition as a definite
integral, i.e.,
Use the definiteIntegral function, and return the approximation
that uses the smallest number of partitions n such that
|(definiteIntegral 1 x g n)−(definiteIntegral 1 x g (n-1))| ≤ tol.
7. Your file can be imported into GHCi and all of your functions perform
correctly.
2.2 Testing
Include in your file a test plan for all four functions mentioned above. The
test plan must include at least three test cases for each function. Each test
case should have following form:
Function: Name of the function being tested.
Test Case Number: The number of the test case.
Input: Inputs for function.
Expected Output: Expected output for the function.
Actual Output: Actual output for the function.
In addition, your test plan must include at least one QuickCheck case
for each of the four functions. Each QuickCheck case should have following
form:
Function: Name of the function being tested.
Property: Code defining the property to be tested by QuickCheck.
Actual Test Result: Pass or Fail.
The test plan should be at the bottom of your file in a comment region
beginning with a {- line and ending with a -} line. Put your testing code
for this assignment in the Assign 5 Test.hs file in the test folder.
3
3 Background Extra Credit
Monte-Carlo Integration is a technique for computing approximations of
definite integrals relying on random number generation. Recall, a definite
integral
Z b
a
f(x) dx
is the area between the curve of f(x) and the x-axis over the domain a ≤
x ≤ b. Monte-Carlo Integration relies on approximating this area as a ratio
of the area of the smallest rectangle that can encapsulate the curve over
the given domain. Approximating the ratio of this rectangle is done by
generating random sampling points within the rectangle, and counting the
number of points inside the curve (hits) vs the number of points outside of
the curve (misses).
More formally, given a hit function H(x, y), a number of samples N
and a set of randomly generated samples {(xi
, yi) · i ← {1..N}},
Figure 1: Example Sampling of a Quarter Unit Circle
As an example, consider computing the area of the unit circle (circle of
radius 1). To simplify the problem, we’ll compute only the positive/upperright
quadrant. Given the circle has radius 1, the area of the encapsulating
rectangle is 1 × 1 = 1.
Figure 1 shows an example sampling of the unit circle, where hits/misses
are denoted by red/black dots respectively. After simplifying the area of the
4
rectangle to 1,
Generally, a uniform distribution is the simplest distribution to sample
from. However sometimes a different distribution such as the normal
distribution is more appropriate. The Box-Muller transform can be used
to take two uniform distribution samples U1 and U2 on the unit interval
(0, 1) and return a point (Z1, Z2) from a standard normal distribution,
where
Z0 = Rcos(θ) = p
−2lnU1cos(2πU2)
Z1 = Rsin(θ) = p
−2lnU1sin(2πU2)
4 Assignment 5 Extra Credit
The purpose of this assignment is to create a Haskell module for approximating
the definite integral of a function f : R → R in
4.1 Requirements
1. Download from Avenue Assign5 Project Template.zip which contains
the Stack project files for this assignment. Modify the
Assign 5.hs file in the src folder so that the following requirements
are satisfied. Also put your testing code for this assignment in the
Assign 5 Test.hs file in the test folder.
2. Your name, the date, and “Assignment 5” are in comments at the top
of your file. macid is defined to be your MacID.
3. The file includes a function uniformSample2D of type
(Random a,Floating a) => IO (a,a)
that returns a random uniformly distributed point in the IO monad
over the unit interval (0, 1). Hint: the function randomRIO from the
System.Random library returns a single uniformly distributed random
sample. See documentation for System.Random here http://
hackage.haskell.org/package/random-1.1/docs/System-Random.
html)
4. The file includes a function uniformToNorm of type
Floating a => a -> a -> (a,a)
that takes two uniformly distributed samples and transforms them to
a normally distributed sample point using the Box Muller transform
5
5. The file includes a function normalSample2D of type
(Random a, Floating a) => IO (a,a)
that returns a random normally distributed point in the IO monad
voer the unit interval (0, 1)
6. The file includes a function genSamples of type
(Random a, Floating a) => IO (a,a) -> Int -> IO [(a,a)]
that takes a sampling function (i.e uniformSample2D or normalSample2D),
an Integer N and generates a list of N randomly generated samples in
the IO monad
7. The file includes a function monteCarlo2D of type
Floating a => a -> a -> [(a,a)] -> ((a,a) -> Bool) -> a
that (assuming your working in the upper-right positive quadrant of
a coordinate plane) takes xM ax such that the domain of the definite
integral is (0, xM ax), a value yM ax that’s assumed to be the maximum
value of the function over the domain it’s being integrated, a list
of samples and a boolean hit function and returns the Monte-Carlo
Integration approximation.
8. The file includes a function unitCircleHit of type
(Floating a,Ord a) => (a,a) -> Bool
that is the hit function for the unit circle (Hint: H(x, y) as defined in
Section Background)
9. The file includes a function estimatePi of type
IO (Double,Double) -> Int -> IO Double
that uses Monte-Carlo Integration to estimate the value of pi. It takes
a sampling function (i.e uniformSample2D or normalSample2D) and
an Integer N of number of samples to take.Note: the value of pie is the
area of the unit circle (or 4 times the area of the first quadrant of the
unit circle). A uniform distribution should yield a good guess of π at a
sufficiently high N. Interestingly, a normal distribution will generally
half the number hits in the first quadrant, giving a good guess for π
2
10. Your file can be imported into GHCi and all of your functions perform
correctly.
6
4.2 Testing
Include in your file a test plan for uniformSample2D, uniformToNorm,
normalSample2D, genSamples, unitCircleHit. The test plan must should
thoroughly cover critical all critical cases per function. Functions returning
random values need not have specific output listed (i.e can specify range,
property like normally distributed in Expected Output). Each test case
should have following form:
Function: Name of the function being tested.
Test Case Number: The number of the test case.
Input: Inputs for function.
Expected Output: Expected output for the function.
Actual Output: Actual output for the function.
In addition, your test plan must include at least one QuickCheck case
for uniformToNorm and unitCircleHit. Each QuickCheck case should have
following form:
Function: Name of the function being tested.
Property: Code defining the property to be tested by QuickCheck.
Actual Test Result: Pass or Fail.
The test plan should be at the bottom of your file in a comment region
beginning with a {- line and ending with a -} line. Put your testing code
for this assignment in the Assign 5 Test.hs file in the test folder.
7
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
urba6006代写、java/c++编程语...
2024-12-26
代做program、代写python编程语...
2024-12-26
代写dts207tc、sql编程语言代做
2024-12-25
cs209a代做、java程序设计代写
2024-12-25
cs305程序代做、代写python程序...
2024-12-25
代写csc1001、代做python设计程...
2024-12-24
代写practice test preparatio...
2024-12-24
代写bre2031 – environmental...
2024-12-24
代写ece5550: applied kalman ...
2024-12-24
代做conmgnt 7049 – measurem...
2024-12-24
代写ece3700j introduction to...
2024-12-24
代做adad9311 designing the e...
2024-12-24
代做comp5618 - applied cyber...
2024-12-24
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!