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

3 views (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 2 Jul 2020
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 Comments
Sim
Sim on 2 Jul 2020
Edited: Sim on 3 Jul 2020
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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!