Why this Matlab Funcation does not run and every time show such type of error

8 ビュー (過去 30 日間)
function duty = algorithm(vpv,ipv,delta)
% I used the MPPT algorithm in the MATLAB examples
% I only modify somethings.
duty_init = 0.1;
% min and max value are used to limit duty between
% 0 and 0.85
duty_min=0;
duty_max=0.85;
persistent Vold Pold duty_old;
% persistent variable type can be store the data
% we need the old data by obtain difference
% between old and new value
if isempty(Vold)
Vold=0;
Pold=0;
duty_old=duty_init;
end
P= vpv*ipv; % power
dV= vpv - Vold; % differnce between old and new voltage
dP= P - Pold; % Differnce between old and new power
% the algorithm in below search the dP/dV=0
% if the derivative equal to zero
% duty will not change
% if old and new power not equal
% &
% pv voltage bigger then 30v
% the algorithm will works
if dP ~= 0 && vpv>30
if dP < 0
if dV < 0
duty = duty_old - delta;
else
duty = duty_old + delta;
end
else
if dV <0
duty = duty_old + delta;
else
duty = duty_old - delta;
end
end
end
duty = duty_old;
end
% the below if limits the duty between min and max
if duty >= duty_max
duty=duty_max;
elseif dutycycle_min
duty=duty_min;
end
%stored data
duty_old=duty;
vold=vpv;
Pold = p;

採用された回答

Cris LaPierre
Cris LaPierre 2020 年 7 月 29 日
Because the last 10 lines of your code are outside the end that terminates the function. Fix that error, and then see what errors remain. Is this what you intended?
function duty = algorithm(vpv,ipv,delta)
% I used the MPPT algorithm in the MATLAB examples
% I only modify somethings.
duty_init = 0.1;
% min and max value are used to limit duty between
% 0 and 0.85
duty_min=0;
duty_max=0.85;
persistent Vold Pold duty_old;
% persistent variable type can be store the data
% we need the old data by obtain difference
% between old and new value
if isempty(Vold)
Vold=0;
Pold=0;
duty_old=duty_init;
end
P= vpv*ipv; % power
dV= vpv - Vold; % differnce between old and new voltage
dP= P - Pold; % Differnce between old and new power
% the algorithm in below search the dP/dV=0
% if the derivative equal to zero
% duty will not change
% if old and new power not equal
% &
% pv voltage bigger then 30v
% the algorithm will works
if dP ~= 0 && vpv>30
if dP < 0
if dV < 0
duty = duty_old - delta;
else
duty = duty_old + delta;
end
else
if dV <0
duty = duty_old + delta;
else
duty = duty_old - delta;
end
end
end
duty = duty_old;
% the below if limits the duty between min and max
if duty >= duty_max
duty=duty_max;
elseif dutycycle_min
duty=duty_min;
end
%stored data
duty_old=duty;
vold=vpv;
Pold = p;
end
  6 件のコメント
Vinod Suthar
Vinod Suthar 2020 年 8 月 8 日
sir they are show such problem
Cris LaPierre
Cris LaPierre 2020 年 8 月 8 日
Go through the errors one by one and address them each individually. For example, in the first message, you are told that you need to change your current directory. In errors 2 and 3, you need to adjust your sample time.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePower and Energy Systems についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by