I am trying to solve hindmarsh rose equation and i wrote the function for it.. But, as i plot the equation using ode45. i am getting error. I tried using ode15s but, it gives same error. Attached is my code along with the error.

3 次查看(过去 30 天)
I am trying to solve hindmarsh rose equation and i wrote the function for it.. But, as i plot the equation using ode45. i am getting error. I tried using ode15s but, it gives same error. Attached is my code along with the error.
Function:
function F = hindmarsh_rose(x,u) %function
F = zeros(3,1);
X=x(1);
Y=x(2);
Z=x(3);
F = [Y-X.^3+3*X.^2-Z+u;1-5*X.^2-Y;0.001*(4*(X-(-1.618))-Z)]; %equations
end
Code:
u =0:0.01:5; %range for u
x0 = [0.1,0.1,0.1]; %initial values
tspan= [0 25]; %time span
[t,x] = ode15s(@(t,x) hindmarsh_rose(x,u), tspan, x0); %using ode15
plot(t,x);
Error:
>> try1
Error using hindmarsh_rose (line 2)
Not enough input arguments.
Error in @(t,x)hindmarsh_rose
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode15s (line 148)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in try1 (line 4)
[t,x] = ode15s(@(t,x) hindmarsh_rose, tspan, x0);

采纳的回答

Walter Roberson
Walter Roberson 2017-9-9
Your error message says you have the line
[t,x] = ode15s(@(t,x) hindmarsh_rose, tspan, x0);
but the code you posted has the line
[t,x] = ode15s(@(t,x) hindmarsh_rose(x,u), tspan, x0); %using ode15
You did not post the code for the same version that you executed. The version that you posted, with the (x,u) would not produce the error message that you indicate.
However, line 1 of try1 establishes u as a row vector of length 501. Your code inside the hindmarsh_rose function includes the line
F = [Y-X.^3+3*X.^2-Z+u;1-5*X.^2-Y;0.001*(4*(X-(-1.618))-Z)]; %equations
The first component of that list, Y-X.^3+3*X.^2-Z+u, uses u and so would give a row vector of length 501 as its value. The second component of the list, 1-5*X.^2-Y, and the third component of the list, 0.001*(4*(X-(-1.618))-Z), do not use u, and so are going to give scalars. So your [] operation is going to try to do [1 x 501; 1 x 1; 1 x 1] which is going to fail because the number of columns is not the same for the ";" operation. If you were to code,
F = [Y-X.^3+3*X.^2-Z+u.';1-5*X.^2-Y;0.001*(4*(X-(-1.618))-Z)]; %equations
then that would give [501 x 1; 1 x 1; 1 x 1] which could succeed, giving a 503 x 1 output. However, that would then promptly fail because the number of values in the vector, 503, would not match the number of values in x0, namely 3.
My guess at what you want is
u =0:0.01:5; %range for u
x0 = [0.1,0.1,0.1]; %initial values
tspan = [0 25]; %time span
for K = 1 : length(u)
[t,x] = ode15s(@(t,x) hindmarsh_rose(x,u(K)), tspan, x0); %using ode15
plot(t,x);
hold on
end
  1 个评论
Sam17
Sam17 2017-9-10
编辑:Walter Roberson 2017-9-10
Hi, thankyou for your answer i did the way which you have written above but it takes a lot of time to stimulate. Therefore i just only gave a number to 'u' variable. Also, i want some help or suggestion regarding choosing the parameters to plot both hindmarsh_rose and fitzhugh_nagumo model. I am not getting the exact plot. Below is my code:
u = 10
x0 = [0.1,0.1,0.1];
tspan= [0 100];
[t,x] = ode45(@(t,x) hindmarsh_rose(x,u), tspan, x0);
plot(t,x);
%plot(t,x(:,1));
xlabel('time[s]');
ylabel('magnitude');
title('Hindmarsh–Rose neuron model Stimulation')
grid on;
I have attached my plot and the wikipedia link of the plot which i should actually get. https://en.wikipedia.org/wiki/Hindmarsh%E2%80%93Rose_model
Also for Fitzhugh_Nagumo model,
function F =fitzhugh_nagumo(x,u)
F = zeros(2,1);
V=x(1);
W=x(2);
F = [V-((V.^3)/3)-W+u;0.08*(V+0.7-0.8*W)];
end
Code:
u = 3
x0 = [1,1];
tspan= [0 100];
[t,x] = ode45(@(t,x) fitzhugh_nagumo(x,u), tspan, x0);
plot(t,x);
%plot(t,x(:,1));
xlabel('time[s]');
ylabel('magnitude');
title('Hindmarsh–Rose neuron model Stimulation')
%legend('dx/dt','d^2x/d^2t','d^3x/d^3t')
grid on;

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by