Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

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

1 vue (au cours des 30 derniers jours)
Vipin  Padinjarath
Vipin Padinjarath le 24 Oct 2018
Clôturé : MATLAB Answer Bot le 20 Août 2021
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 commentaires
Jan
Jan le 24 Oct 2018
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.
Vipin  Padinjarath
Vipin Padinjarath le 24 Oct 2018
Oh... okay. I got it. Thank you..

Réponses (0)

Cette question est clôturée.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by