How can I connect the points on my graph?
Show older comments
I have written code to plot graphs for the Hindmarsh-Rose equation, but, I have a few problems with it.
I can either plot the point for the graph inside the loop function, which is quick but the points are not connected. Or i can plot the points outside the loop function in which the points end up connected but to get the results it takes a long time.
I have tried a few different things like trying to store the values in an array so i can later use them in the code, but I assume I have not used them correctly as they dont work.
I wasn't sure what part of the code to add to help give a better picture so I decided to put it all in. Any suggestions would be appreciated.
a = 1.0;
b = 3.0;
c = 1.0;
d = 5.0;
I = 3.25;
r = 0.005;
s = 4.0;
p0 = -1.6;
dt = 1;
t = 0;
p = -1.6;
q = 4.0;
n = 2.75;
scale = 0.001;
ms = 50;
iterations = ms * 1000;
count = 0;
arrayp = zeros(1, ms);
for i = 0:iterations
remainder = mod(i,1000);
if remainder == 0
fprintf('t = %.4f p = %.4f q = %.4f n = %.4f do = %.4f \n', t, p, q, n, do)
arrayp(count, :) = (p);
%Using this plot function works faster but the plots don't connect
%plot(t,p, '-xr')
%hold all
end
dp = q - (a*p.^3) + (b*p.^2) - n + I ;
dq = c - (d*p.^2) - q;
dn = r*(s*(p - p0) - n);
p = p + (dp * scale);
q = q + (dq * scale);
n = n + (dn * scale);
t = t + (dt * scale);
%Using this plot function connects the points but it is slow
%plot(t,p,'-xr')
%hold all
end
Accepted Answer
More Answers (0)
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!