Error message for ode45: "too many input arguments"
조회 수: 6 (최근 30일)
이전 댓글 표시
I have a differential equation dQ= alpha*A*Q - beta*Q where each row is its own DE -- I am trying to go through each row and solve the differential equation. I am looking for 6 plots showing the solution.
MY function is as follows:
function dQ = ode_system (t, Q, param)
for j=1:6
dQ(i) = -param.r*Q+param.beta*Q*A(i,j);
end
end
And my script:
param.alpha = 0.001; % set the parameter 'alpha' of the model where 'alpha' is the base infection rate which can be anything larger than 0
param.beta = 0.1; % set the parameter 'beta' of the model where 'beta' is the recovery rate of the system
Q_not=zeros(6,1);
Q_not(randi(6))=1;
A=[1 1 0 0 1 0; 1 0 1 0 1 0;0 1 0 1 0 0;0 0 1 0 1 1;1 1 0 1 0 0;0 0 0 1 0 0]; %This is the adjacency matrix of the system
model_title = 'SIS Epidemics';
end_time = 100;
for i=1:6
initial.Q=Q_not(i);
% Extract initial values from the 'initial' structure and collect them
% in a column vector for use in 'ode45'.
initial_values = []; variable_names = fieldnames(initial);
for i=1:length(variable_names)
initial_values = [initial_values; initial.(variable_names{i})];
end
% integrate [t, y] = ode45(@(t, Q) ode_system(t, Q, param), ... [0 end_time], ... initial_values, ... []);
% for plotting legend_texts = cell(length(variable_names), 1);
for i=1:length(variable_names)
text = [variable_names{i} '(t)'];
legend_texts{i} = text;
end
plot(t, y);
xlabel('time');
ylabel('number of individuals');
title(model_title);
legend(legend_texts);
end
댓글 수: 2
Geoff Hayes
2014년 10월 30일
Brynn- rather than pasting the script into your function, it may be easier to just attach it to your question using the paper clip button (that way, it will be formatted properly).
In your ode_system, you reference param.r and A. The former is not a field within your param structure, and the latter is not an input to the function. (Neither is the index variable i.)
These three problems don't generate the error too many input arguments, so you may want to adjust your code, question title and/or add some context as to what you are attempting and what the problem is.
Stephen23
2014년 10월 30일
Also you should avoid using i as a vairable name, as this is the name of the inbuilt imaginary unit . Some common alternatives are ii, jj, m, n,...
답변 (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!