Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 1 (최근 30일)
Vipin  Padinjarath
Vipin Padinjarath 2018년 10월 24일
마감: MATLAB Answer Bot 2021년 8월 20일
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