How to solve this error while using ode15s.
1 次查看(过去 30 天)
显示 更早的评论
function dx=man(t,x,V,VF,y,L,D,acond)
dx =((V+VF)*y-L*x-D*x)*1/acond;
end
%%prob settings
lb=[0 0 0 0 0 0 ];
ub= [100 120 1 100 110 20 ];
prob=@(t,x) man(t,x,V,VF,y,L,D,acond);---------main areas creating the error
%% parameters for differential evolution
np=10;
it=100;
cr=0.7;
F=0.8;
%% START of DE
f=NaN(np,1);
fu=NaN(np,1);
d=length(lb);
U=NaN(np,d);
p= repmat(lb,np,1)+(repmat((ub-lb),np,1).*rand(np,d));
for i=1:np
A=p(i,:);
V=A(1);
VF=A(2);
y=A(3);
L=A(4);
D=A(5);
acond=A(6);
[t X]=ode15s('prob',[0 75],0);-------main areas creating the error.
f(i)=X(100,1);
end
0 个评论
采纳的回答
Stephan
2020-11-27
%prob settings
lb=[0 0 0 0 0 0 ];
ub= [100 120 1 100 110 20 ];
% parameters for differential evolution
np=10;
it=100;
cr=0.7;
F=0.8;
% START of DE
f=NaN(np,1);
fu=NaN(np,1);
d=length(lb);
U=NaN(np,d);
p= repmat(lb,np,1)+(repmat((ub-lb),np,1).*rand(np,d));
for i=1:np
A=p(i,:);
V=A(1);
VF=A(2);
y=A(3);
L=A(4);
D=A(5);
acond=A(6);
[t, X]=ode15s(@(t,x)man(t,x,V,VF,y,L,D,acond),[0 75],0);
f(i)=X(size(t,1),1);
end
function dx=man(~,x,V,VF,y,L,D,acond)
dx =((V+VF)*y-L*x-D*x)*1/acond;
end
3 个评论
Stephan
2020-11-27
calling the function by passing extra parameters works this way:
[t, X]=ode15s(@(t,x)man(t,x,V,VF,y,L,D,acond),[0 75],0);
instead of:
prob=@(t,x) man(t,x,V,VF,y,L,D,acond);
.
.
.
[t X]=ode15s('prob',[0 75],0);
And inside the loop:
f(i)=X(size(t,1),1);
instead of
f(i)=X(100,1);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!