Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%% 1d integral: integrate x^2 from 0 to 1
fun = @(x) x^2;
assert(abs((dquad(1,fun) - 1/3)*3)<0.01)
ans =
0.3332
|
2 | Pass |
%% 2d integral from the example
fun = @(x) x(1)*x(2);
assert(abs((dquad(2,fun) - 0.25)*4)<0.01)
ans =
0.2504
|
3 | Pass |
%% constant in most dimensions
fun = @(x) 1+sin(x(1));
assert(abs((dquad(50,fun) - 1.45969769)/1.45969769)<0.01)
ans =
1.4593
|
4 | Pass |
%% volume of d-dimensional 2^d box with a spherical hole, d between 5 and 10
d = randi([5 10],1)
r = rand*0.8
fun = @(x) 2^d*(norm(x)>r);
dball = exp(d/2*log(pi)+d*log(r)-gammaln(d/2+1));
assert(abs((dquad(d,fun) - 2^d+dball)/(2^d-dball))<0.01)
d =
7
r =
0.7585
ans =
127.2768
|
2261 Solvers
64 Solvers
202 Solvers
489 Solvers
Create an n-by-n null matrix and fill with ones certain positions
270 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!