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.
조회 수: 2 (최근 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);
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!