my @realval = (
0.994704478,
0.989459074,
0.994717023,
1.000000000,
1.000000000,
0.002647761,
0.005282977,
0.000882587,
0.005270463,
0.000882587,
0.002635231,
0.000882587,
0.002635231,);
my @row_index = qw( 1 2 3 4 5 1 3 1 2 1 2 1 2);
my @col_index = qw(1 2 3 4 5 5 3 2 1 3 3 4 4);
my @mat_dim = (5,5); # M always equal to N
####
my @actual_mat = (
[ 0.994704478, 0.000882587, 0.000882587, 0.000882587, 0.002647761],
[ 0.005270463, 0.989459074, 0.002635231, 0.002635231, 0.000000000],
[ 0.000000000, 0.000000000, 0.005282977, 0.000000000, 0.000000000].
[ 0.000000000, 0.000000000, 0.000000000, 1.000000000, 0.000000000],
[ 0.000000000, 0.000000000, 0.000000000, 0.000000000, 1.000000000]
);
# It is simply done by assigning the value in @real_value given
# the corresponding (@row,@index) as coordinate;
# e.g. to assign $real_value[-1] into
# $actual_mat[$row_index[-1]-1,$col_index[-1]-1);
####
my @p = (0.4,0.2,0.2,0.2,0.2);
####
my $result = [
0.3989409,
0.2010541,
0.2000000,
0.2000000,
0.2000000,
];