How to create a vector from a "for iteration"
2 views (last 30 days)
Show older comments
I'm creating a code using Gauss-Seidel method. I'd like to create a vector with the answers of the iterations. How can I do that?
My work:
Ybus1 = [3.73-49.72i 0 0 0 -3.73+49.72i];
Ybus2 = [0 2.68-28.46i 0 -0.89+9.92i -1.79+19.84i];
Ybus3 = [0 0 7.46-99.44i -7.46+99.44i 0];
Ybus4 = [0 -0.89+9.92i -7.46+99.44i 11.92-147.96i -3.57+39.68i];
Ybus5 = [-3.73+49.72i -1.79+19.84i 0 -3.57+39.68i 9.09-108.58i];
Ybus = [Ybus1; Ybus2; Ybus3; Ybus4; Ybus5];
Vi = [1;1;1.05;1;1];
pk = [0 -8 4.4 0 0];
qk = [0 -2.8 0 0 0];
%% ********Gauss-Seidel********
N = size(Ybus,1);
for k = 2:N;
Vk = Vi(k);
S1 = 0;
S2 = 0;
F1 = Ybus(k,k);
for n = 1:k-1
S1 = S1 + (Ybus(k,n))*(Vi(n));
end
for n = k+1:N
S2 = S2 +(Ybus(k,n))*(Vi(n));
end
for iter = 1:100
F2 = (pk(k)-(qk(k)*1i))/conj(Vk);
Vk = (F2-S1-S2)/F1
end
end
0 Comments
Answers (1)
Star Strider
on 25 Aug 2020
Subscript them appropriately:
for iter = 1:100
F2(k,iter) = (pk(k)-(qk(k)*1i))/conj(Vk);
Vk(k,iter) = (F2-S1-S2)/F1
end
I’m not certain what you want to do, so it may be necessary for you to change the subscripts get the result you want. However that’s the general approach.
2 Comments
Star Strider
on 25 Aug 2020
My code produces a matrix where the rows are over ‘k’ and the columns are over ‘iter’. My code will do what you want. You simply need to address the matrix correctly to get the result you want.
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!