非常感谢大伙的帮助,我之前可能说的不太清楚,因为我对s函数不太很熟,我不知道怎么写,我把我的程序贴出来麻烦大家再帮我看看,看我的问题在哪。
我要寻找的是u(3)的最大值,当u(8)或u(9)发生变化时,我要重新启动程序寻找最大值。
怎样才能算找到最大值呢,有什么标志么,重新启动的话是不是要在后面加一个多路选择是否重新执行这个s函数,还是可以直接在这个函数里面写,谢谢!
function [sys,x0,str,ts] = mppt(t,x,u,flag)
switch flag,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
%%%%%%%%%%
% Update %
%%%%%%%%%%
case 2,
sys = mdlUpdate(t,x,u);
%%%%%%%%%%
% Output %
%%%%%%%%%%
case 3,
sys = mdlOutputs(t,x,u);
case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);
%%%%%%%%%%%%%
% Terminate %
%%%%%%%%%%%%%
case 9,
sys = [];
otherwise
error(['unhandled flag = ',num2str(flag)]);
end
%end sfundsc1
%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 3;
sizes.NumOutputs = 3;
sizes.NumInputs = 9;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [0;0;0];
str = [];
ts = [-2 0]; % Inherited sample time
% end mdlInitializeSizes
function sys = mdlUpdate(t,x,u)
x(1) = max(u(3)) ;如何结束呢?
我以前是: 判断这个值如果比它前面的大,同时比他后面的大
%if x(3) > (u(3)+10)*(u(7)*(1-u(5)*(exp((u(3)+10-u(1))/(u(4)*u(6)))-1))+u(2)) && x(3) > (u(3)-10)*(u(7)*(1-u(5)*(exp((u(3)-10-u(1))/(u(4)*u(6)))-1))+u(2))
% x(1) = u(3) ;但是我不知道如何保持输出值一直为最大值?
x(2)= u(7)*(1-u(5)*(exp((x(1)-u(1))/(u(4)*u(6)))-1))+u(2) ; %j计算公式
x(3)= u(3)*(u(7)*(1-u(5)*(exp((u(3)-u(1))/(u(4)*u(6)))-1))+u(2)) ; %j计算公式
sys=x;
%
%=======================================================================
% mdlUpdate
% Handle discrete state updates, sample time hits, and major time step
% requirements.
%=======================================================================
%
%end mdlUpdate
%
%=======================================================================
% mdlOutputs
% Return the output vector for the S-function
%=====================================================================
function sys = mdlOutputs(t,x,u)
sys(1)= x(1);
sys(2) = x(2) ;
sys(3) = x(1)*x(2) ;
function sys=mdlGetTimeOfNextVarHit(t,x,u)
sampletime=0.0001;
sys=t+sampletime;
[ 本帖最后由 gty3344 于 2008-12-24 22:55 编辑 ] |