Can someone help me create my loops?

[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

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.

Sign in to comment.

Answers (1)

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

1 Comment

Thanks. It's actually supposed to be a PV curve. I recognize now I can't plot with just the "for" P part versus the V(n) and I'm going to try to add an equation for that.

Sign in to comment.

Categories

Find more on Mixed-Signal Blockset in Help Center and File Exchange

Asked:

on 23 Jul 2011

Community Treasure Hunt

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

Start Hunting!