How to solve this error while using ode15s.

1 view (last 30 days)
bhargav mehar on 26 Nov 2020
Commented: bhargav mehar on 27 Nov 2020
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

Stephan on 27 Nov 2020
%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

bhargav mehar on 27 Nov 2020
Thank you mate.....worked like a charm.....can you please explain me the reason for my error.
Stephan on 27 Nov 2020
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);
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);
f(i)=X(100,1);
bhargav mehar on 27 Nov 2020
okay thank you so much