Error in using ode23t to solve a differential equation on a graph/network
Show older comments
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
More Answers (0)
Categories
Find more on Chemistry in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!