Unrecognized function or variable 'calculate_power_loss'.

조회 수: 2 (최근 30일)
Kaustubh Joshi
Kaustubh Joshi 2024년 6월 18일
답변: Ayush Modi 2024년 6월 18일
bus_data = [1 0 0 0
2 100 60 0
3 90 40 0
4 120 80 0
5 60 30 0
6 60 20 0
7 200 100 0
8 200 100 0
9 60 20 0
10 60 20 0
11 45 30 0
12 60 35 0
13 60 35 0
14 120 80 0
15 60 10 0
16 60 20 0
17 60 20 0
18 90 40 0
19 90 40 0
20 90 40 0
21 90 40 0
22 90 40 0
23 90 50 0
24 420 200 0
25 420 200 0
26 60 25 0
27 60 25 0
28 60 20 0
29 120 70 0
30 200 600 0
31 150 70 0
32 210 100 0
33 60 40 0 ];
line_data = [1 1 2 0.0922 0.0470
2 2 3 0.4930 0.2511
3 3 4 0.3660 0.1864
4 4 5 0.3811 0.1941
5 5 6 0.8190 0.7070
6 6 7 0.1872 0.6188
7 7 8 0.7114 0.2351
8 8 9 1.0300 0.7400
9 9 10 1.0440 0.7400
10 10 11 0.1966 0.0650
11 11 12 0.3744 0.1238
12 12 13 1.4680 1.1550
13 13 14 0.5416 0.7129
14 14 15 0.5910 0.5260
15 15 16 0.7463 0.5450
16 16 17 1.2890 1.7210
17 17 18 0.7320 0.5740
18 2 19 0.1640 0.1565
19 19 20 1.5042 1.3554
20 20 21 0.4095 0.4784
21 21 22 0.7089 0.9373
22 3 23 0.4512 0.3083
23 23 24 0.8980 0.7091
24 24 25 0.8960 0.7011
25 6 26 0.2030 0.1034
26 26 27 0.2842 0.1447
27 27 28 1.0590 0.9337
28 28 29 0.8042 0.7006
29 29 30 0.5075 0.2585
30 30 31 0.9744 0.9630
31 31 32 0.3105 0.3619
32 32 33 0.3410 0.5302 ];
load_data = [1 0 0
2 100 60
3 90 40
4 120 80
5 60 30
6 0 0
7 200 100
8 200 100
9 60 20
10 60 20
11 45 30
12 60 35
13 60 35
14 120 80
15 60 10
16 60 20
17 60 20
18 90 40
19 90 40
20 90 40
21 90 40
22 90 40
23 90 50
24 420 200
25 420 200
26 60 25
27 0 0
28 60 20
29 120 70
30 200 600
31 150 70
32 210 100
33 60 40];
% PSO parameters
num_particles = 50; % Number of particles
max_iterations = 100; % Maximum number of iterations
c1 = 2; % Cognitive parameter
c2 = 2; % Social parameter
w = 0.5; % Inertia weight
particles = rand(num_particles, 2); % Random initial positions for DGs (bus, size)
velocities = zeros(num_particles, 2); % Initial velocities
best_particle_positions = particles;
best_particle_losses = inf (num_particles, 1);
[~, best_global_index] = min(best_particle_losses);
best_global_position = best_particle_positions(best_global_index, :);
for i=1:size(particles,1)
dg_bus=round(particles(i,1));
dg_size=particles(i,2);
loss=0;
loss=loss+ calculate_power_loss(dg_bus,dg_size,bus_data, line_data,load_data);
%disp(loss);
end
for iter = 1:max_iterations
for i = 1:num_particles
% Evaluate the objective function
current_loss = objective_function(particles(i, :), bus_data, line_data, load_data);
% Update personal bests
if current_loss < best_particle_losses(i)
best_particle_losses(i) = current_loss;
best_particle_positions(i, :) = particles(i, :);
end
end
end
function loss = objective_function(particles, bus_data, line_data, load_data)
end
  댓글 수: 3
Aquatris
Aquatris 2024년 6월 18일
You probably forgot to add the path where calculate_power_loss function is to your matlab environment.
Kaustubh Joshi
Kaustubh Joshi 2024년 6월 18일
This is not a full code. But I will check for it. Thank you for reply @Ayush Modi

댓글을 달려면 로그인하십시오.

답변 (1개)

Ayush Modi
Ayush Modi 2024년 6월 18일
Hi Kaustubh,
It appears from the code snippet shared that you're invoking a function named 'calculate_power_loss' in the below line:
loss=loss+ calculate_power_loss(dg_bus,dg_size,bus_data, line_data,load_data);
However, the function definition is not present. Including the function definition might solve the issue.

카테고리

Help CenterFile Exchange에서 Web Services에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by