I've seen this question asked before but don't understand the answers provided.
I am running the following code:
function F = Fexample1(t, y)
% check the size of y
n = length(y);
if n ~= 2, error('invalid size of y'); end
F1 = 0.25*y(1) - 0.002*y(1)^2 - 0.005*y(1)*y(2)
F2 = 0.05*y(2) - 0.009*y(2)^2 - 0.005*y(1)*y(2)
F = [F1, F2];
[Y, t] = ODEsolver_eulerND('Fexample1', [0 1], 0, 1, 11);
I get this error:
Not enough input arguments. Error in final (line 4) n = length(y);
Any advice?

 채택된 답변

Walter Roberson
Walter Roberson 2017년 5월 14일

1 개 추천

function [Y, t] = final
[Y, t] = ODEsolver_eulerND(@Fexample1, [0 1], 0, 1, 11);
function F = Fexample1(t, y)
% check the size of y
n = length(y);
if n ~= 2, error('invalid size of y'); end
F1 = 0.25*y(1) - 0.002*y(1)^2 - 0.005*y(1)*y(2)
F2 = 0.05*y(2) - 0.009*y(2)^2 - 0.005*y(1)*y(2)
F = [F1; F2];
Note: I changed the F = [F1, F2]; to F = [F1; F2]; for consistency with the Mathworks ode*() routines. Using a column vector there will allow you to check your results using ode45()

추가 답변 (0개)

카테고리

태그

질문:

2017년 5월 14일

답변:

2017년 5월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by