bm3plot.m

来自「用matalab开发的随机数生成程序包」· M 代码 · 共 40 行

M
40
字号
function [bmproc] = bm3plot(npoints, sigma)
%
% BM3PLOT Generate and plot a 3-dimensional Brownian motion
%
% [bmproc] = brownian3d(npoints [, sigma])
%
% Inputs: npoints - length of the trajectory 
%         sigma - optional, the norming constant. Default 1.
%
% Outputs: bmproc - npoints x 3 matrix with values of the process

% Authors: R.Gaigalas, I.Kaj
% v1.2 04-Oct-02

  % set default parameter values
  if (nargin==1)
    sigma = 1;
  end

  % generate a 3-dimensional random walk with normally distributed
  % jumps
  bmproc = cumsum([zeros(1, 3); sigma^0.5*randn(npoints-1, 3)]);

  % plot the process 
  % first the trajectory in black
  plot3(bmproc(:, 1), bmproc(:, 2), bmproc(:, 3), 'k');

  % create colour matrices for every point
  p_col = (bmproc-repmat(min(bmproc), npoints, 1))./ ...
	  repmat(max(bmproc)-min(bmproc), npoints, 1);

  % plot the jump points as points in the colour cube
  % to get a "space" feeling 
  hold on;
  scatter3(bmproc(:, 1), bmproc(:, 2), bmproc(:, 3), ...
	   10, p_col, 'filled');
  grid on;
  hold off;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?