why this equation is not ploting
Mostrar comentarios más antiguos
Tstart = 100;
Tend = 1000.0;
Nt = 2000;
dT = (Tend-Tstart)/Nt;
X0 = 0.3;
Y0 = 0;
Z0 = 0;
N = 20;
k1=1;
k2=2.52;
k3=1;
k4=5;
I=1.5;
s=4;
xr=-1.6;
r=0.01;
T = zeros(Nt+1,1);
X = zeros(Nt+1,1);
Y = zeros(Nt+1,1);
Z = zeros(Nt+1,1);
a = zeros(N+1,1);
b = zeros(N+1,1);
c = zeros(N+1,1);
T(1) = 0.0;
X(1) = X0;
Y(1) = Y0;
Z(1) = Z0;
for j = 2:Nt+1
a(1) = X(j-1);
b(1) = Y(j-1);
c(1) = Z(j-1);
for k = 1:N
a(k+1)=(b(k)-k1*a(k).^3+k2*a(k).^2-c(k)+I)/(k+1);
b(k+1)=(k3-k4*a(k).^2-b(k))/(k+1);
c(k+1)=r*(s*(a(k)-xr)-c(k))/(k+1);
end
x = a(1);
y = b(1);
z = c(1);
for k = 2:N+1
x = x + a(k)*dT^(k-1);
y = y + b(k)*dT^(k-1);
z = z + c(k)*dT^(k-1);
end
T(j) = T(j-1) + dT;
X(j) = x;
Y(j) = y;
Z(j) = z;
end
plot(T,X)
It's not showing the plot! How do I resolve this?
2 comentarios
Image Analyst
el 1 de Abr. de 2022
It works for us.
shiv gaur
el 1 de Abr. de 2022
Editada: Walter Roberson
el 1 de Abr. de 2022
Respuestas (1)
Sam Chak
el 1 de Abr. de 2022
Editada: Walter Roberson
el 1 de Abr. de 2022
Hi @shiv gaur
Simulating the Hindmarsh–Rose model requires solving the differential equations using some numerical ode solvers. You can change the parameters in the code below for your study. If you find my Answer is helpful, please vote and Accept.
function Hindmarsh_Rose
close all
clc
tspan = [0 1000]; % time span of simulation
y0 = [-1.5 -10 2]; % initial values
[t, y] = ode45(@(t, y) odefcn(t, y), tspan, y0);
plot(t, y(:,1), 'linewidth', 1.5)
grid on
xlabel('Time, t [sec]')
ylabel('x(t)')
title('Hindmarsh–Rose Neuronal Bursting Model')
end
function dydt = odefcn(t, y) % Ordinary Differential Equations
dydt = zeros(3,1);
a = 1;
b = 3;
c = 1;
d = 5;
I = 2;
r = 0.0021;
s = 4;
xR = -8/5;
dydt(1) = y(2) - a*y(1)^3 + b*y(1)^2 - y(3) + I;
dydt(2) = c - d*y(1)^2 - y(2);
dydt(3) = r*(s*(y(1) - xR) - y(3));
end
Result:

17 comentarios
shiv gaur
el 1 de Abr. de 2022
Editada: Walter Roberson
el 1 de Abr. de 2022
shiv gaur
el 1 de Abr. de 2022
Editada: Walter Roberson
el 1 de Abr. de 2022
shiv gaur
el 1 de Abr. de 2022
shiv gaur
el 1 de Abr. de 2022
Sam Chak
el 1 de Abr. de 2022
Ok @shiv gaur, please show all relevant equations and explain how your power series works. Are you researching on a never-seen-before novel mathematical power series based numerical solver? The proposed ode45 solution does not meet your expectation, although it took some time to research on the Hindmarsh–Rose model on a few papers and type out the code.
shiv gaur
el 1 de Abr. de 2022
shiv gaur
el 1 de Abr. de 2022
shiv gaur
el 1 de Abr. de 2022
Torsten
el 1 de Abr. de 2022
for k = 1:N
a(k+1)=(b(k)-k1*a(k).^3+k2*a(k).^2-c(k)+I)/(k+1);
b(k+1)=(k3-k4*a(k).^2-b(k))/(k+1);
c(k+1)=r*(s*(a(k)-xr)-c(k))/(k+1);
end
If it were that easy to get the Taylor coefficients for the Hindmarsh-Rose model, the loop for the Lorenz equation would have been
for k = 1:N
a(k+1) = (SIGMA*(b(k) - a(k)))/k;
b(k+1) = ((R*a(k) - b(k)) - a(k)*c(k))/k ;
c(k+1) = (-B*c(k) + a(k)*b(k))/k ;
end
instead of
for k = 1:N
SB = 0.0;
SC = 0.0;
for i= 0:k-1
SB = SB + a(i+1)*c(k-i);
SC = SC + a(i+1)*b(k-i);
end
a(k+1) = (SIGMA*(b(k) - a(k)))/k;
b(k+1) = ((R*a(k) - b(k)) - SB)/k ;
c(k+1) = (-B*c(k) + SC)/k ;
end
wouldn't it ?
shiv gaur
el 2 de Abr. de 2022
shiv gaur
el 2 de Abr. de 2022
@shiv gaur Your Hindmarsh–Rose code generates NaN in a, b, c in the loop "for k = 1:N". The HR ODEs are different from the Lorenz ODEs because they contain power terms. But there is none in the Lorenz system.
When you use .^ operator, the power() function is called, and it executes
The NaN was generated most likely because on the 3rd iteration, a(k) becomes negative and log(a(k)) produces a complex number, and your looping code creates a chain of issues. That's why it plots until T = 0.5 sec instead of 1000 sec.
Tstart = 0;
Tend = 1000.0;
Nt = 2000;
dT = (Tend-Tstart)/Nt;
X0 = -1.5;
Y0 = -10;
Z0 = 2;
N = 200;
k1 = 1;
k2 = 3;
k3 = 1;
k4 = 5;
I = 2;
s = 4;
xr = -1.6;
r = 0.0021;
T = zeros(Nt+1,1);
X = zeros(Nt+1,1);
Y = zeros(Nt+1,1);
Z = zeros(Nt+1,1);
a = zeros(N+1,1);
b = zeros(N+1,1);
c = zeros(N+1,1);
T(1) = 0.0;
X(1) = X0;
Y(1) = Y0;
Z(1) = Z0;
for j = 2:Nt+1
a(1) = X(j-1);
b(1) = Y(j-1);
c(1) = Z(j-1);
for k = 1:N % NaN is produced in this loop due to the power terms in Hindmarsh–Rose
a(k + 1) = (b(k) - k1*a(k).^3 + k2*a(k).^2 - c(k) + I)/(k + 1);
b(k + 1) = (k3 - k4*a(k).^2 - b(k))/(k + 1);
c(k + 1) = r*(s*(a(k) - xr) - c(k))/(k + 1);
% Test (no power terms)
% a(k + 1) = (b(k))/(k + 1);
% b(k + 1) = (k3 - k4*a(k) - b(k))/(k + 1);
% c(k + 1) = r*(s*(a(k) - xr) - c(k))/(k + 1);
end
x = a(1);
y = b(1);
z = c(1);
for k = 2:N+1
x = x + a(k)*dT^(k-1);
y = y + b(k)*dT^(k-1);
z = z + c(k)*dT^(k-1);
end
T(j) = T(j-1) + dT;
X(j) = x;
Y(j) = y;
Z(j) = z;
end
plot(T, X)
Try fixing that or you may want to request for help from the Experts like @Torsten and @Image Analyst.
yes in case of lorenz equation is correct in Hmarsh eq is different
No, it's not different. The rules for calculating the coeffcients of the Taylor series for the solutions of systems of ordinary differential equations are not dependent on the differential equation you solve. They are valid in general.
shiv gaur
el 2 de Abr. de 2022
shiv gaur
el 2 de Abr. de 2022
shiv gaur
el 3 de Abr. de 2022
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


