gbmSim 接受两个输入项 mu 和 sigma,并返回四个输出项,分别为 m、mtrue、s 和 strue。
定义表 params,其中包含要输入到布朗运动模型中的参数。
mu = [-.5; -.25; 0; .25; .5];
sigma = [.1; .2; .3; .2; .1];
params = table(mu,sigma)
params =
5x2 table
mu sigma
_____ _____
-0.5 0.1
-0.25 0.2
0 0.3
0.25 0.2
0.5 0.1
将函数 gbmSim 应用于表 params 的各行。
stats = rowfun(@gbmSim,params,...
'OutputVariableNames',...
{'simulatedMean' 'trueMean' 'simulatedStd' 'trueStd'})
stats =
5x4 table
simulatedMean trueMean simulatedStd trueStd
_____________ ________ ____________ ________
0.60501 0.60653 0.05808 0.060805
0.77916 0.7788 0.161 0.15733
1.0024 1 0.3048 0.30688
1.2795 1.284 0.25851 0.25939
1.6498 1.6487 0.16285 0.16529
'OutputVariableNames' 名称-值对组参数指定的四个变量名称指示 rowfun 应从 gbmSim 获取四个输出。您可以指定较少的输出变量名称以从 gbmSim 返回较少的输出项。
将函数输出 stats 追加到输入 params 的末尾。
[params stats]
ans =
5x6 table
mu sigma simulatedMean trueMean simulatedStd trueStd
_____ _____ _____________ ________ ____________ ________
-0.5 0.1 0.60501 0.60653 0.05808 0.060805
-0.25 0.2 0.77916 0.7788 0.161 0.15733
0 0.3 1.0024 1 0.3048 0.30688
0.25 0.2 1.2795 1.284 0.25851 0.25939
0.5 0.1 1.6498 1.6487 0.16285 0.16529