How to write the intermediate result of a for loop in array, at each iteration?

0

below is the attempt to code to calculate the following situation:

  • I have two vectors: "q_qp" and "pe", I need each element of the "pe" vector to multiply all elements of "q_qp", for example: the value of 9.528007810207796E-5 of "pe" multiplies all values of "q_qp" and returns me a resulting vector in the same dimension of "q_qp" (33 x 1), and so on until the last value of "pe".

As the dimension of "pe" is 22 x 1 and "q_qp" is 33 x 1, I will have 22 column vectors of 33 rows at the end of the loop.

The question is, how can I do so that with each iteration the result is written in an ordered way in a matrix of zeros with dimension of 33 x 22, ie first iteration records the vector in the first column, second iteration vector in the second column, and so on. I'm using scilab and I was able to generate the vectors with the loop, but I can not write the result in the array in any way. If anyone can help me, I'll be very grateful.

clc
clear

q_qp= [0 0.03 0.1 0.19 0.31 0.47 0.66 0.82 0.93 0.99 1 0.99 0.93 0.86 0.78 0.68 0.56 0.46 0.39 0.33 0.28 0.207 0.147 0.107 0.077 0.055 0.04 0.029 0.021 0.015 0.011 0.005 0]' 

pe= [9.528007810207796E-5
0.015612153888687455
0.04127114106369897
0.06865675895676779
0.10234219137829395
0.149156938574736
0.2221660433295402
0.3516835634365342
0.6253621948431046
0.9021458528207191
2.49812553600102
1.4110166279515943
0.47462270737544116
0.2936798150556328
0.2010333119231717
0.1471011647128549
0.1128517315033946
0.08968709798222249
0.07325270551003342
0.06114745114515898
0.0]

[l c]= size(pe)
Q1= zeros(33, l)
[la ca]= size(Q1)

for i= 1:l
    for j= 1:c

        a= pe(i ,1)
        disp(a)
        Q= a .* q_qp
        disp(Q)
        B(i)= [Q(i)] ***>>> Aqui eu gostaria que B recebesse o cálculo da primeira iteração na primeira coluna da matriz, na segunda iteração o vetor fosse gravado na segunda coluna da matriz B, e assim sucessivamente até completar o for.*** 
    end

    for m= 1:la  ***>>> esse segundo for foi uma tentativa de gravar os vetores na matriz, mas não deu certo. ele grava somente o resultado da última iteração, ou seja a multiplicação entre o último valor de "pe" e o vetor "q_qp".*** 
        for n= 1:ca
            Q2(m, n)= [Q(i)] 
        end
    end
end
    
asked by anonymous 04.11.2014 / 23:42

1 answer

1

In MatLab, the following syntax is used ( I imagine that in scilab it should not be very different ):

outputMatrix = zeros(33, 22);
for i = 1:22
    scaledVector = pe(i)*q_qp;
    outputMatrix(:, i) = scaledVector';
end        

Note that a scaledVector vector was used as the intermediate step to transpose the result. Failure to do so would cause a dimension compatibility error. But this step can be suppressed if the language directly accepts the outputMatrix(:, i) = pe(i)*q_qp' command.

    
05.11.2014 / 12:11