Not enough input arguments, ODE 45, System of ODEs

3 Ansichten (letzte 30 Tage)
Ievgenii
Ievgenii am 25 Okt. 2014
Kommentiert: Star Strider am 26 Okt. 2014
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)

Akzeptierte Antwort

Star Strider
Star Strider am 25 Okt. 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 Kommentare
Ievgenii
Ievgenii am 26 Okt. 2014
Bearbeitet: Ievgenii am 26 Okt. 2014
Here is full code to chu2.m
function dy = chu2( * *!! you mean here I should write input arguments?!!* * )
m0 = -3/7;
m1 = 4/7;
alpha = 9;
beta = 14;
dy = zeros(3,1); % 0 0 0
dy(1) = alpha*(y(2) - y(1) - (1/2)*(m0 - m1)*(abs(y(1) + 1) - abs(y(1) - 1)));
dy(2) = y(1) - y(2) + y(3);
dy(3) = -beta*y(2);
end
And I am calling it in command line like this :
[T,Y] = ode45(@chu2,[0 10],[0 1 1]);
If I write here function dy = chu2( ~,y ) then program has no ERRORs!
One more question - How can plot my system ODE if the output, as far as I understand is: Column vector of time points and Solution array. Each row in Y corresponds to the solution at a time returned in the corresponding row of T. To plot 3d plot I need to have each projection of Y to plot on its own axis, and I will have such numbers (y1,y2,y3) - T times. But how to separate from the Y projections?
Star Strider
Star Strider am 26 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Contour Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by