【电力系统】两节点电力系统的高斯 - 赛德尔(Gauss-Seidel)潮流计算MATLAB代码,求解电力网络中 PQ 节点(母线 2)的电压幅值和相角

简介: ✅作者简介:热爱科研的Matlab仿真开发者,擅长数据处理、建模仿真、程序设计、完整代码获取、论文复现及科研仿真。🍎 往期回顾关注个人主页:Matlab科研工作室 👇 关注我领取海量matlab电子书和数学建模资料 🍊个人信条:格物致知,完整Matlab代码获取及仿真咨询内容私信。🔥 内容介绍 一、引言:潮流计算的核心意义与高斯 - 赛德尔算法的价值1.1 潮流计算:电力系统分析的 “基石”潮流计算是电力系统规划、运行与控制的核心基础,其本质是求解电力网络的稳态运行状态 —— 通过已知的负荷、电源参数,计算各母线的电压幅值、相角,以及线路功率流向与损耗。无论是电网

✅作者简介:热爱科研的Matlab仿真开发者,擅长数据处理、建模仿真、程序设计、完整代码获取、论文复现及科研仿真。

🍎 往期回顾关注个人主页:Matlab科研工作室

👇 关注我领取海量matlab电子书和数学建模资料

🍊个人信条:格物致知,完整Matlab代码获取及仿真咨询内容私信。

🔥 内容介绍
一、引言:潮流计算的核心意义与高斯 - 赛德尔算法的价值
1.1 潮流计算:电力系统分析的 “基石”
潮流计算是电力系统规划、运行与控制的核心基础,其本质是求解电力网络的稳态运行状态 —— 通过已知的负荷、电源参数,计算各母线的电压幅值、相角,以及线路功率流向与损耗。无论是电网扩容规划、新能源接入评估,还是调度运行中的安全校验,都离不开潮流计算的支撑。

1.2 两节点系统:潮流计算的 “入门模型”
两节点电力系统是最简单的电力网络拓扑(含 1 个平衡节点、1 个 PQ 节点),虽结构简单,但能直观体现潮流计算的核心逻辑。本文聚焦两节点系统,采用经典的高斯 - 赛德尔(Gauss-Seidel)迭代法,手把手演示 PQ 节点(未知电压幅值和相角)的求解过程,帮助读者快速掌握潮流计算的核心思路。

1.3 高斯 - 赛德尔算法:迭代法的 “经典代表”
高斯 - 赛德尔算法是潮流计算中最基础的迭代算法,核心优势是原理简单、计算量小、易实现—— 基于节点功率平衡方程,通过逐次迭代更新未知节点电压,直至满足收敛条件。虽收敛速度慢于牛顿 - 拉夫逊法,但对于简单系统(如两节点、三节点),是理解潮流计算本质的最佳切入点。

二、核心原理:两节点系统建模与高斯 - 赛德尔迭代公式
2.1 两节点系统拓扑与参数定义
2.1.1 系统结构
两节点系统由母线 1(平衡节点) 、母线 2(PQ 节点) 及连接线路组成,结构如下:

平衡节点(母线 1):电压幅值 V₁和相角 θ₁已知(通常设为 V₁=1.0∠0° pu,作为电压参考点),承担平衡系统功率损耗的角色;

PQ 节点(母线 2):注入有功功率 P₂、无功功率 Q₂已知(由负荷或电源决定),需求解电压幅值 V₂和相角 θ₂;

线路参数:线路阻抗 Z=R+jX(或导纳 Y=G+jB=1/Z,B 为线路电纳,忽略时 Y=G+j0)。

2.1.2 节点导纳矩阵(Y 矩阵)
两节点系统的节点导纳矩阵为 2×2 矩阵,核心是描述节点间的电气连接关系:

Image

Image

⛳️ 运行结果
Image

Image

📣 部分代码
%---------Initial settings-----------

clc;

clear;

close all

Convergence_Tolerance=1e-6; %Newton Raphon Convergence Tolerance

disp(['Convergence Tolerance, Ep:',num2str(Convergence_Tolerance)]);

%-----------------Node, tributary data---------------

% Node data

node = ...

[...

    1 3 0        0.065      0     0     1.06      0       0

    2 1 1.82    0.64       0     0       1       0       0

  ];

% Matrix formed by node data: column 1 node number, column 2 node type:1 - PQ 2 - PV 3 - balance

% column 3 load active, column 4 load reactive, column 5 generation active, column 6 generation reactive

% column 7 voltage real, column 8 voltage imaginary

% column 9 node-to-ground conductance

% Branch data

branch = ...

[...

%bus_i %bus_j % R % X % Bi/2 % k

1 2 0 0.034 0 1;

];

% bus_i denotes the first node of a branch.

% bus_j denotes the end node of the branch.

% R and X denote the branch resistance and reactance, respectively, and B denotes the dana.

% k denotes the transformer ratio of the first node to the last node.

n=size(node,1); %Number of nodes

l=size(branch,1); %Number of branches

%%--------------------------------------

%Calculating the nodal derivative matrix

%%--------------------------------------

Y=zeros(n); %Calculating the nodal conductance matrix

for j=1:l

s1=branch(j,1);s2=branch(j,2);  %s1 is the first segment node of each branch and s2 is the end node

kij=branch(j,6); %Branch transformer ratio

Y(s1,s2)=-1/( (branch(j,3)+1i*branch(j,4))*kij );

Y(s2,s1)=Y(s1,s2);

Y(s1,s1)=Y(s1,s1)+1/( (branch(j,3)+1i*branch(j,4))*kij^2 )+i*branch(j,5);  

Y(s2,s2)=Y(s2,s2)+1/(branch(j,3)+1i*branch(j,4))+i*branch(j,5);  

end

for a=1:n %--Calculation of conductivity to earth--

Y(a,a)=Y(a,a)+1i*node(a,9);

end

G=real(Y); %Nodal derivative matrix real part matrix

B=imag(Y); %Nodal derivative matrix imaginary part matrix

%%Newton Raphon method of calculating currents

e=node(:,7); %Initial value of the real part of the voltage

f=zeros(n,1); %Initial value of the imaginary part of the voltage

for a=1:n %Search to balance nodes

if node(a,2)==3

    slack=a;

end

end

it=0; %Number of iterations

Convergence=[];

while 1

DP=zeros(n,1); DQ=zeros(n,1); %Uneven measurement

Pi=zeros(n,1); Qi=zeros(n,1); %Nodal injected power calculated by the tidal equation

for a=1:n %Calculating Pi, Qi

   if node(a,2)==1 || node(a,2)==3 %Determined to be a PQ node

      for b=1:n

          Pi(a,1)=Pi(a,1)+e(a,1)*( G(a,b)*e(b,1)-B(a,b)*f(b,1) )+ f(a,1)*( G(a,b)*f(b,1)+B(a,b)*e(b,1) );

          Qi(a,1)=Qi(a,1)+f(a,1)*( G(a,b)*e(b,1)-B(a,b)*f(b,1) )- e(a,1)*( G(a,b)*f(b,1)+B(a,b)*e(b,1) );

      end

      DP(a,1)=( node(a,5)-node(a,3) )-Pi(a,1);  %Calculating unevenness

      DQ(a,1)=( node(a,6)-node(a,4) )-Qi(a,1);

   elseif node(a,2)==2  %Determined to be a PV node

       for b=1:n

          Pi(a,1)=Pi(a,1)+e(a,1)*( G(a,b)*e(b,1)-B(a,b)*f(b,1) )+ f(a,1)*( G(a,b)*f(b,1)+B(a,b)*e(b,1) );

          Qi(a,1)=e(a,1)^2+f(a,1)^2;

       end

      DP(a,1)=( node(a,5)-node(a,3) )-Pi(a,1);

      DQ(a,1)=node(a,7)^2-Qi(a,1);  %PV node voltage imbalance

   end  %Balance nodes regardless of

end

DPQ=zeros(2*n,1); %Integration of active, reactive and voltage inequalities into one matrix

for a=1:n

   DPQ(2*a-1,1)=DP(a,1);

   DPQ(2*a,1)=DQ(a,1);

end

DPQ([2slack-1,2slack],:)=[]; % The slack node is a balancing node and does not participate in iterations, remove

xV=zeros(n,1);   %Node voltage amplitude

xR=zeros(n,1);   %Node voltage phase angle

for a=1:n

   xV(a,1)=sqrt( e(a,1)^2+f(a,1)^2 );

   xR(a,1)=atan(f(a,1)/e(a,1))*180/pi;

end

disp(['Number of iteration:',num2str(it),' Max(|DP|,|DQ|):',num2str(max(abs(DPQ))),' Voltage Magnitude at bus 2:',num2str(xV(2,1)),' Voltage Angle at bus 2:',num2str(xR(2,1))]);

%If the inequality is less than the convergence accuracy, then the convergence condition has been reached and the iteration is skipped

Convergence=[Convergence;max(abs(DPQ))];

if max(abs(DPQ))<=Convergence_Tolerance

   break;

end

%If accuracy is achieved, the Jacobi matrix and corrections are calculated downwards and the iteration continues

H=zeros(n,n);  % Calculation of DP/De

N=zeros(n,n);  % Calculation of DP/Df

K=zeros(n,n);  % Calculate DQ/De for the PQ node and DU/De for the PV node

L=zeros(n,n);  % Calculate DQ/Df for the PQ node and DU/Df for the PV node

for a=1:n

   if node(a,2)==1 %Determined to be a PQ node

       for b=1:n

           if a~=b 

               H(a,b)=-( G(a,b)*e(a,1)+B(a,b)*f(a,1) );

               N(a,b)=B(a,b)*e(a,1)-G(a,b)*f(a,1) ;

               K(a,b)=B(a,b)*e(a,1)-G(a,b)*f(a,1) ;

               L(a,b)=G(a,b)*e(a,1)+B(a,b)*f(a,1) ;

           elseif a==b

               for c=1:n

                  H(a,b)=H(a,b)-( G(a,c)*e(c,1)-B(a,c)*f(c,1) ); 

                  N(a,b)=N(a,b)-( G(a,c)*f(c,1)+B(a,c)*e(c,1) );

                  K(a,b)=K(a,b)+( G(a,c)*f(c,1)+B(a,c)*e(c,1) );

                  L(a,b)=L(a,b)-( G(a,c)*e(c,1)-B(a,c)*f(c,1) );

               end

               H(a,b)=H(a,b)-G(a,a)*e(a,1)-B(a,a)*f(a,1);

               N(a,b)=N(a,b)+B(a,a)*e(a,1)-G(a,a)*f(a,1);

               K(a,b)=K(a,b)+B(a,a)*e(a,1)-G(a,a)*f(a,1);

               L(a,b)=L(a,b)+G(a,a)*e(a,1)+B(a,a)*f(a,1);

           end

       end

   elseif node(a,2)==2 %Determined to be a PV node

       for b=1:n

           if a~=b 

               H(a,b)=-( G(a,b)*e(a,1)+B(a,b)*f(a,1) );

               N(a,b)=B(a,b)*e(a,1)-G(a,b)*f(a,1) ;

               K(a,b)=0 ; 

               L(a,b)=0 ;

           elseif a==b

               for c=1:n

                  H(a,b)=H(a,b)-( G(a,c)*e(c,1)-B(a,c)*f(c,1) ); 

                  N(a,b)=N(a,b)-( G(a,c)*f(c,1)+B(a,c)*e(c,1) );

               end

               H(a,b)=H(a,b)-G(a,a)*e(a,1)-B(a,a)*f(a,1);

               N(a,b)=N(a,b)+B(a,a)*e(a,1)-G(a,a)*f(a,1);

               K(a,b)=-2*e(a,1); 

               L(a,b)=-2*f(a,1);

           end

       end

   end  %Balance nodes regardless of

end

jacobi=zeros(2*n); %Jacobi Matrix

for a=1:n

    for b=1:n

       jacobi(2*a-1,2*b-1)=H(a,b);

       jacobi(2*a-1,2*b)=N(a,b);

       jacobi(2*a,2*b-1)=K(a,b);

       jacobi(2*a,2*b)=L(a,b);

    end

end

jacobi([2*slack-1,2*slack],:)=[]; jacobi(:,[2*slack-1,2*slack])=[]; % The slack node is a balancing node and does not participate in iterations, remove



delt=-jacobi\DPQ;    %Calculation of corrections to variables



%Balance node (node with slack number) with e and f corrections of 0

if slack==1

    delt=[0;0;delt];

elseif slack==n

    delt=[delt;0;0];

else

    delt1=delt(1:2*slack-2,:);

    delt2=delt(2*slack-1:2*n-2,:);

    delt=[delt1;0;0;delt2];

end





for a=1:n

    e(a,1)=e(a,1)+delt(2*a-1,1);

    f(a,1)=f(a,1)+delt(2*a,1);

end





it=it+1; %Number of iterations

end

Pi=zeros(n,1); Qi=zeros(n,1);

for a=1:n %Calculating Pi, Qi

for b=1:n

    Pi(a,1)=Pi(a,1)+e(a,1)*( G(a,b)*e(b,1)-B(a,b)*f(b,1) )+ f(a,1)*( G(a,b)*f(b,1)+B(a,b)*e(b,1) );

    Qi(a,1)=Qi(a,1)+f(a,1)*( G(a,b)*e(b,1)-B(a,b)*f(b,1) )- e(a,1)*( G(a,b)*f(b,1)+B(a,b)*e(b,1) );

end

end

disp(['Active Power Injection at bus 2:',num2str(Pi(2,1)),' Reactive Power Injection at bus 2:',num2str(Qi(2,1))]);

figure(1);

k=1:it+1;

plot(k-1,Convergence(k,1),'-b'),xlabel('k'),ylabel('Convergence Tolerance'); hold on;

🔗 参考文献
[1]涂志军,曹晔,李伟,等.一种新型高斯塞德尔算法在电力系统潮流计算中的应用研究[J].江西科学, 2010, 28(6):4.DOI:10.3969/j.issn.1001-3679.2010.06.024.

图片
🏆团队擅长辅导定制多种科研领域MATLAB仿真,助力科研梦:

相关文章
|
3月前
|
人工智能 安全 调度
AI工程vs传统工程 —「道法术」中的变与不变
本文从“道、法、术”三个层面对比AI工程与传统软件工程的异同,指出AI工程并非推倒重来,而是在传统工程坚实基础上,为应对大模型带来的不确定性(如概率性输出、幻觉、高延迟等)所进行的架构升级:在“道”上,从追求绝对正确转向管理概率预期;在“法”上,延续分层解耦、高可用等原则,但建模重心转向上下文工程与不确定性边界控制;在“术”上,融合传统工程基本功与AI新工具(如Context Engineering、轨迹可视化、多维评估体系),最终以确定性架构驾驭不确定性智能,实现可靠价值交付。
613 41
AI工程vs传统工程 —「道法术」中的变与不变
|
2月前
|
JSON 安全 测试技术
别再只用 `net/http` 了!Go 高并发场景的“涡轮增压”方案:`fasthttp`
`fasthttp` 是由 Valyala 开发的高性能 HTTP 引擎,专为高吞吐、低延迟、低内存场景优化。相比 `net/http`,它快 6 倍+、零堆分配、支持百万级连接,适合 API 网关、实时服务等场景,但仅支持 HTTP/1.1。(239 字)
|
3月前
|
存储 数据采集 弹性计算
面向多租户云的 IO 智能诊断:从异常发现到分钟级定位
当 iowait 暴涨、IO 延迟飙升时,你是否还在手忙脚乱翻日志?阿里云 IO 一键诊断基于动态阈值模型与智能采集机制,实现异常秒级感知、现场自动抓取、根因结构化输出,让每一次 IO 波动都有据可查,真正实现从“被动响应”到“主动洞察”的跃迁。
405 77
|
3月前
|
人工智能 运维 前端开发
阿里云百炼高代码应用全新升级
阿里云百炼高代码应用全新升级,支持界面化代码提交、一键模板创建及Pipeline流水线部署,全面兼容FC与网关多Region生产环境。开放构建日志与可观测能力,新增高中低代码Demo与AgentIdentity最佳实践,支持前端聊天体验与调试。
573 52
|
2月前
|
机器学习/深度学习 存储 人工智能
让 AI 智能体学会自我进化:Agent Lightning 实战入门
Agent Lightning 是一个框架无关的强化学习包装层,赋能现有AI智能体实现在线持续学习。它解耦执行与训练,支持LangChain/AutoGen等任意框架,通过VERL算法解决稀疏奖励难题,让智能体从运行反馈中自动优化提示词与策略。
277 5
让 AI 智能体学会自我进化:Agent Lightning 实战入门
|
11月前
|
运维 网络协议 数据可视化
流量实时分析软件的核心价值与实战指南
流量实时分析软件是网络运维与安全的必备工具,被誉为网络的“千里眼”。它通过捕获、解析并可视化网络流量数据,帮助管理员快速识别异常、排查问题,保障业务稳定运行。本文深入探讨其作用机制、核心功能(如流量捕获、协议解析、可视化告警等)、典型应用场景(故障定位、威胁检测、合规审计)及选型建议,强调其在现代IT系统中的重要价值。
流量实时分析软件的核心价值与实战指南
|
机器学习/深度学习 安全
Prompt攻击
【8月更文挑战第5】
1152 3
|
人工智能 自然语言处理 算法
|
传感器 物联网 大数据
[总结]蓝牙各个版本的关系和区别
[总结]蓝牙各个版本的关系和区别
2671 0
|
算法 Ubuntu Linux
在Linux中,对比apt和yum两种包管理器在不同Linux发行版中应用有何区别?
在Linux中,对比apt和yum两种包管理器在不同Linux发行版中应用有何区别?

热门文章

最新文章