我希望创建两个单独的矩阵,在一个创建两个输出的函数上使用for循环。 看起来有点像这样:
% prepare output matrixes
output1=zeros(size(input2),1) % corresponds to a vector of length n of the nodes (bank capital
levels in this case)
output2=zeros(size(input2)) % corresponds to an adj matrix of size n
input2=[100,200,300 ... ] % corresponds to a vector of length n with capital levels.
input1=1:length(input2); % correspounds to vector of [1:n] of individual banks to trigger each
bank's default in the model, so [1,2,3,4,5]
% input3 is an nxn adjacency matrix of directed exposures (with 0 along the
% main diagonal)
input3=[0,2190,7708,39034,32088,19584,18694,9923,513,14221; ... ]; %continues much longer ]
input4=0.8 % Loss Given Default (LGD
input5=0.4 % loss % of funding fraction from interbank lending
input6=0.4 % loss % from asset fire sales
for j=1:input1
[output1 output2] = function(input1, input2, input3, input4, input5,input6)
output_matrix(j)=[output1(j) output2(j)]
end
以上是我失败的尝试。这是一个手动创建的整个事物的较小版本。
input3 = ...
[70000, 15000, 24000, 52453;
23420, 24252, 10000, 35354;
98763, 45666, 96555, 05000;
09800, 54444, 04336, 67520]; % interbank loans in the function
input1 = 3; % default_bank
input2=[100000;200000;300000;400000]; % capital levels in the function
input4 = 1;
input5 = .35;
input6 = 1;
% function calls on above inputs
[capital_losses defaulted_banks] = interbank_model( ...
input1, input2, input3, input4, input5, input6)
% this is the standard output for one iteration with default_bank=3, but I need this for 300+, so a loop would be helpful...
capital_losses3 =
1.0e+05 *
0.5857
0.2598
3.0000
0.0609
defaulted_banks3 =
0
0
1
0
我想获得每个违约银行的输出,即 要由for循环显示default_bank = 1:4,如下所示:
capital_losses_all =
1.0e+05 *
1.0000 0.2320 0.5857 0.5857
0.2867 2.0000 0.2598 0.2598
1.0716 0.4917 3.0000 3.0000
0.2816 0.6682 0.0609 0.0609
defaulted_banks_all =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
我找到的每一种方式都可以循环通过默认的不同库,也就是说,通过输入1:n,旧向量被前一个被覆盖了n次。我想生成一个output1矩阵,其中迭代被连接以评估每个j,并且对于j的每个值,输出2都是相同的,如上面的4x4示例所示... 我假设有一个简单的答案,非常感谢任何指针。谢谢, 克里斯托弗