How can I use Matlab to evaluate ∫10∫10∫101(xyz)xyz dx dy dz?
I was struggling with my MATLAB Assignment help and then a good friend told me about MatlabSolutions.com website and they gave me the best Assignment help ever. I hope to always count on the quality and efficiency of your services.
Numerical approach: sample
Two methods have been suggested here for the numerical approach, regular sampling and random sampling.
In many cases, however, semi-random sampling has superior convergence.
The problem of regular grid sampling, is that you sample at fixed spatial frequencies, risking under/oversampling of important frequencies.
The problem of random sampling, is that you could easily under/oversample important regions by chance.
A better approach is semi-random sampling, in which the sampled points are globally more uniformly distributed.
In this example, I chose to sample near each point in the regular grid, however, the relative distance to this gridpoint was varied. In each dimension I randomly selected the deviation from the a uniform distribution on the interval [-1/2*d, 1/2*d] in which d is the distance between the regular gridpoints.
In the figure below it is seen how semi-random sampling (blue line) converges faster than random sampling (red line) or regular sampling (green line).
Semi random sampling (blue line) converges faster than random sampling (red line) or regular sampling (green line). The horizontal axis (N) represents the number of gridpoints in each dimension, leading to N³ sampled points. (Also N³ samples for random sampling).
Same figure, but now for ten simulations.
%% MATLAB CODE:
Nseries = 50:50:400;
results = zeros(3, length(Nseries));
for m = 1:length(Nseries)
N = Nseries(m);
% Random sampling
xyz = rand(1,N³).*rand(1,N³).*rand(1,N³);
results(1, m) = mean(1./xyz.^xyz);
% Regular sampling
gridPoints_1D = linspace(1/(2*N),1–1/(2*N),N);
[x,y,z] = meshgrid(gridPoints_1D);
% on exact grid nodes:
xyz = x(:).*y(:).*z(:);
results(2, m) = mean(1./xyz.^xyz);
% near grid nodes, random deviation:
x = x + (rand(size(x))-0.5)/N;
y = y + (rand(size(x))-0.5)/N;
z = z + (rand(size(x))-0.5)/N;
xyz = x(:).*y(:).*z(:);
results(3, m) = mean(1./xyz.^xyz);
end
figure;
semilogx(Nseries, results(1,:), ‘r’); hold on;
semilogx(Nseries, results(2,:), ‘g’);
semilogx(Nseries, results(3,:), ‘b’);