why this equation is not ploting

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 Comments

It works for us.
shiv gaur
shiv gaur on 1 Apr 2022
Edited: Walter Roberson on 1 Apr 2022
why this is not like that pl match with equation very famous hind marsh

Sign in to comment.

Answers (1)

Sam Chak
Sam Chak on 1 Apr 2022
Edited: Walter Roberson on 1 Apr 2022
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 Comments

this may be the option
now we have use lorenz system using power series the program is given below so here we are applying power series to hindmarsh equation in same way as lorenz
program is here
Tstart = 0.0;
Tend = 1000.0;
Nt = 20000;
dT = (Tend-Tstart)/Nt;
X0 = 0.0;
Y0 = 1.0;
Z0 = 0.0;
N = 20;
SIGMA = 10;
R = 28;
B = 8/3;
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
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
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,Y)
from lorenz to apply HM equation
I have use the your value HM equation
the program using power series is right how to match with ode your program with power series program is given below
Tstart = 0;
Tend = 1000.0;
Nt = 2000;
dT = (Tend-Tstart)/Nt;
X0 = -1.5;
Y0 = -10;
Z0 = 2;
N = 200;
k1=1
k1 = 1
k2=3
k2 = 3
k3=1
k3 = 1
k4=5
k4 = 5
I=2
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
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)
if any one help to match the graph accept the answer
we are matching the ode with power series in lorenz system why in the HMarsh the ode plot is not matching with power series
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.
I have use in lorenz equation just as butterfly using power series so this is to apply in rossler also
why is not applicable to HMarsh equation
I have to match the ode solution with bpower series as in same as in lorenz system
this is the lorenz type fig 4 ,5 paper that program works but in HM equation this is not matching properly
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 ?
in hmarsh equation we have not use SB and SC so any product of summation is not there so we use same equation
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
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)
yes in case of lorenz equation is correct in Hmarsh eq is different
https://en.wikipedia.org/wiki/Hindmarsh%E2%80%93Rose_model
Sam Chak
Sam Chak on 2 Apr 2022
Edited: Sam Chak on 2 Apr 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.
Torsten
Torsten on 2 Apr 2022
Edited: Torsten on 2 Apr 2022
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.
so how to resolve this problem
Torsten
Torsten on 2 Apr 2022
Edited: Torsten on 2 Apr 2022
What shall I say ?
By correctly calculating the a, b and c arrays.
sir you have all the things equation papers so you are req to resolve the problem
if any one help appriciation for solving hmarsh using power series

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Products

Release

R2021b

Asked:

on 1 Apr 2022

Commented:

on 3 Apr 2022

Community Treasure Hunt

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

Start Hunting!