Can someone help me create my loops?
Show older comments
[EDIT: 20110723 20:33 CDT - reformat - WDR]
I need help in creating these loops properly. Also, how do you update your M-File after making changes without going to edit-run-config's and then copy & pasting?
%----------------------------------------------------------------
clear , clc ;
E = 1.05; % Per-Unit Voltage
X = 0.75; % Per-Unit Reactance
PF = input(' input Power Factor ');
% PF = 1.0, 0.95 Leading or 0.95 Lagging
% Leading indicates negative phase angle
% Lagging PF Maximum Active Power
Pmaxp = ( PF / ( 1 + sin ( acos ( PF ) ) ) * E ^ 2 / ( 2 * X ))
% Leading PF Maximum Active Power
Pmaxp = ( PF / ( 1 - sin ( acos ( PF ) ) ) * E ^ 2 / ( 2 * X ))
n = 1;
for v = 0 : 0.05 : 2;
v;
Q(n) = - v ^ 2 / X + E * v * PF / X; % Per-Unit Reactive Power
n = n + 1;
end
n=1;
for P = 0 : 0.05 : 2;
P;
V(n) = (E^2/2-Q*X+(E^4/4-X^2*P^2-X*E^2*Q)^0.5)^0.5;
%Per-Unit Voltage
n = n + 1;
end
figure ( 1 );
set (gca, 'FontSize', 12)
plot (V , P), grid on
xlabel ('Real Power [Per-Unit]','FontSize',14);
ylabel ('Voltage [Per-Unit]','FontSize',14);
1 Comment
Jan
on 23 Jul 2011
Please format your code properly. See the "{} code" button and read the "Markup" link on this page.
If you want us to make your loops properly, please describe, why they are not proper in the current version.
Answers (1)
Fangjun Jiang
on 24 Jul 2011
Not sure what do you mean exactly? Do you want to debug your code to make it run? Or do you want to vectorize to eliminate the for-loop?
Tried your code, looks like you need to make changes in two lines.
V(n) = (E^2/2-Q(n)*X+(E^4/4-X^2*P^2-X*E^2*Q(n))^0.5)^0.5;%%change to Q(n)
plot (V , Q), grid on %%probably a typo
Categories
Find more on Mixed-Signal Blockset 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!