Info

此问题已关闭。 请重新打开它进行编辑或回答。

Is there any way I can ensure that the numbers generated in ode45 are positive?

1 次查看(过去 30 天)
Here is my code. Many numbers generated in the solution are negative and there are a lot of NaNs too.
%setting up the values of constants
N=1000; %number of systems
%m=0.3*ones(N,1)
%S=0.7;%coupling streangth
tspan=linspace(0,10000,10000)';%time steps
%solving the equation
ystart=zeros(N,1);
for i=1:N
ystart(i)=unifrnd(0,1);%Initial conditions; (9 by 1) column vector
%indicating that each oscillator starts with
%random initil voltage between 0 and 1
end
%options=odeset('NonNegative',1);
[t,y]=ode45(@CLIF,tspan,ystart);%options);
%Plotting
%rescale(y(11,:))
plot(y(5,:),'.')
%axis([1 11 0 1])
xlabel('ith oscillator')
ylabel('voltage')
title('Coupled LIF')
%Defining the system of equations
function dydt=CLIF(t,y,m,N,S)
N=1000;
m=0.3;
S=15;
dydt=zeros(N,1);
for i=1:N
if i<N
dydt(i)=-y(i)+m+(S).*((y(i)-y(i+1)));
else
break
end
end
end
  13 个评论
Jan
Jan 2018-10-24
You need y(i+1) to construct the N'th value. Does y has N+1 elements? If so, use N instead of N-1.

回答(0 个)

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by