Error in using ode23t to solve a differential equation on a graph/network

조회 수: 7 (최근 30일)
Hi, I am trying to solve a differential equation about a substance spreading on a graph/network.
I am using the ode23t solver, but I am getting the following errors:
Error using odearguments (line 113)
Inputs must be floats, namely single or double.
Error in ode23t (line 143)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in fr_net (line 48)
[T,H] = ode23t(@(t,h) MYODE(t,h,G,N,e,n,z,initialnode,w,Q,lambda),tspan,h,opts);
Do you have any idea how to fix it?
Here following, I tried to summarise the relevant parts of the code:
% network
s = [1 1 2 2 3 3 4 5 5 6 6 7 7 8 9 9 10 10 11 11 12 13 14 15];
t = [2 5 3 6 4 7 8 6 9 7 10 8 11 12 10 13 11 14 12 15 16 14 15 16];
G = graph(s,t);
N = numnodes(G); % 16 nodes
e = table2array(G.Edges);
n = table2array(G.Nodes);
% networks coordinates (x,y,z)
x = ...
y = ...
z = ...
G.Nodes.X = x'; G.Nodes.Y = y'; G.Nodes.Z = z';
% inputs/initial conditions/parameters
initialnode = 1;
h = repelem(0.01,N);
h(initialnode) = 0.5;
w = repelem(1,N);
Q(initialnode) = 0;
lambda = 0.3;
% ode23t solver
tspan = [0 3600]; % t = time
opts = odeset('MaxStep',3600);
[T,H] = ode23t(@(t,h) MYODE(t,h,G,N,e,n,z,initialnode,w,Q,lambda),tspan,h,opts);
% MYODE
function dhdt = MYODE(t,h,G,N,e,n,z,initialnode,w,Q,lambda),tspan,h,opts);
for i = 1 : N
j = randi([1 N]);
% some operation/equation (I use cells for Q, since it could "store" several numbers)
Qcell{i} = ... % some operation/equation
dhdt_tmp{i} = cell2mat(Qcell{i}) / function_ij; % differential equation
end
dhdt = cell2mat(dhdt_tmp);
end

채택된 답변

Walter Roberson
Walter Roberson 2020년 7월 2일
function dhdt = MYODE(t,h,G,N,e,n,z,initialnode,w,Q,lambda),tspan,h,opts);
That is an illegal function declaration. I suspect you made a mistake in your copying.
You appear to be building dhdt_tmp as a row cell array. cell2mat() would convert that to a row vector, but the output needs to be a column vector.
Inputs must be floats, namely single or double.
At that polnt in the code, that error would result if tspan or h are not numeric (which they certainly look to be) or if the ode called on the first time and first boundary condition, returns something that is not numeric.
  댓글 수: 7
Sim
Sim 2020년 7월 2일
편집: Sim 2020년 7월 2일
ok... doing this:
class(G)
result = MYODE(tspan(1), h(:), G, N, e, n, z, initialnode, w, Q, lambda)
I obtain:
ans =
'graph'
...but I still get this error:
Undefined function 'neighbors' for input arguments of type 'double'.
Error in fr_net>MYODE (line 66)
neighb = neighbors(G,i);
Error in fr_net (line 49)
result = MYODE(tspan(1), h(:), G, N, e, n, z, initialnode, w, Q, lambda)
....Probably I should put G as global variable (or open a new question about this last error....) ?!
Sim
Sim 2020년 7월 2일
편집: Sim 2020년 7월 3일
Problem solved! There was a typo in the function!
Thank you very much Walter! You gave me the right advices and diagnostic tools to understand my mistakes!
All the best,
Sim

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by