when i tried to runpf matpower 33 bus program, it shows this problem
28 ビュー (過去 30 日間)
古いコメントを表示
Error using loadcase (line 199)
loadcase: syntax error or undefined data matrix(ices) in the file
Undefined function 'feval_w_path' for input arguments of type 'char'.
Error in runpf (line 101)
mpc = loadcase(casedata);
0 件のコメント
回答 (3 件)
Namnendra
2024 年 7 月 23 日
Hi Fausta,
The error you're encountering indicates that there is a problem with the syntax or content of the case file you're trying to load in MATPOWER, a power system simulation package in MATLAB. The `loadcase` function is used to load the case data, and it seems like there's a syntax error or an undefined variable in your case file.
Here's a step-by-step guide to troubleshoot and resolve this issue:
Steps to Troubleshoot and Resolve the Error
1. Check the Case File Syntax:
- Ensure that the case file (e.g., `case33.m`) follows the correct MATPOWER case file format.
- The case file should define a MATLAB struct with fields such as `mpc.version`, `mpc.baseMVA`, `mpc.bus`, `mpc.gen`, `mpc.branch`, etc.
2. Verify Variable Definitions:
- Check that all required matrices (`bus`, `gen`, `branch`, etc.) are defined and populated correctly.
- Ensure there are no syntax errors or undefined variables in the case file.
3. MATPOWER Path Configuration:
- Ensure that MATPOWER is correctly installed and its path is added to MATLAB's search path.
- You can add the MATPOWER path using the `addpath` function:
addpath('path_to_matpower');
4. Example Case File:
- Compare your case file with an example case file provided by MATPOWER (e.g., `case9.m`) to ensure the structure and syntax are correct.
- Here is an example structure of a MATPOWER case file:
function mpc = case33
%CASE33 Power flow data for 33 bus distribution system.
%% MATPOWER Case Format : Version 2
mpc.version = '2';
%%----- Power Flow Data -----%%
%% system MVA base
mpc.baseMVA = 1;
%% bus data
% bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin
mpc.bus = [
1 1 0.0 0.0 0.0 0.0 1 1.00 0.0 12.66 1 1.05 0.95;
2 1 0.1 0.06 0.0 0.0 1 1.00 0.0 12.66 1 1.05 0.95;
% more bus data...
];
%% generator data
% bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf
mpc.gen = [
1 0.0 0.0 10.0 -10.0 1.00 1.0 1 10.0 -10.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0;
% more generator data...
];
%% branch data
% fbus tbus r x b rateA rateB rateC ratio angle status angmin angmax
mpc.branch = [
1 2 0.0922 0.0470 0.0 100.0 100.0 100.0 0.0 0.0 1 -360.0 360.0;
% more branch data...
];
%%----- OPF Data -----%%
%% generator cost data
% 1 startup shutdown n x1 y1 ... xn yn
% 2 startup shutdown n c(n-1) ... c0
mpc.gencost = [
2 0.0 0.0 3 0.0 20.0 0.0;
% more cost data...
];
end
5. Run the Power Flow Analysis:
- Once the case file is correctly formatted and saved, you can run the power flow analysis using the `runpf` function:
mpc = loadcase('case33');
results = runpf(mpc);
I hope the above information helps.
Thank you.
0 件のコメント
Walter Roberson
2024 年 7 月 23 日
You appear to have a corrupted version of matpower .
feval_w_path is defined for at least MATPOWER 5, MATPOWER 6, MATPOWER 7, and MATPOWER 8
It is possible that your version of MATPOWER has the function but that somehow the function is not on the MATLAB path.
0 件のコメント
Izhar
2025 年 12 月 3 日 14:01
Lab2Code.m
% =============================================================== % LAB 2: Load Flow Analysis of IEEE 9-Bus System (Newton-Raphson) % =============================================================== % Author: Muhammad Haris % Tool: MATLAB + MATPOWER % =============================================================== clc; clear; close all; define_constants; disp('==============================================='); disp(' LOAD FLOW ANALYSIS USING NEWTON-RAPHSON '); disp('==============================================='); %% Step 1: Load IEEE 9-Bus System mpc = loadcase('case9'); disp('✅ IEEE 9-Bus Test Case Loaded Successfully'); disp(['Total Buses: ', num2str(size(mpc.bus,1))]); disp(['Total Generators: ', num2str(size(mpc.gen,1))]); disp(['Total Branches: ', num2str(size(mpc.branch,1))]); disp('-----------------------------------------------'); %% Step 2: Run Power Flow using Newton-Raphson Method mpopt = mpoption('pf.alg','NR','verbose',1,'out.all',0); tic; results = runpf(mpc, mpopt); elapsed_time = toc; if results.success disp('✅ Power Flow Converged Successfully'); else disp('❌ Power Flow Did Not Converge'); end disp(['Computation Time: ', num2str(elapsed_time), ' seconds']); disp(['Iterations Taken: ', num2str(results.iterations)]); disp('-----------------------------------------------'); %% Step 3: Display Bus Results disp('========= BUS VOLTAGE RESULTS ========='); BusData = table(results.bus(:,BUS_I), results.bus(:,VM), results.bus(:,VA), ... 'VariableNames', {'Bus','Voltage_pu','Angle_deg'}); disp(BusData); %% Step 4: Display Line Flow Results disp('========= BRANCH FLOW RESULTS ========='); BranchData = table(results.branch(:,F_BUS), results.branch(:,T_BUS), ... results.branch(:,PF), results.branch(:,QF), results.branch(:,PT), results.branch(:,QT), ... 'VariableNames', {'From_Bus','To_Bus','P_from_MW','Q_from_Mvar','P_to_MW','Q_to_Mvar'}); disp(BranchData); %% Step 5: Calculate Total System Losses total_loss_P = sum(results.branch(:,PF) + results.branch(:,PT)); total_loss_Q = sum(results.branch(:,QF) + results.branch(:,QT)); disp('========= SYSTEM LOSSES ========='); fprintf('Total Real Power Loss = %.4f MW\n', abs(total_loss_P)); fprintf('Total Reactive Power Loss = %.4f Mvar\n', abs(total_loss_Q)); %% Step 6: Plot Voltage Profile figure('Color','w'); plot(results.bus(:,BUS_I), results.bus(:,VM), 'o-b','LineWidth',1.8); xlabel('Bus Number'); ylabel('Voltage Magnitude (p.u.)'); title('Voltage Profile - IEEE 9-Bus System (Newton-Raphson)'); grid on; %% Step 7: Plot Bus Voltage Angles figure('Color','w'); plot(results.bus(:,BUS_I), results.bus(:,VA), 's-r','LineWidth',1.8); xlabel('Bus Number'); ylabel('Voltage Angle (degrees)'); title('Bus Voltage Angles - IEEE 9-Bus System'); grid on; %% Step 8: Heavy Load Case (Optional) % Increase load at Bus 5 by 50% mpc.bus(5, PD) = 1.5 * mpc.bus(5, PD); disp('⚙️ Increasing load at Bus 5 by 50%...'); results_heavy = runpf(mpc, mpopt); % Compare voltage profile figure('Color','w'); plot(results.bus(:,BUS_I), results.bus(:,VM),'o-b','LineWidth',1.8); hold on; plot(results_heavy.bus(:,BUS_I), results_heavy.bus(:,VM),'s--r','LineWidth',1.8); xlabel('Bus Number'); ylabel('Voltage (p.u.)'); legend('Base Case','Heavy Load Case'); title('Voltage Profile Comparison under Load Variation'); grid on; disp('-----------------------------------------------'); disp('Simulation Completed Successfully ✅'); disp('-----------------------------------------------');
3 件のコメント
Izhar
2025 年 12 月 3 日 14:02
移動済み: Walter Roberson
2025 年 12 月 3 日 18:35
mMake sure MATPOWER is installed for runpf to work (see guidance above).
Walter Roberson
2025 年 12 月 3 日 18:34
Please format this as code.
First click on the '>' button in the CODE portion of the tool ribbon. Then paste your code into the area that gets opened.
参考
カテゴリ
Help Center および File Exchange で Controller Creation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!