Open in the MATLAB editor: g05xb_example
function g05xb_example fprintf('g05xb example results\n\n'); % Get information required to set up the bridge [bgord,t0,tend,ntimes,intime,nmove,move] = get_bridge_init_data(); % Make the bridge construction bgord [times, ifail] = g05xe( ... t0, tend, intime, move, 'bgord', bgord); % Initialize the Brownian bridge generator [rcomm, ifail] = g05xa( ... t0, tend, times); % Get additional information required by the bridge generator [npaths, d, start, term, c] = get_bridge_gen_data(); % Generate the Z values [z] = get_z(npaths, d, ntimes); % Call the Brownian bridge generator routine [z, b, ifail] = g05xb( ... npaths, start, term, z, c, rcomm); % Display the results for i = 1:npaths fprintf('Weiner Path %d, %d time steps, %d dimensions\n', i, ntimes+1, d); w = transpose(reshape(b(:,i), d, ntimes+1)); ifail = x04ca('G', ' ', w, ''); fprintf('\n'); end function [bgord,t0,tend,ntimes,intime,nmove,move] = get_bridge_init_data() % Set the basic parameters for a Wiener process t0 = 0; n = 10; ntimes = int64(n); % We want to generate the Wiener process at these time points intime = 1:n + t0; tend = t0 + n + 1; nmove= int64(0); move = zeros(nmove, 1, 'int64'); bgord = int64(3); function [npaths,d,start,term,c] = get_bridge_gen_data(); % Set the basic parameters for a non-free Wiener process npaths = int64(2); d = 3; start = zeros(d, 1); term = [1, 0.5, 0]; % We want the following covariance matrix c = [ 6, 1, -0.2; 1, 5, 0.3; -0.2, 0.3, 4]; % Cholesky factorize the covariance matrix c [c, info] = f07fd('l', c); function [z] = get_z(npaths, d, ntimes) % Non-free Wiener process (the default) a = int64(1); idim = d*(ntimes+1-a); % We now need to generate the input pseudorandom points % First initialize the base pseudorandom number generator state = initialize_prng(int64(6), int64(0), [int64(1023401)]); % Scrambled quasi-random sequences preserve the good discrepancy % properties of quasi-random sequences while counteracting the bias % some applications experience when using quasi-random sequences. % Initialize the scrambled quasi-random generator. [iref, state] = initialize_scrambled_qrng(int64(1), int64(2), ... idim, state); % Generate the quasi-random points from N(0,1) xmean = zeros(idim, 1); std = ones(idim, 1); [z, iref, ifail] = g05yj( ... xmean, std, npaths, iref); z = z'; function [state] = initialize_prng(genid, subid, seed) % Initialize the generator to a repeatable sequence [state, ifail] = g05kf( ... genid, subid, seed); function [iref, state] = initialize_scrambled_qrng(genid,stype,idim,state) iskip = int64(0); nsdigits = int64(32); [iref, state, ifail] = g05yn( ... genid, stype, int64(idim), iskip, ... nsdigits, state);
g05xb example results Weiner Path 1, 11 time steps, 3 dimensions 1 2 3 1 -1.0602 -2.8701 -0.9415 2 -3.0575 -1.9502 0.2596 3 -6.8274 -2.4434 0.4597 4 -5.2855 -3.4475 0.0795 5 -8.1784 -5.2296 -0.0921 6 -4.6874 -5.0220 1.4862 7 -3.0959 -4.8623 -4.4076 8 -2.9605 -1.8936 -3.9539 9 -5.4685 -2.3856 -3.2031 10 0.1205 -5.0520 -1.0385 11 1.0000 0.5000 0.0000 Weiner Path 2, 11 time steps, 3 dimensions 1 2 3 1 0.6564 3.5142 1.5911 2 -2.3773 3.1618 3.0316 3 0.3020 6.8815 2.0875 4 -0.2169 4.6026 1.1982 5 -2.0684 4.1503 2.4758 6 -5.1075 3.7303 2.7563 7 -3.8497 3.6682 2.4827 8 -1.8292 4.4153 0.1916 9 -2.0649 0.6952 -2.1201 10 0.1962 1.7769 -5.7685 11 1.0000 0.5000 0.0000