montecarlo.m
来自「斯坦福大学Grant和Boyd教授等开发的凸优化matlab工具箱」· M 代码 · 共 23 行
M
23 行
function prob = montecarlo(A,b,Sigma,notrials);% estimates probability than random vector x in R2% with mean zero and covariance Sigma satisfies Ax <= b%% Sigma must be postive definite%% based on 100*notrials trialsrandn('state',0);m = size(A,1);R = chol(Sigma); % Y = R^{-T}X has covariance IX = R'*randn(2,notrials);prob = length(find(sum(A*X - b(:,ones(1,notrials)) < 0) == m))/notrials;for i=1:99X = R'*randn(2,notrials);prob = 0.5*(prob + ... length(find(sum(A*X - b(:,ones(1,notrials)) < 0) == m))/notrials);end;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?