Can any body help me to form a full matrix which is having sub matrices.And these sub matrices are similar to each other. I have used counter to repeat the same calculation. where i is varying row wise and similarly k is varying column wise.

row1=1;row2=2;lo1=1;lo2=2;
for i=1:3 (when i=1 it will evaluate the first block matrix, similarly when i=2...)
row1=row1+2;row2=row2+2;lo1=lo1+2;lo2=lo2+2;
for k=4:9
D5(row1,lo1)= - V(i)*V(k)*abs(Y(i,k))*sin(Th(i)-Th(k)-angle(Y(i,k)));
D5(row1,lo2)= - V(i)*abs(Y(i,k))*cos(Th(i)-Th(k)-angle(Y(i,k)));
D5(row2,lo1)= V(i)*V(k)*abs(Y(i,k))*cos(Th(i)-Th(k)-angle(Y(i,k)));
D5(row2,lo2)= - V(i)*abs(Y(i,k))*sin(Th(i)-Th(k)-angle(Y(i,k)));
end
end

3 Comments

What do you need help with? Does this code give you the result you want or not? Are you looking for improvements or corrections?
I am not getting the proper answer for it....so can you please help me out to generalize
Actually this coding is calculating the first sub matrix...and the counters are to repeat the same for i=1...n ....like wise for the values of k...can you please help me out regarding this

Sign in to comment.

 Accepted Answer

As k is varied, D5 is written at the same positions repeatedly from k equal to 4 to k equal to 9. Only the final one will remain in effect. My guess is that you actually want to do something like this:
for i = 1:3
for k = 4:9
D5(2*i-1,2*k-7) = ...
D5(2*i-1,2*k-6) = ...
D5(2*i,2*k-7) = ...
D5(2*i,2*k-6) = ...
In other words let i and k determine where D5 is to receive inputs, and not by using the variables, row1, row2, lo1, etc.
Note that this is just a guess. You need to specify more precisely just what it is you wish to accomplish.

More Answers (1)

Thanks for the effort..
Suppose i is 3 , 4 , 5 it can be any similarly for k...
Suppose type=1 , 2 , 3 ... and i is 1:n , now I need when type ==3 then only it will calculate the 1st sub matrix...and this type==3 are in position i= 3, 4 , 5....similarly for k
The code
For i=1:n For k=1:n If type(i)==3 && type (k)==2 D5 ()=
End
How can I develope this? Pls help me out

1 Comment

As I see it, Prasenjit, you have two problems, the first being to determine the locations in vectors V and Th and matrix Y to be used in the computations of D5 values, and the second being just where to store those results. If these proceed in a regular fashion with blocks packed adjacent to one another in a rectangular pattern, as I speculated in my answer, you can use the i and k quantities in the for-loops to determine both of these. On the other hand if one or the other of these locations is irregular in some respect, requiring some kind of "type" vector, then you can compute the needed indices directly from type(i) or type(k). If at all possible, you should avoid the method you wrote:
If type(i)==3 && type (k)==2
as this may lead to very cumbersome, ugly coding.
If my response seems vague, it is because I do not fully understand what it is you are trying to do. It might help if you could give a simple example of the desired arrangement of D5 value blocks in what you called "submatrices".

Sign in to comment.

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!