Not enough input arguments, ODE 45, System of ODEs
3 views (last 30 days)
Show older comments
Hello everybody! I seem to be very unlucky, I can not find any solution to my problem - I have:
Error using chu2 (line 9)
Not enough input arguments.
Here is my code:
function dy = chu2(y)
m0 = -3/7;
m1 = 4/7;
alpha = 9;
beta = 14;
dy = zeros(3,1);
dy(1) = alpha*(y(2) - y(1) - (.5)*(m0 - m1)*(abs(y(1) + 1) - abs(y(1) - 1)));
dy(2) = y(1) - y(2) + y(3);
dy(3) = -beta*y(2);
[~,Y] = ode45(@chu2,[0 1 1]);
plot3(Y)
Firstly, I thought the problem is because I gave not enough info, but I have checked everything.
Also I have a question about ODE45 - what method Matlab uses as it ? Runge–Kutta method ?* * Thank you for answering such dull question, but I am so desperate to find any mistake in my code, I have googled but that did not help.
Solution to this problem by Star Strider is to call not the chu2(y) but chu2(~,y)
0 Comments
Accepted Answer
Star Strider
on 25 Oct 2014
First, it seems that you are calling your ODE function ‘chu2’ from inside the function, with these lines:
[~,Y] = ode45(@chu2,[0 1 1]);
plot3(Y)
Do not do that! Call it from outside your function, in the main script file.
Second, the ODE solvers require 3 arguments, the first one being your ODE function (that you supplied), the second one being vector containing a range [beginning end] or vector of solution times, and the third your initial conditions. It seems you omitted your time vector, the reason you got the error.
4 Comments
Star Strider
on 26 Oct 2014
Quoting:
‘function dy = chu2( * !! you mean here I should write input arguments?!! * )’
Yes!
‘If I write here function dy = chu2( ~,y ) then program has no ERRORs!’
Success!!
If you want to plot each y-value on its own axis, I would use the subplot function:
figure(1)
subplot(2,1,1)
plot(t, y(:,1))
title('Y_1')
grid
subplot(2,1,2)
plot(t, y(:,2))
title('Y_2')
grid
subplot(2,1,3)
plot(t, y(:,3))
title('Y_3')
grid
That should work for your plots.
More Answers (0)
See Also
Categories
Find more on Contour 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!